Skip to content

Commit

Permalink
arena: clean up tests. (pingcap#1150)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngaut committed Apr 23, 2016
1 parent 0b2f000 commit 15db558
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions util/arena/arena_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,62 +24,44 @@ func TestSimpleArenaAllocator(t *testing.T) {
t.Error("off not match, expect 10 bug got", arena.off)
}

if len(slice) != 0 {
t.Error("slice len not match, expect 0 bug got", len(slice))
}

if cap(slice) != 10 {
t.Error("slice len not match, expect 10 bug got", cap(slice))
if len(slice) != 0 || cap(slice) != 10 {
t.Error("slice length or cap not match")
}

slice = arena.Alloc(20)
if arena.off != 30 {
t.Error("off not match, expect 30 bug got", arena.off)
}

if len(slice) != 0 {
t.Error("slice len not match, expect 0 bug got", len(slice))
}

if cap(slice) != 20 {
t.Error("slice len not match, expect 20 bug got", cap(slice))
if len(slice) != 0 || cap(slice) != 20 {
t.Error("slice length or cap not match")
}

slice = arena.Alloc(1024)

if arena.off != 30 {
t.Error("off not match, expect 30 bug got", arena.off)
}

if len(slice) != 0 {
t.Error("slice len not match, expect 0 bug got", len(slice))
}

if cap(slice) != 1024 {
t.Error("slice len not match, expect 1024 bug got", cap(slice))
if len(slice) != 0 || cap(slice) != 1024 {
t.Error("slice length or cap not match")
}

slice = arena.AllocWithLen(2, 10)

if arena.off != 40 {
t.Error("off not match, expect 40 bug got", arena.off)
}

if len(slice) != 2 {
t.Error("slice len not match, expect 2 bug got", len(slice))
}

if cap(slice) != 10 {
t.Error("slice len not match, expect 10 bug got", cap(slice))
if len(slice) != 2 || cap(slice) != 10 {
t.Error("slice length or cap not match")
}

arena.Reset()
if arena.off != 0 || cap(arena.arena) != 1000 {
t.Error("off should be 0")
t.Error("off or cap not match")
}

if cap(arena.arena) != 1000 {
t.Error("off should be 0")
t.Error("cap not match")
}
}

Expand Down

0 comments on commit 15db558

Please sign in to comment.