Skip to content

Commit

Permalink
test(trees): make the TestCreateTree table use labeled entries
Browse files Browse the repository at this point in the history
This makes the test data specify the label: number to make it more
readable; it is hard to map the four numbers to the field name of
original createTreeTest type.
  • Loading branch information
meling committed Dec 22, 2024
1 parent 5fe6e96 commit 2bd3535
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions trees/treeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@ import (
"github.com/relab/hotstuff"
)

type createTreeTest struct {
configurationSize int
id hotstuff.ID
branchFactor int
height int
}

func TestCreateTree(t *testing.T) {
createTreeTestData := []createTreeTest{
{10, 1, 2, 4},
{21, 1, 4, 3},
{21, 1, 3, 4},
{111, 1, 10, 3},
{111, 1, 3, 5},
tests := []struct {
configurationSize int
id hotstuff.ID
branchFactor int
wantHeight int
}{
{configurationSize: 10, id: 1, branchFactor: 2, wantHeight: 4},
{configurationSize: 21, id: 1, branchFactor: 4, wantHeight: 3},
{configurationSize: 21, id: 1, branchFactor: 3, wantHeight: 4},
{configurationSize: 111, id: 1, branchFactor: 10, wantHeight: 3},
{configurationSize: 111, id: 1, branchFactor: 3, wantHeight: 5},
}
for _, test := range createTreeTestData {
for _, test := range tests {
tree := CreateTree(test.configurationSize, test.id, test.branchFactor)
if tree.GetTreeHeight() != test.height {
t.Errorf("Expected height %d, got %d", test.height, tree.GetTreeHeight())
if tree.GetTreeHeight() != test.wantHeight {
t.Errorf("CreateTree(%d, %d, %d).GetTreeHeight() = %d, want %d",
test.configurationSize, test.id, test.branchFactor, tree.GetTreeHeight(), test.wantHeight)
}
}
}
Expand Down

0 comments on commit 2bd3535

Please sign in to comment.