public void GetLoadTest() { #region getting test data from file var testIn = File.ReadAllLines("test.in"); int dictionaryLength = int.Parse(testIn[0]); var dictionaryData = testIn. Skip(1). Take(dictionaryLength). Select(_ => _.Split(' ')). Select(_ => new { value = _[0], relevancy = int.Parse(_[1]) } ); int testPrefixCount = int.Parse(testIn[dictionaryLength + 1]); var testPrefixData = testIn. Skip(dictionaryLength + 1 + 1). Take(testPrefixCount).ToArray(); #endregion var trie = new ItemTrie(); foreach (var a in dictionaryData) { trie.Add(a.value, a.relevancy); } trie.Prepare(10); var timer = Stopwatch.StartNew(); foreach (var a in testPrefixData) { trie.Get(a); } timer.Stop(); Assert.IsTrue(timer.Elapsed.Milliseconds <= 500, "operation takes longer than half a second on the test data"); }
public void GetTest() { var trie = new ItemTrie(); trie.Add("kare", 10); trie.Add("kanojo", 20); trie.Add("karetachi", 1); trie.Add("korosu", 7); trie.Add("sakura", 3); trie.Prepare(10); Assert.AreEqual(4, trie.Get("k").Count()); Assert.AreEqual(3, trie.Get("ka").Count()); Assert.AreEqual(2, trie.Get("kar").Count()); }
public static void Main() { var testIn = ReadAllInput().ToArray(); int dictionaryLength = int.Parse(testIn[0]); var dictionaryData = testIn. Skip(1). Take(dictionaryLength). Select(_ => _.Split(' ')). Select(_ => new { value = _[0], relevancy = int.Parse(_[1]) } ); int testPrefixCount = int.Parse(testIn[dictionaryLength + 1]); var testPrefixData = testIn. Skip(dictionaryLength + 1 + 1). Take(testPrefixCount) /*.ToArray()*/; var trie = new ItemTrie(); foreach (var a in dictionaryData) { trie.Add(a.value, a.relevancy); } trie.Prepare(10); foreach (var a in testPrefixData) { foreach (var b in trie.Get(a)) { Console.Out.WriteLine(b.Value); } Console.Out.WriteLine(); } }
public void GetTest() { var trie = new ItemTrie(); trie.Add("kare", 10); trie.Add("kanojo", 20); trie.Add("karetachi", 1); trie.Add("korosu", 7); trie.Add("sakura", 3); trie.Prepare(10); using (var server = new Server(port, trie)) using (var client = new Client("localhost", port)) { Assert.AreEqual(4, client.GetStrings("k").Count()); Assert.AreEqual(3, client.GetStrings("ka").Count()); Assert.AreEqual(2, client.GetStrings("kar").Count()); } }
private static void Init(ItemTrie trie, string file, int resultCount) { var testIn = File.ReadAllLines(file); int dictionaryLength = int.Parse(testIn[0]); var dictionaryData = testIn. Skip(1). Take(dictionaryLength). Select(_ => _.Split(' ')). Select(_ => new { value = _[0], relevancy = int.Parse(_[1]) } ); foreach (var a in dictionaryData) { trie.Add(a.value, a.relevancy); } trie.Prepare(resultCount); }
public void GetLoadTest() { #region getting test data from file var testIn = File.ReadAllLines("test.in"); int dictionaryLength = int.Parse(testIn[0]); var dictionaryData = testIn. Skip(1). Take(dictionaryLength). Select(_ => _.Split(' ')). Select(_ => new { value = _[0], relevancy = int.Parse(_[1]) } ); int testPrefixCount = int.Parse(testIn[dictionaryLength + 1]); var testPrefixData = testIn. Skip(dictionaryLength + 1 + 1). Take(testPrefixCount).ToArray(); #endregion var trie = new ItemTrie(); foreach (var a in dictionaryData) { trie.Add(a.value, a.relevancy); } trie.Prepare(10); using (var server = new Server(port, trie)) using (var client1 = new Client("localhost", port)) using (var client2 = new Client("localhost", port)) using (var client3 = new Client("localhost", port)) using (var client4 = new Client("localhost", port)) using (var client5 = new Client("localhost", port)) using (var client6 = new Client("localhost", port)) using (var client7 = new Client("localhost", port)) using (var client8 = new Client("localhost", port)) using (var client9 = new Client("localhost", port)) { var timer = Stopwatch.StartNew(); foreach (var a in testPrefixData) { client1.GetStrings(a); client2.GetStrings(a); client3.GetStrings(a); client4.GetStrings(a); client5.GetStrings(a); client6.GetStrings(a); client7.GetStrings(a); client8.GetStrings(a); client9.GetStrings(a); } timer.Stop(); Assert.IsTrue(timer.Elapsed.Milliseconds <= 500 * 9, "operation takes longer than half a second per client on the test data"); } }