File tree 1 file changed +26
-0
lines changed
src/_DataStructures_/Trees/Trie/unique-word-count
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ const Trie = require ( '../index' ) ;
2
+ const uniqueWordCount = require ( '.' ) ;
3
+
4
+ describe ( 'Trie Unique Word Count' , ( ) => {
5
+ it ( 'counts an empty trie' , ( ) => {
6
+ const trie = new Trie ( ) ;
7
+ const wordCount = uniqueWordCount ( trie . root ) ;
8
+ expect ( wordCount ) . toEqual ( 0 ) ;
9
+ } ) ;
10
+
11
+ it ( 'counts unique words' , ( ) => {
12
+ const trie = new Trie ( ) ;
13
+ const words = [ 'one' , 'two' , 'three' , 'four' ] ;
14
+ words . forEach ( word => trie . insert ( word ) ) ;
15
+ const wordCount = uniqueWordCount ( trie . root ) ;
16
+ expect ( wordCount ) . toEqual ( 4 ) ;
17
+ } ) ;
18
+
19
+ it ( 'does not count duplicate words' , ( ) => {
20
+ const trie = new Trie ( ) ;
21
+ const words = [ 'one' , 'one' , 'two' , 'three' ] ;
22
+ words . forEach ( word => trie . insert ( word ) ) ;
23
+ const wordCount = uniqueWordCount ( trie . root ) ;
24
+ expect ( wordCount ) . toEqual ( 3 ) ;
25
+ } ) ;
26
+ } ) ;
You can’t perform that action at this time.
0 commit comments