-
Notifications
You must be signed in to change notification settings - Fork 293
/
Trie_Tests.cs
106 lines (82 loc) · 3.64 KB
/
Trie_Tests.cs
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System.Linq;
using Advanced.Algorithms.DataStructures;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Advanced.Algorithms.Tests.DataStructures
{
[TestClass]
public class TrieTests
{
[TestMethod]
public void Trie_Smoke_Test_Banana()
{
var trie = new Trie<char>();
trie.Insert("banana".ToCharArray());
Assert.IsTrue(trie.Contains("banana".ToCharArray()));
trie.Insert("anana".ToCharArray());
Assert.IsTrue(trie.Contains("anana".ToCharArray()));
trie.Insert("nana".ToCharArray());
Assert.IsTrue(trie.Contains("nana".ToCharArray()));
Assert.IsFalse(trie.Contains("banan".ToCharArray()));
Assert.IsTrue(trie.ContainsPrefix("banan".ToCharArray()));
trie.Insert("ana".ToCharArray());
Assert.IsTrue(trie.Contains("ana".ToCharArray()));
trie.Insert("na".ToCharArray());
Assert.IsTrue(trie.Contains("na".ToCharArray()));
trie.Insert("a".ToCharArray());
Assert.IsTrue(trie.Contains("a".ToCharArray()));
Assert.IsTrue(trie.Count == 6);
//IEnumerable test
Assert.AreEqual(trie.Count, trie.Count());
Assert.IsTrue(trie.Contains("banana".ToCharArray()));
trie.Delete("banana".ToCharArray());
Assert.IsFalse(trie.Contains("banana".ToCharArray()));
Assert.IsTrue(trie.Contains("anana".ToCharArray()));
trie.Delete("anana".ToCharArray());
Assert.IsFalse(trie.Contains("anana".ToCharArray()));
Assert.IsTrue(trie.Contains("nana".ToCharArray()));
trie.Delete("nana".ToCharArray());
Assert.IsFalse(trie.Contains("nana".ToCharArray()));
Assert.IsTrue(trie.Contains("ana".ToCharArray()));
trie.Delete("ana".ToCharArray());
Assert.IsFalse(trie.Contains("ana".ToCharArray()));
Assert.IsTrue(trie.Contains("na".ToCharArray()));
trie.Delete("na".ToCharArray());
Assert.IsFalse(trie.Contains("na".ToCharArray()));
Assert.IsTrue(trie.Contains("a".ToCharArray()));
trie.Delete("a".ToCharArray());
Assert.IsFalse(trie.Contains("a".ToCharArray()));
Assert.IsTrue(trie.Count == 0);
//IEnumerable test
Assert.AreEqual(trie.Count, trie.Count());
}
/// <summary>
/// A tree test
/// </summary>
[TestMethod]
public void Trie_Smoke_Test()
{
var trie = new Trie<char>();
trie.Insert("abcd".ToCharArray());
trie.Insert("abcde".ToCharArray());
trie.Insert("bcde".ToCharArray());
trie.Insert("cdab".ToCharArray());
trie.Insert("efghi".ToCharArray());
Assert.IsTrue(trie.Contains("cdab".ToCharArray()));
Assert.IsFalse(trie.Contains("ab".ToCharArray()));
trie.Delete("cdab".ToCharArray());
Assert.IsFalse(trie.Contains("cdab".ToCharArray()));
//IEnumerable test
Assert.AreEqual(trie.Count, trie.Count());
var matches = trie.StartsWith("b".ToCharArray());
Assert.IsTrue(matches.Count == 1);
matches = trie.StartsWith("abcd".ToCharArray());
Assert.IsTrue(matches.Count == 2);
trie.Delete("abcd".ToCharArray());
trie.Delete("abcde".ToCharArray());
trie.Delete("bcde".ToCharArray());
trie.Delete("efghi".ToCharArray());
//IEnumerable test
Assert.AreEqual(trie.Count, trie.Count());
}
}
}