Skip to content

Commit

Permalink
cherry pick changes from non-interactive defaults branch
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes committed Sep 2, 2022
1 parent d2d645b commit 9cf9f54
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/inclusion/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ package inclusion
//nolint:unused,deadcode
func genSubTreeRootPath(depth int, pos uint) []bool {
path := make([]bool, depth)
for i := depth; i >= 0; i-- {
counter := 0
for i := depth - 1; i >= 0; i-- {
if (pos & (1 << i)) == 0 {
path = append(path, false)
path[counter] = false
} else {
path = append(path, true)
path[counter] = true
}
counter++
}
return path
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/inclusion/paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,23 @@ func Test_calculateSubTreeRootCoordinates(t *testing.T) {
assert.Equal(t, tt.expected, res, tt.name)
}
}

func Test_genSubTreeRootPath(t *testing.T) {
type test struct {
depth int
pos uint
expected []bool
}
tests := []test{
{2, 0, []bool{false, false}},
{0, 0, []bool{}},
{3, 0, []bool{false, false, false}},
{3, 1, []bool{false, false, true}},
{3, 2, []bool{false, true, false}},
{5, 16, []bool{true, false, false, false, false}},
}
for _, tt := range tests {
path := genSubTreeRootPath(tt.depth, tt.pos)
assert.Equal(t, tt.expected, path)
}
}

0 comments on commit 9cf9f54

Please sign in to comment.