github.com/moontrade/nogc@v0.1.7/autofree_test.go (about) 1 package nogc 2 3 import "testing" 4 5 func TestAuto_Add(t *testing.T) { 6 //sizeBefore := int64(0) 7 auto := NewAuto(20) 8 9 for i := 0; i < 100; i++ { 10 auto.Alloc(64) 11 } 12 13 //if sizeBefore >= a.Stats().AllocSize { 14 // t.Fatal("allocator should have some allocs") 15 //} 16 //if a.Stats().Allocs != 105 { 17 // t.Fatalf("expected 105 allocs not %d", a.Stats().Allocs) 18 //} 19 20 auto.Print() 21 auto.Free() 22 23 //if a.Stats().AllocSize != 0 { 24 // t.Fatal("allocator should have zero allocs") 25 //} 26 } 27 28 func TestAuto_Scope(t *testing.T) { 29 Scope(func(a AutoFree) { 30 for i := 0; i < 100; i++ { 31 a.Alloc(64) 32 // a.Str(128) 33 } 34 }) 35 //if a.Stats().Allocs != 0 { 36 // t.Fatalf("allocator should have 0 allocs not: %d", a.Stats().Allocs) 37 //} 38 //if a.Stats().FreeSize == 0 { 39 // t.Fatal("allocator should have a FreeSize greater than zero") 40 //} 41 //if a.Stats().AllocSize != 0 { 42 // t.Fatal("allocator should have zero allocs") 43 //} 44 }