public void sampleInput2() { List <string[]> oData = GetInputData(_sTestDataRootDir + "sampleinput02_input.txt"); List <string[]> result = new List <string[]>(); List <string[]> expected = new List <string[]>(); expected.Add(new string[2] { "1", "3" }); expected.Add(new string[2] { "2", "6" }); expected.Add(new string[3] { "0", "1", "5" }); foreach (string[] arr in oData) { int[] r = SaveHumanity.GetVirusIndices(arr[0], arr[1]); if (r[0] == -1) { result.Add(new string[1] { "No Match!" }); } else { result.Add(r.Select(i => i.ToString()).ToArray()); } } CollectionAssert.AreEqual(expected, result); }
public void HackerrankTests(int testNum) { string inFile = string.Format("{0}hackerrank{1}_input.txt", _sTestDataRootDir, testNum); List <string[]> oData = GetInputData(inFile); string ansFile = string.Format("{0}hackerrank{1}_answer.txt", _sTestDataRootDir, testNum); List <string[]> expected = GetAnswerData(ansFile, oData.Count); int testCounter = 0; Stopwatch sw = new Stopwatch(); Assert.Multiple(() => { foreach (string[] arr in oData) { Debug.WriteLine(string.Format("Test number: {0}", testCounter + 1)); Debug.WriteLine(string.Format("Size of human DNA strand: {0}", arr[0].Length)); Debug.WriteLine(string.Format("Size of virus DNA strand: {0}", arr[1].Length)); Debug.WriteLine(string.Format("Ratio of virus length to human dna length: {0}", (float)arr[1].Length / (float)arr[0].Length)); SaveHumanity.ToleranceCheckCounter = 0; SaveHumanity.EqualityCheckCounter = 0; sw.Start(); string sFailMsg = string.Format("Failed on sub-test {0}", testCounter + 1); int[] r = SaveHumanity.GetVirusIndices(arr[0], arr[1]); if (r[0] == -1) { CollectionAssert.AreEqual(expected.ElementAt(testCounter), new string[1] { "No Match!" }, sFailMsg); } else { CollectionAssert.AreEqual(expected.ElementAt(testCounter), r.Select(i => i.ToString()).ToArray(), sFailMsg); } sw.Stop(); string dbgResult = (r[0] == -1) ? "No Match!" : string.Format("{0} locations found.", r.Length); Debug.WriteLine(string.Format("Number of checks done because hash was within tolerance: {0}", SaveHumanity.ToleranceCheckCounter)); Debug.WriteLine(string.Format("Number of equality checks performed: {0}", SaveHumanity.EqualityCheckCounter)); Debug.WriteLine(dbgResult); Debug.WriteLine(string.Format("Time elapsed: {0} seconds", (float)sw.ElapsedMilliseconds / 1000.0)); Debug.WriteLine(""); testCounter++; sw.Reset(); } }); }
public void sampleInput1() { List <string[]> oData = GetInputData(_sTestDataRootDir + "sampleinput01_input.txt"); List <string[]> expected = new List <string[]>(); expected.Add(new string[2] { "1", "2" }); expected.Add(new string[1] { "No Match!" }); expected.Add(new string[2] { "0", "2" }); int testCounter = 0; Assert.Multiple(() => { foreach (string[] arr in oData) { int[] r = SaveHumanity.GetVirusIndices(arr[0], arr[1]); if (r[0] == -1) { CollectionAssert.AreEqual(expected.ElementAt(testCounter), new string[1] { "No Match!" }); } else { CollectionAssert.AreEqual(expected.ElementAt(testCounter), r.Select(i => i.ToString()).ToArray()); } testCounter++; } }); }