@@ -457,8 +457,6 @@ func TestSubtreeConsistency(t *testing.T) {
457457 wantErr bool
458458 }{
459459 // Errors.
460- {start : 0 , end : 0 , size : 0 , wantErr : true }, // start = end = 0
461- {start : 1 , end : 1 , size : 1 , wantErr : true }, // start = end
462460 {start : 2 , end : 1 , size : 0 , wantErr : true }, // start > end
463461 {start : 0 , end : 5 , size : 0 , wantErr : true }, // end > size
464462 {start : 0 , end : 9 , size : 8 , wantErr : true }, // end > size
@@ -467,6 +465,7 @@ func TestSubtreeConsistency(t *testing.T) {
467465
468466 // Small trees.
469467 // start = 0
468+ {start : 0 , end : 0 , size : 0 , want : Nodes {IDs : []compact.NodeID {}}}, // start = end = 0
470469 {start : 0 , end : 1 , size : 2 , want : nodes (id (0 , 1 ))}, // b
471470 {start : 0 , end : 1 , size : 4 , want : nodes (id (0 , 1 ), id (1 , 1 ))}, // b bb
472471 {start : 0 , end : 1 , size : 6 , want : rehash (2 , 3 , id (0 , 1 ), id (1 , 1 ), id (1 , 2 ))}, // b bb cc
@@ -485,12 +484,14 @@ func TestSubtreeConsistency(t *testing.T) {
485484 {start : 0 , end : 7 , size : 8 , want : nodes (
486485 id (0 , 6 ), id (0 , 7 ), id (1 , 2 ), id (2 , 0 ))}, // g h cc aaa
487486 // start > 0
487+ {start : 1 , end : 1 , size : 1 , want : Nodes {IDs : []compact.NodeID {}}}, // start = end
488488 {start : 1 , end : 2 , size : 3 , want : rehash (1 , 2 , id (0 , 0 ), id (0 , 2 ))}, // a c
489489 {start : 1 , end : 2 , size : 5 , want : rehash (2 , 3 , id (0 , 0 ), id (1 , 1 ), id (0 , 4 ))}, // a bb e
490490 {start : 2 , end : 4 , size : 5 , want : rehash (1 , 2 , id (1 , 0 ), id (0 , 4 ))}, // aa e
491491 {start : 1 , end : 2 , size : 7 , want : rehash (2 , 4 , id (0 , 0 ), id (1 , 1 ), id (0 , 6 ), id (1 , 2 ))}, // a bb g cc
492492 {start : 2 , end : 4 , size : 10 , want : rehash (2 , 3 , id (1 , 0 ), id (2 , 1 ), id (1 , 4 ))}, // aa bbb ee
493493 {start : 4 , end : 6 , size : 10 , want : rehash (2 , 3 , id (1 , 3 ), id (2 , 0 ), id (1 , 4 ))}, // dd aaa ee
494+ {start : 4 , end : 4 , size : 10 , want : Nodes {IDs : []compact.NodeID {}}}, // start = end
494495 {start : 4 , end : 7 , size : 11 , want : rehash (4 , 6 , // ccc=hash(ee,k)
495496 id (0 , 6 ), id (0 , 7 ), id (1 , 2 ), id (2 , 0 ), id (0 , 10 ), id (1 , 4 ))}, // g h cc aaa k ee
496497 {start : 4 , end : 8 , size : 11 , want : rehash (1 , 3 , // ccc=hash(ee,k)
@@ -637,9 +638,9 @@ func TestConsistencySucceedsUpToTreeSize(t *testing.T) {
637638
638639func TestSubtreeConsistencySucceedsUpToTreeSize (t * testing.T ) {
639640 const maxSize = uint64 (100 )
640- for s := uint64 ( 1 ); s <= maxSize ; s ++ {
641- for sbe := uint64 ( 1 ); sbe <= s ; sbe ++ {
642- for sbs := range sbe {
641+ for s := range maxSize + 1 {
642+ for sbe := range s + 1 {
643+ for sbs := range sbe + 1 {
643644 if err := isSubtreeValid (sbs , sbe ); err != nil {
644645 continue
645646 }
@@ -829,16 +830,16 @@ func TestFindSubtrees(t *testing.T) {
829830 }{
830831 // Already-valid subtrees are returned as-is.
831832 // Single entry subtrees:
832- {start : 0 , end : 1 , want : []Subtree {{Start : 0 , End : 1 }}},
833- {start : 3 , end : 4 , want : []Subtree {{Start : 3 , End : 4 }}},
833+ {start : 0 , end : 1 , want : []Subtree {{Start : 0 , End : 1 }, { Start : 1 , End : 1 } }},
834+ {start : 3 , end : 4 , want : []Subtree {{Start : 3 , End : 4 }, { Start : 4 , End : 4 } }},
834835 // Perfectly aligned subtrees:
835- {start : 4 , end : 6 , want : []Subtree {{Start : 4 , End : 6 }}},
836- {start : 16 , end : 32 , want : []Subtree {{Start : 16 , End : 32 }}},
836+ {start : 4 , end : 6 , want : []Subtree {{Start : 4 , End : 5 }, { Start : 5 , End : 6 }}},
837+ {start : 16 , end : 32 , want : []Subtree {{Start : 16 , End : 24 }, { Start : 24 , End : 32 }}},
837838 // Non-perfect trees are split into two:
838839 {start : 5 , end : 13 , want : []Subtree {{Start : 4 , End : 8 }, {Start : 8 , End : 13 }}},
839840 {start : 7 , end : 9 , want : []Subtree {{Start : 7 , End : 8 }, {Start : 8 , End : 9 }}},
840841 // Invalid inputs:
841- {start : 5 , end : 5 , wantErr : true },
842+ {start : 5 , end : 5 , want : [] Subtree {{ Start : 5 , End : 5 }, { Start : 5 , End : 5 }} },
842843 {start : 6 , end : 5 , wantErr : true },
843844 } {
844845 t .Run (fmt .Sprintf ("%d:%d" , tc .start , tc .end ), func (t * testing.T ) {
0 commit comments