github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/merkle/util_test.go (about) 1 package merkle 2 3 import ( 4 "fmt" 5 "reflect" 6 "testing" 7 ) 8 9 func TestComputeSkipPointers(t *testing.T) { 10 var tests = []struct { 11 in TreeSeqno 12 out []TreeSeqno 13 }{ 14 {0, nil}, 15 {1, nil}, 16 {2, []TreeSeqno{1}}, 17 {3, []TreeSeqno{2, 1}}, 18 {4, []TreeSeqno{3, 2}}, 19 {5, []TreeSeqno{4, 3, 1}}, 20 {16, []TreeSeqno{15, 14, 12, 8}}, 21 {31, []TreeSeqno{30, 29, 27, 23, 15}}, 22 {32, []TreeSeqno{31, 30, 28, 24, 16}}, 23 {33, []TreeSeqno{32, 31, 29, 25, 17, 1}}, 24 {100, []TreeSeqno{99, 98, 96, 92, 84, 68, 36}}, 25 {255, []TreeSeqno{254, 253, 251, 247, 239, 223, 191, 127}}, 26 {256, []TreeSeqno{255, 254, 252, 248, 240, 224, 192, 128}}, 27 {257, []TreeSeqno{256, 255, 253, 249, 241, 225, 193, 129, 1}}, 28 {1000, []TreeSeqno{999, 998, 996, 992, 984, 968, 936, 872, 744, 488}}, 29 {2048, []TreeSeqno{2047, 2046, 2044, 2040, 2032, 2016, 1984, 1920, 1792, 1536, 1024}}, 30 {123456, []TreeSeqno{ 31 123455, 123454, 123452, 123448, 123440, 123424, 123392, 123328, 32 123200, 122944, 122432, 121408, 119360, 115264, 107072, 90688, 33 57920, 34 }}, 35 } 36 for _, tt := range tests { 37 tt := tt 38 t.Run(fmt.Sprintf("%+v", tt.in), func(t *testing.T) { 39 actual := ComputeSkipPointers(tt.in) 40 if !reflect.DeepEqual(actual, tt.out) { 41 t.Errorf("(%d): expected %#v, actual %#v", tt.in, tt.out, actual) 42 } 43 }) 44 } 45 } 46 47 func TestComputeSkipPath(t *testing.T) { 48 tests := []struct { 49 start TreeSeqno 50 end TreeSeqno 51 expected []TreeSeqno 52 }{ 53 {100, 2033, []TreeSeqno{1009, 497, 241, 113, 105, 101}}, 54 {100, 102, []TreeSeqno{}}, 55 {100, 103, []TreeSeqno{101}}, 56 {200, 100, []TreeSeqno{}}, 57 } 58 for _, test := range tests { 59 got := ComputeSkipPath(test.start, test.end) 60 if !reflect.DeepEqual(got, test.expected) { 61 t.Fatalf("Failed on input (%d, %d), expected %v, got %v.", test.start, test.end, test.expected, got) 62 } 63 } 64 }