diff options
author | Martin Kobetic <mkobetic@gmail.com> | 2015-06-12 21:32:55 -0400 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2015-06-16 13:48:54 -0600 |
commit | 04a3e85793043e76d41164037d0d7f9d53eecae3 (patch) | |
tree | 392ab1953fd26bdaaa2c4e4bb81cd998c2d36bdf /page_test.go | |
parent | Merge pull request #388 from ajvb/master (diff) | |
download | dedo-04a3e85793043e76d41164037d0d7f9d53eecae3.tar.gz dedo-04a3e85793043e76d41164037d0d7f9d53eecae3.tar.xz |
Merge sorted pgids rather than resorting everything
Diffstat (limited to 'page_test.go')
-rw-r--r-- | page_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/page_test.go b/page_test.go index 7a4d327..59f4a30 100644 --- a/page_test.go +++ b/page_test.go @@ -1,7 +1,10 @@ package bolt import ( + "reflect" + "sort" "testing" + "testing/quick" ) // Ensure that the page type can be returned in human readable format. @@ -27,3 +30,43 @@ func TestPage_typ(t *testing.T) { func TestPage_dump(t *testing.T) { (&page{id: 256}).hexdump(16) } + +func TestPgids_merge(t *testing.T) { + a := pgids{4, 5, 6, 10, 11, 12, 13, 27} + b := pgids{1, 3, 8, 9, 25, 30} + c := a.merge(b) + if !reflect.DeepEqual(c, pgids{1, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 25, 27, 30}) { + t.Errorf("mismatch: %v", c) + } + + a = pgids{4, 5, 6, 10, 11, 12, 13, 27, 35, 36} + b = pgids{8, 9, 25, 30} + c = a.merge(b) + if !reflect.DeepEqual(c, pgids{4, 5, 6, 8, 9, 10, 11, 12, 13, 25, 27, 30, 35, 36}) { + t.Errorf("mismatch: %v", c) + } +} + +func TestPgids_merge_quick(t *testing.T) { + if err := quick.Check(func(a, b pgids) bool { + // Sort incoming lists. + sort.Sort(a) + sort.Sort(b) + + // Merge the two lists together. + got := a.merge(b) + + // The expected value should be the two lists combined and sorted. + exp := append(a, b...) + sort.Sort(exp) + + if !reflect.DeepEqual(exp, got) { + t.Errorf("\nexp=%+v\ngot=%+v\n", exp, got) + return false + } + + return true + }, nil); err != nil { + t.Fatal(err) + } +} |