forked from code-shoily/algorithms-in-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrie_test.dart
63 lines (47 loc) · 1.63 KB
/
trie_test.dart
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
import 'package:test/test.dart';
import 'package:algorithms/trie/trie.dart';
void main() {
Trie emptyTrie, trie, customTrie;
setUp(() {
emptyTrie = Trie.ofAlphabets();
trie = Trie.ofAlphabets();
trie.add('algorithms');
customTrie = Trie(
{'a', 'b', 'f', 'o', 'r', 'z'}, (value) => value.toString().split(''));
customTrie.add('foo');
});
test('Components', () {
expect(trie.components,
equals({...List.generate(26, (i) => String.fromCharCode(122 - i))}));
expect(customTrie.components, equals({'f', 'o', 'b', 'a', 'r', 'z'}));
});
test('Empty trie', () {
expect(emptyTrie.isEmpty, isTrue);
expect(trie.isEmpty, isFalse);
});
test('Add value', () {
trie.add('hi');
expect(trie.root.children[7].children[8].isValue, isTrue);
customTrie.add('bar');
expect(customTrie.root.children[1].children[0].children[4].isValue, isTrue);
customTrie.add('baz');
expect(customTrie.root.children[1].children[0].children[5].isValue, isTrue);
});
test('Contains value', () {
expect(emptyTrie.contains('test'), isFalse);
expect(trie.contains('algorithm'), isFalse);
expect(trie.contains('algorithms'), isTrue);
expect(customTrie.contains('boar'), isFalse);
expect(customTrie.contains('foo'), isTrue);
});
test('Delete value', () {
emptyTrie.delete('');
emptyTrie.delete('test');
expect(trie.contains('algorithms'), isTrue);
trie.delete('algorithms');
expect(trie.contains('algorithms'), isFalse);
expect(customTrie.contains('foo'), isTrue);
customTrie.delete('foo');
expect(customTrie.contains('foo'), isFalse);
});
}