Skip to content

Commit

Permalink
Add diff logic between two AMTs (#48)
Browse files Browse the repository at this point in the history
* Util to diff 2 AMTs

* Adjust diff logic to refactored node types and variable bit widths

* Remove outdated TODO

* Simplify diff function signatures

* Small stylistic and lint changes

Co-authored-by: Aayush Rajasekaran <[email protected]>
  • Loading branch information
iand and arajasek authored Mar 30, 2021
1 parent 005fc97 commit 8a02dbd
Show file tree
Hide file tree
Showing 5 changed files with 779 additions and 12 deletions.
23 changes: 12 additions & 11 deletions amt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ func init() {
}

func TestMain(m *testing.M) {
var exitCode int

// Hack to test with multiple widths, without hassle.
for defaultBitWidth = 2; defaultBitWidth <= 18; defaultBitWidth++ {
fmt.Printf("WIDTH %d\n", defaultBitWidth)
if code := m.Run(); code != 0 {
os.Exit(code)
exitCode = code
}
}
os.Exit(0)
os.Exit(exitCode)
}

type mockBlocks struct {
Expand Down Expand Up @@ -125,7 +127,6 @@ func TestBasicSetGet(t *testing.T) {
assertGet(ctx, t, clean, 2, "foo")

assertCount(t, clean, 1)

}

func TestRoundTrip(t *testing.T) {
Expand Down Expand Up @@ -328,9 +329,9 @@ func TestChaos(t *testing.T) {
bs := cbor.NewCborStore(newMockBlocks())
seed := time.Now().UnixNano()
ctx := context.Background()
//seed = 1579200312848358622 // FIXED
//seed = 1579202116615474412
//seed = 1579202774458659521
// seed = 1579200312848358622 // FIXED
// seed = 1579202116615474412
// seed = 1579202774458659521
// all above are with ops=100,maxIndx=2000
r := rand.New(rand.NewSource(seed))
t.Logf("seed: %d", seed)
Expand Down Expand Up @@ -526,7 +527,7 @@ func TestDelete(t *testing.T) {
assertDelete(t, a, 3)

assertCount(t, a, 0)
fmt.Println("trying deeper operations now")
t.Logf("trying deeper operations now")

assertSet(t, a, 23, "dog")
assertSet(t, a, 24, "dog")
Expand Down Expand Up @@ -557,9 +558,9 @@ func TestDelete(t *testing.T) {
}

if c != a2c {
fmt.Printf("%#v\n", a)
fmt.Printf("%#v\n", na)
fmt.Printf("%#v\n", a2)
t.Logf("%#v\n", a)
t.Logf("%#v\n", na)
t.Logf("%#v\n", a2)
t.Fatal("unexpected cid", c, a2c)
}
}
Expand Down Expand Up @@ -833,7 +834,7 @@ func TestFirstSetIndex(t *testing.T) {
found, err := after.Delete(ctx, v)
require.NoError(t, err)
require.True(t, found)
fsi, err = after.FirstSetIndex(ctx)
_, err = after.FirstSetIndex(ctx)
require.Error(t, err)
}
}
Expand Down
Loading

0 comments on commit 8a02dbd

Please sign in to comment.