aboutsummaryrefslogtreecommitdiff
path: root/freelist_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-05-21 13:46:12 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-05-21 13:46:12 -0600
commit7432bc341f8bbfc73eefc3278f2698e712e516b8 (patch)
tree33897520b5bd98383fe3b17cc9090e931c690b9c /freelist_test.go
parentMerge pull request #171 from Shopify/tx_copy (diff)
parentFix freelist allocate(). (diff)
downloaddedo-7432bc341f8bbfc73eefc3278f2698e712e516b8.tar.gz
dedo-7432bc341f8bbfc73eefc3278f2698e712e516b8.tar.xz
Merge pull request #169 from benbjohnson/allocation
Fix freelist allocation direction.
Diffstat (limited to 'freelist_test.go')
-rw-r--r--freelist_test.go33
1 files changed, 18 insertions, 15 deletions
diff --git a/freelist_test.go b/freelist_test.go
index 2b321a4..5948f3b 100644
--- a/freelist_test.go
+++ b/freelist_test.go
@@ -29,22 +29,25 @@ func TestFreelist_release(t *testing.T) {
f.free(102, &page{id: 39})
f.release(100)
f.release(101)
- assert.Equal(t, f.ids, []pgid{13, 12, 9})
+ assert.Equal(t, []pgid{9, 12, 13}, f.ids)
f.release(102)
- assert.Equal(t, f.ids, []pgid{39, 13, 12, 9})
+ assert.Equal(t, []pgid{9, 12, 13, 39}, f.ids)
}
// Ensure that a freelist can find contiguous blocks of pages.
func TestFreelist_allocate(t *testing.T) {
- f := &freelist{ids: []pgid{18, 13, 12, 9, 7, 6, 5, 4, 3}}
- assert.Equal(t, f.allocate(2), pgid(12))
- assert.Equal(t, f.allocate(1), pgid(18))
- assert.Equal(t, f.allocate(3), pgid(5))
- assert.Equal(t, f.allocate(3), pgid(0))
- assert.Equal(t, f.allocate(2), pgid(3))
- assert.Equal(t, f.allocate(1), pgid(9))
- assert.Equal(t, f.allocate(0), pgid(0))
- assert.Equal(t, f.ids, []pgid{})
+ f := &freelist{ids: []pgid{3, 4, 5, 6, 7, 9, 12, 13, 18}}
+ assert.Equal(t, 3, int(f.allocate(3)))
+ assert.Equal(t, 6, int(f.allocate(1)))
+ assert.Equal(t, 0, int(f.allocate(3)))
+ assert.Equal(t, 12, int(f.allocate(2)))
+ assert.Equal(t, 7, int(f.allocate(1)))
+ assert.Equal(t, 0, int(f.allocate(0)))
+ assert.Equal(t, []pgid{9, 18}, f.ids)
+ assert.Equal(t, 9, int(f.allocate(1)))
+ assert.Equal(t, 18, int(f.allocate(1)))
+ assert.Equal(t, 0, int(f.allocate(1)))
+ assert.Equal(t, []pgid{}, f.ids)
}
// Ensure that a freelist can deserialize from a freelist page.
@@ -87,9 +90,9 @@ func TestFreelist_write(t *testing.T) {
// Ensure that the freelist is correct.
// All pages should be present and in reverse order.
assert.Equal(t, len(f2.ids), 5)
- assert.Equal(t, f2.ids[0], pgid(39))
- assert.Equal(t, f2.ids[1], pgid(28))
+ assert.Equal(t, f2.ids[0], pgid(3))
+ assert.Equal(t, f2.ids[1], pgid(11))
assert.Equal(t, f2.ids[2], pgid(12))
- assert.Equal(t, f2.ids[3], pgid(11))
- assert.Equal(t, f2.ids[4], pgid(3))
+ assert.Equal(t, f2.ids[3], pgid(28))
+ assert.Equal(t, f2.ids[4], pgid(39))
}