You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.5 KiB

package twosumiv_test
import (
"testing"
ts "git.jxs.me/leetgo/twosumiv"
"github.com/stretchr/testify/require"
)
func TestEmpty(t *testing.T) {
var root *ts.TreeNode
found := ts.FindTarget(root, 1)
require.False(t, found)
}
func TestShallow(t *testing.T) {
root := ts.TreeNode{
Val: 5,
Left: &ts.TreeNode{Val: 4},
Right: &ts.TreeNode{Val: 6},
}
found := ts.FindTarget(&root, 10)
require.True(t, found)
}
func TestShallowMissing(t *testing.T) {
root := ts.TreeNode{
Val: 5,
Left: &ts.TreeNode{Val: 4},
Right: &ts.TreeNode{Val: 6},
}
found := ts.FindTarget(&root, 12)
require.False(t, found)
}
func TestExample1(t *testing.T) {
root := ts.TreeNode{
Val: 5,
Left: &ts.TreeNode{Val: 3,
Left: &ts.TreeNode{Val: 2},
Right: &ts.TreeNode{Val: 4}},
Right: &ts.TreeNode{Val: 6,
Right: &ts.TreeNode{Val: 7}},
}
found := ts.FindTarget(&root, 9)
require.True(t, found)
}
func TestExample2(t *testing.T) {
root := ts.TreeNode{
Val: 5,
Left: &ts.TreeNode{Val: 3,
Left: &ts.TreeNode{Val: 2},
Right: &ts.TreeNode{Val: 4}},
Right: &ts.TreeNode{Val: 6,
Right: &ts.TreeNode{Val: 7}},
}
found := ts.FindTarget(&root, 28)
require.False(t, found)
}
func TestHalf(t *testing.T) {
root := ts.TreeNode{
Val: 5,
Left: &ts.TreeNode{Val: 3,
Left: &ts.TreeNode{Val: 2},
Right: &ts.TreeNode{Val: 4}},
Right: &ts.TreeNode{Val: 6,
Right: &ts.TreeNode{Val: 7}},
}
found := ts.FindTarget(&root, 14)
require.False(t, found)
}