@@ -18,36 +18,6 @@ describe('TrieNode', () => {
18
18
expect ( trieNode . toString ( ) ) . toBe ( 'c:a,o' ) ;
19
19
} ) ;
20
20
21
- describe ( 'removing child nodes' , ( ) => {
22
- it ( 'should delete child node if the child node has NO children' , ( ) => {
23
- const trieNode = new TrieNode ( 'c' ) ;
24
- trieNode . addChild ( 'a' ) ;
25
- expect ( trieNode . hasChild ( 'a' ) ) . toBe ( true ) ;
26
-
27
- trieNode . removeChild ( 'a' ) ;
28
- expect ( trieNode . hasChild ( 'a' ) ) . toBe ( false ) ;
29
- } ) ;
30
-
31
- it ( 'should NOT delete child node if the child node has children' , ( ) => {
32
- const trieNode = new TrieNode ( 'c' ) ;
33
- trieNode . addChild ( 'a' ) ;
34
- const childNode = trieNode . getChild ( 'a' ) ;
35
- childNode . addChild ( 'r' ) ;
36
-
37
- trieNode . removeChild ( 'a' ) ;
38
- expect ( trieNode . hasChild ( 'a' ) ) . toEqual ( true ) ;
39
- } ) ;
40
-
41
- it ( 'should NOT delete child node if the child node completes a word' , ( ) => {
42
- const trieNode = new TrieNode ( 'c' ) ;
43
- const IS_COMPLETE_WORD = true ;
44
- trieNode . addChild ( 'a' , IS_COMPLETE_WORD ) ;
45
-
46
- trieNode . removeChild ( 'a' ) ;
47
- expect ( trieNode . hasChild ( 'a' ) ) . toEqual ( true ) ;
48
- } ) ;
49
- } ) ;
50
-
51
21
it ( 'should get child nodes' , ( ) => {
52
22
const trieNode = new TrieNode ( 'c' ) ;
53
23
@@ -79,4 +49,32 @@ describe('TrieNode', () => {
79
49
80
50
expect ( trieNode . suggestChildren ( ) ) . toEqual ( [ 'a' , 'o' ] ) ;
81
51
} ) ;
52
+
53
+ it ( 'should delete child node if the child node has NO children' , ( ) => {
54
+ const trieNode = new TrieNode ( 'c' ) ;
55
+ trieNode . addChild ( 'a' ) ;
56
+ expect ( trieNode . hasChild ( 'a' ) ) . toBe ( true ) ;
57
+
58
+ trieNode . removeChild ( 'a' ) ;
59
+ expect ( trieNode . hasChild ( 'a' ) ) . toBe ( false ) ;
60
+ } ) ;
61
+
62
+ it ( 'should NOT delete child node if the child node has children' , ( ) => {
63
+ const trieNode = new TrieNode ( 'c' ) ;
64
+ trieNode . addChild ( 'a' ) ;
65
+ const childNode = trieNode . getChild ( 'a' ) ;
66
+ childNode . addChild ( 'r' ) ;
67
+
68
+ trieNode . removeChild ( 'a' ) ;
69
+ expect ( trieNode . hasChild ( 'a' ) ) . toEqual ( true ) ;
70
+ } ) ;
71
+
72
+ it ( 'should NOT delete child node if the child node completes a word' , ( ) => {
73
+ const trieNode = new TrieNode ( 'c' ) ;
74
+ const IS_COMPLETE_WORD = true ;
75
+ trieNode . addChild ( 'a' , IS_COMPLETE_WORD ) ;
76
+
77
+ trieNode . removeChild ( 'a' ) ;
78
+ expect ( trieNode . hasChild ( 'a' ) ) . toEqual ( true ) ;
79
+ } ) ;
82
80
} ) ;
0 commit comments