github.com/aigarnetwork/aigar@v0.0.0-20191115204914-d59a6eb70f8e/core/vm/intpool_test.go (about) 1 // Copyright 2018 The go-ethereum Authors 2 // Copyright 2019 The go-aigar Authors 3 // This file is part of the go-aigar library. 4 // 5 // The go-aigar library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // The go-aigar library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the go-aigar library. If not, see <http://www.gnu.org/licenses/>. 17 18 package vm 19 20 import ( 21 "testing" 22 ) 23 24 func TestIntPoolPoolGet(t *testing.T) { 25 poolOfIntPools.pools = make([]*intPool, 0, poolDefaultCap) 26 27 nip := poolOfIntPools.get() 28 if nip == nil { 29 t.Fatalf("Invalid pool allocation") 30 } 31 } 32 33 func TestIntPoolPoolPut(t *testing.T) { 34 poolOfIntPools.pools = make([]*intPool, 0, poolDefaultCap) 35 36 nip := poolOfIntPools.get() 37 if len(poolOfIntPools.pools) != 0 { 38 t.Fatalf("Pool got added to list when none should have been") 39 } 40 41 poolOfIntPools.put(nip) 42 if len(poolOfIntPools.pools) == 0 { 43 t.Fatalf("Pool did not get added to list when one should have been") 44 } 45 } 46 47 func TestIntPoolPoolReUse(t *testing.T) { 48 poolOfIntPools.pools = make([]*intPool, 0, poolDefaultCap) 49 nip := poolOfIntPools.get() 50 poolOfIntPools.put(nip) 51 poolOfIntPools.get() 52 53 if len(poolOfIntPools.pools) != 0 { 54 t.Fatalf("Invalid number of pools. Got %d, expected %d", len(poolOfIntPools.pools), 0) 55 } 56 }