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

_red_black_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
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assertStrictEquals } from "../assert/mod.ts";import { RedBlackNode } from "./_red_black_node.ts";
Deno.test("RedBlackNode", () => { const parent: RedBlackNode<number> = new RedBlackNode(null, 5); const child: RedBlackNode<number> = new RedBlackNode(parent, 7); parent.left = child; assertStrictEquals(parent.red, true); parent.red = false;
assertStrictEquals(parent.parent, null); assertStrictEquals(parent.left, child); assertStrictEquals(parent.right, null); assertStrictEquals(parent.value, 5); assertStrictEquals(parent.red, false);
assertStrictEquals(child.parent, parent); assertStrictEquals(child.left, null); assertStrictEquals(child.right, null); assertStrictEquals(child.value, 7); assertStrictEquals(child.red, true);});
Deno.test("RedBlackNode.from()", () => { const parent: RedBlackNode<number> = new RedBlackNode(null, 5); const child: RedBlackNode<number> = new RedBlackNode(parent, 7); parent.left = child; parent.red = false;
const parentClone: RedBlackNode<number> = RedBlackNode.from(parent); const childClone: RedBlackNode<number> = RedBlackNode.from(child);
assertStrictEquals(parentClone.parent, null); assertStrictEquals(parentClone.left, child); assertStrictEquals(parentClone.right, null); assertStrictEquals(parentClone.value, 5); assertStrictEquals(parentClone.red, false);
assertStrictEquals(childClone.parent, parent); assertStrictEquals(childClone.left, null); assertStrictEquals(childClone.right, null); assertStrictEquals(childClone.value, 7); assertStrictEquals(childClone.red, true);});
std

Version Info

Tagged at
6 months ago