-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
27 lines (21 loc) · 1.08 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const {createUnivalNode, isUnivalTree} = require('.');
test('Unival tree', () => {
const UNIC_VALUE = '1';
const nodeOne = createUnivalNode({value: UNIC_VALUE});
const nodeTwoChildOne = createUnivalNode({value: UNIC_VALUE});
const nodeTwoChildTwo = createUnivalNode({value: UNIC_VALUE});
const nodeTwo = createUnivalNode({value: UNIC_VALUE, nodes: [nodeTwoChildOne, nodeTwoChildTwo]});
const mainNode = createUnivalNode({value: UNIC_VALUE, nodes: [nodeOne, nodeTwo]});
const expected = isUnivalTree(mainNode, UNIC_VALUE);
expect(expected).toBeTruthy();
});
test('Non-Unival tree', () => {
const UNIC_VALUE = '1';
const nodeOne = createUnivalNode({value: '123'});
const nodeTwoChildOne = createUnivalNode({value: UNIC_VALUE});
const nodeTwoChildTwo = createUnivalNode({value: UNIC_VALUE});
const nodeTwo = createUnivalNode({value: UNIC_VALUE, nodes: [nodeTwoChildOne, nodeTwoChildTwo]});
const mainNode = createUnivalNode({value: UNIC_VALUE, nodes: [nodeOne, nodeTwo]});
const expected = isUnivalTree(mainNode, UNIC_VALUE);
expect(expected).toBeFalsy();
});