github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/core/vm/intpool_test.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 12:09:35</date>
    10  //</624342622357426176>
    11  
    12  
    13  package vm
    14  
    15  import (
    16  	"testing"
    17  )
    18  
    19  func TestIntPoolPoolGet(t *testing.T) {
    20  	poolOfIntPools.pools = make([]*intPool, 0, poolDefaultCap)
    21  
    22  	nip := poolOfIntPools.get()
    23  	if nip == nil {
    24  		t.Fatalf("Invalid pool allocation")
    25  	}
    26  }
    27  
    28  func TestIntPoolPoolPut(t *testing.T) {
    29  	poolOfIntPools.pools = make([]*intPool, 0, poolDefaultCap)
    30  
    31  	nip := poolOfIntPools.get()
    32  	if len(poolOfIntPools.pools) != 0 {
    33  		t.Fatalf("Pool got added to list when none should have been")
    34  	}
    35  
    36  	poolOfIntPools.put(nip)
    37  	if len(poolOfIntPools.pools) == 0 {
    38  		t.Fatalf("Pool did not get added to list when one should have been")
    39  	}
    40  }
    41  
    42  func TestIntPoolPoolReUse(t *testing.T) {
    43  	poolOfIntPools.pools = make([]*intPool, 0, poolDefaultCap)
    44  	nip := poolOfIntPools.get()
    45  	poolOfIntPools.put(nip)
    46  	poolOfIntPools.get()
    47  
    48  	if len(poolOfIntPools.pools) != 0 {
    49  		t.Fatalf("Invalid number of pools. Got %d, expected %d", len(poolOfIntPools.pools), 0)
    50  	}
    51  }
    52