js-practice/test/tree/validate-binary-search-tree.test.js

13 lines
584 B
JavaScript
Raw Normal View History

2020-05-05 18:25:52 +08:00
import { isValidBST } from '../../src/tree/validate-binary-search-tree'
import Tree from './Tree'
test('验证二叉搜索树', () => {
expect(isValidBST(Tree.arrToTree([1, 1]))).toBe(false)
expect(isValidBST(Tree.arrToTree([2, 1, 3]))).toBe(true)
expect(isValidBST(Tree.arrToTree([5, 1, 4, null, null, 3, 6]))).toBe(false)
expect(isValidBST(Tree.arrToTree([-1]))).toBe(true)
expect(isValidBST(Tree.arrToTree([2, 1, 4, null, null, 3, 5]))).toBe(true)
expect(isValidBST(null)).toBe(true)
expect(isValidBST(Tree.arrToTree([10, 5, 15, null, null, 6, 20]))).toBe(false)
})