Skip to content

Commit

Permalink
day 94: DRY the creation of the test tree
Browse files Browse the repository at this point in the history
  • Loading branch information
vaskoz committed Nov 27, 2018
1 parent 7de8f90 commit a2a27f5
Showing 1 changed file with 18 additions and 34 deletions.
52 changes: 18 additions & 34 deletions day94/problem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,33 @@ package day94

import "testing"

func TestMaxPathSum(t *testing.T) {
t.Parallel()
tree := &BinaryTree{
-15,
&BinaryTree{5,
&BinaryTree{-8,
&BinaryTree{2, nil, nil},
&BinaryTree{6, nil, nil}},
&BinaryTree{1, nil, nil}},
&BinaryTree{6,
&BinaryTree{3, nil, nil},
&BinaryTree{9, nil,
&BinaryTree{0,
&BinaryTree{4, nil, nil},
&BinaryTree{-1, &BinaryTree{10, nil, nil}, nil},
},
var tree = &BinaryTree{
-15,
&BinaryTree{5,
&BinaryTree{-8,
&BinaryTree{2, nil, nil},
&BinaryTree{6, nil, nil}},
&BinaryTree{1, nil, nil}},
&BinaryTree{6,
&BinaryTree{3, nil, nil},
&BinaryTree{9, nil,
&BinaryTree{0,
&BinaryTree{4, nil, nil},
&BinaryTree{-1, &BinaryTree{10, nil, nil}, nil},
},
},
}
},
}

func TestMaxPathSum(t *testing.T) {
t.Parallel()
result := MaxPathSum(tree)
if result != 27 {
t.Errorf("Expected 27 got %v", result)
}
}

func BenchmarkMaxPathSum(b *testing.B) {
tree := &BinaryTree{
-15,
&BinaryTree{5,
&BinaryTree{-8,
&BinaryTree{2, nil, nil},
&BinaryTree{6, nil, nil}},
&BinaryTree{1, nil, nil}},
&BinaryTree{6,
&BinaryTree{3, nil, nil},
&BinaryTree{9, nil,
&BinaryTree{0,
&BinaryTree{4, nil, nil},
&BinaryTree{-1, &BinaryTree{10, nil, nil}, nil},
},
},
},
}
for i := 0; i < b.N; i++ {
MaxPathSum(tree)
}
Expand Down

0 comments on commit a2a27f5

Please sign in to comment.