deno.land / std@0.224.0 / data_structures / _binary_search_node_test.ts

_binary_search_node_test.ts
View Documentation
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assertEquals, assertStrictEquals } from "../assert/mod.ts";import { BinarySearchNode } from "./_binary_search_node.ts";
let parent: BinarySearchNode<number>;let child: BinarySearchNode<number>;function beforeEach() { parent = new BinarySearchNode(null, 5); child = new BinarySearchNode(parent, 7); parent.right = child;}
Deno.test("BinarySearchNode", () => { beforeEach(); assertStrictEquals(parent.parent, null); assertStrictEquals(parent.left, null); assertStrictEquals(parent.right, child); assertStrictEquals(parent.value, 5);
assertStrictEquals(child.parent, parent); assertStrictEquals(child.left, null); assertStrictEquals(child.right, null); assertStrictEquals(child.value, 7);});
Deno.test("BinarySearchNode.from()", () => { beforeEach(); const parentClone: BinarySearchNode<number> = BinarySearchNode.from(parent); const childClone: BinarySearchNode<number> = BinarySearchNode.from(child);
assertStrictEquals(parentClone.parent, null); assertStrictEquals(parentClone.left, null); assertStrictEquals(parentClone.right, child); assertStrictEquals(parentClone.value, 5);
assertStrictEquals(childClone.parent, parent); assertStrictEquals(childClone.left, null); assertStrictEquals(childClone.right, null); assertStrictEquals(childClone.value, 7);});
Deno.test("BinarySearchNode.directionFromParent()", () => { beforeEach(); const child2 = new BinarySearchNode(parent, 3); assertEquals(child2.directionFromParent(), null); parent.left = child2; assertEquals(child2.directionFromParent(), "left"); assertEquals(parent.directionFromParent(), null); assertEquals(child.directionFromParent(), "right");});
Deno.test("BinarySearchNode.findMinNode()", () => { beforeEach(); assertStrictEquals(parent.findMinNode(), parent); const child2 = new BinarySearchNode(parent, 3); parent.left = child2; assertStrictEquals(parent.findMinNode(), child2); const child3 = new BinarySearchNode(child2, 4); child2.right = child3; assertStrictEquals(parent.findMinNode(), child2); const child4 = new BinarySearchNode(child2, 2); child2.left = child4; assertStrictEquals(parent.findMinNode(), child4);});
Deno.test("BinarySearchNode.findMaxNode()", () => { beforeEach(); assertStrictEquals(parent.findMaxNode(), child); const child2 = new BinarySearchNode(child, 6); child.left = child2; assertStrictEquals(parent.findMaxNode(), child); const child3 = new BinarySearchNode(child2, 6.5); child2.right = child3; assertStrictEquals(parent.findMaxNode(), child); const child4 = new BinarySearchNode(child2, 8); child.right = child4; assertStrictEquals(parent.findMaxNode(), child4); parent.right = null; assertStrictEquals(parent.findMaxNode(), parent);});
Deno.test("BinarySearchNode.findSuccessorNode()", () => { beforeEach(); assertStrictEquals(parent.findSuccessorNode(), child); assertStrictEquals(child.findSuccessorNode(), null); const child2 = new BinarySearchNode(child, 6); child.left = child2; assertStrictEquals(parent.findSuccessorNode(), child2); assertStrictEquals(child.findSuccessorNode(), null);});
std

Version Info

Tagged at
6 months ago