public void CheckIfAllLCSAreOutputed() { string s1 = "Just a simple test, nothing more."; string s2 = "Something not so...simple, want more."; var expected = new string[] { "thing ", "simple", " more." }; var LCSs = LongestCommonSubstringFinder.GetAllLCS(s1, s2); Assert.IsTrue(LCSs.Count == expected.Length); for (int i = 0; i < expected.Length; i++) { Assert.IsTrue(LCSs.Contains(expected[i])); } s1 = "Кирилицата е много хубав език."; s2 = "Пиши на кирилица... много красив език."; expected = new string[] { "ирилица", " много ", "в език." }; LCSs = LongestCommonSubstringFinder.GetAllLCS(s1, s2); Assert.IsTrue(LCSs.Count == expected.Length); for (int i = 0; i < expected.Length; i++) { Assert.IsTrue(LCSs.Contains(expected[i])); } s1 = "a b c d e f g h i j k l m n"; s2 = "n m l k j i h g f e d c b a"; expected = new string[] { " b ", " c ", " d ", " e ", " f ", " g ", " h ", " i ", " j ", " k ", " l ", " m " }; LCSs = LongestCommonSubstringFinder.GetAllLCS(s1, s2); Assert.IsTrue(LCSs.Count == expected.Length); for (int i = 0; i < expected.Length; i++) { Assert.IsTrue(LCSs.Contains(expected[i])); } s1 = "52352345235"; s2 = "assadgasdfasf"; expected = new string[] { }; LCSs = LongestCommonSubstringFinder.GetAllLCS(s1, s2); Assert.IsTrue(LCSs.Count == expected.Length); }
public void RandomStringCheckIfAllLCSAreFoundInStrings() { var rand = new Random(Environment.TickCount); int stringsLength = 100; int numOfDifferentSymbols = 10; int numberOfTests = 1000; for (int t = 0; t < numberOfTests; t++) { // Create first string var sb = new StringBuilder(); for (int i = 0; i < stringsLength; i++) { sb.Append((char)rand.Next(numOfDifferentSymbols)); } string s1 = sb.ToString(); // Create second string sb.Length = 0; for (int i = 0; i < stringsLength; i++) { sb.Append((char)rand.Next(numOfDifferentSymbols)); } string s2 = sb.ToString(); // Check LCSs int lcsLength; var allLCSs = LongestCommonSubstringFinder.GetAllLCS(s1, s2, out lcsLength); foreach (var lcs in allLCSs) { Assert.IsTrue(s1.Contains(lcs)); Assert.IsTrue(s2.Contains(lcs)); Assert.IsTrue(lcs.Length == lcsLength); } } }