public void TestRandomSequence(ISorter <int> sorter) { var input = new int[] { 45, 11, 299, 30, 51, 0 }; var expected = new int[] { 0, 11, 30, 45, 51, 299 }; SorterTestsHelper.TestSorter(input, expected, sorter); }
public void TestReverseSortedSequence(ISorter <int> sorter) { var input = Enumerable.Range(-3, testLength).Reverse().ToArray(); var expected = Enumerable.Range(-3, testLength).ToArray(); SorterTestsHelper.TestSorter(input, expected, sorter); }
public void TestSortedSequence(ISorter <string> sorter) { var input = new string[] { "a", "b", "c", "d", "e" }; var expected = new string[] { "a", "b", "c", "d", "e" }; SorterTestsHelper.TestSorter(input, expected, sorter); }
public void TestAllSorters <T>() { Type sorterTesterType = typeof(ISorterTester <T>); var sorterTesterTypes = this.allTypes .Where(type => sorterTesterType.IsAssignableFrom(type) && !type.IsGenericTypeDefinition) .ToArray(); Assert.IsTrue(sorterTesterTypes.Any(), "there is no sorter for this type of data"); var sorterHelper = Activator.CreateInstance(sorterTesterTypes[0]) as ISorterTester <T>; foreach (Type sorterType in this.sorterTypes) { ISorter <T> sorterImplementation = null; if (sorterType.IsGenericTypeDefinition) { Type[] typeArgs = { typeof(T) }; Type constructed = sorterType.MakeGenericType(typeArgs); sorterImplementation = Activator.CreateInstance(constructed) as ISorter <T>; } else if (typeof(ISorter <T>).IsAssignableFrom(sorterType)) { sorterImplementation = Activator.CreateInstance(sorterType) as ISorter <T>; } if (sorterImplementation != null) { sorterHelper.TestSortedSequence(sorterImplementation); sorterHelper.TestReverseSortedSequence(sorterImplementation); sorterHelper.TestRandomSequence(sorterImplementation); SorterTestsHelper.TestSorterOnEmptyData(sorterImplementation); } } }
public void TestSortedSequence(ISorter <char> sorter) { var input = new char[] { 'a', 'b', 'c', 'd', 'e' }; var expected = new char[] { 'a', 'b', 'c', 'd', 'e' }; SorterTestsHelper.TestSorter(input, expected, sorter); }
public void TestSortedSequence(ISorter <int> sorter) { var baseSequense = Enumerable.Range(1, testLength); var input = baseSequense.ToArray(); var expected = baseSequense.ToArray(); SorterTestsHelper.TestSorter(input, expected, sorter); }
public void TestRandomSequence(ISorter <double> sorter) { var input = new double[] { 4.5, 1.5, 2.5, 3.5, 5.5 }; var expected = Enumerable .Range(1, 5) .Select(x => x + 0.5) .ToArray(); SorterTestsHelper.TestSorter(input, expected, sorter); }