X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/087d725b5ab41ad34ffd24938482d45a8b99a080..c781f79f3c8cb9a7577ee1574d196988da2719b3:/view_test.go diff --git a/view_test.go b/view_test.go index f3d4e2a..f771eb2 100644 --- a/view_test.go +++ b/view_test.go @@ -10,8 +10,11 @@ import ( func TestViewMergesInTheOrderOfTheRollbackPush(t *testing.T) { tree := ViewBuiltTree{} + view := newView(0, 0) + var states *ViewPushEntry + for tick := range 20001 { states = viewPush(tick, states) starts := states.starts() @@ -31,11 +34,13 @@ func TestViewMergesInTheOrderOfTheRollbackPush(t *testing.T) { func TestViewMergesInOneBatchFromHighToLow(t *testing.T) { tree := ViewBuiltTree{} + view := newView(10, 5) sizes := make([]int, 0, 20) for range 20 { _, err := view.Append(tree) require.NoError(t, err) + sizes = append(sizes, view.Size()) } @@ -144,14 +149,6 @@ func TestRestoreViewRejectsAGap(t *testing.T) { // ViewBuiltTree is a tree with each node built, with 1 byte of text. type ViewBuiltTree struct{} -func (v ViewBuiltTree) Built(_, _ int) (bool, error) { - return true, nil -} - -func (ViewBuiltTree) Node(level, index int) (Node, bool, error) { - return treeTestNode(level, index, "a"), true, nil -} - // ViewPushEntry is one entry of the rollback state list of the reference // design, newest first. Under push alone, life stays 0, so the entry leaves it // out. @@ -161,9 +158,23 @@ type ViewPushEntry struct { older *ViewPushEntry } +// ViewPartTree is a tree with the built nodes of its sizes. +type ViewPartTree struct { + sizes map[NodeKey]int +} + +func (v ViewBuiltTree) Built(_, _ int) (bool, error) { + return true, nil +} + +func (ViewBuiltTree) Node(level, index int) (Node, bool, error) { + return treeTestNode(level, index, "a"), true, nil +} + // starts returns the states of the list, oldest first. func (e *ViewPushEntry) starts() []int { var starts []int + for entry := e; entry != nil; entry = entry.older { starts = append(starts, entry.state) } @@ -173,11 +184,6 @@ func (e *ViewPushEntry) starts() []int { return starts } -// ViewPartTree is a tree with the built nodes of its sizes. -type ViewPartTree struct { - sizes map[NodeKey]int -} - func (p ViewPartTree) Built(level, index int) (bool, error) { _, built := p.sizes[NodeKey{level, index}] return built, nil