public static void RunTests() { //This mostly follows the format established by the original author of these tests Test test = new Test(); Driver <SimpleRef <int>, SimpleRef <String> > driver1 = new Driver <SimpleRef <int>, SimpleRef <String> >(test); Driver <SimpleRef <String>, SimpleRef <int> > driver2 = new Driver <SimpleRef <String>, SimpleRef <int> >(test); Driver <SimpleRef <int>, SimpleRef <int> > driver3 = new Driver <SimpleRef <int>, SimpleRef <int> >(test); Driver <SimpleRef <String>, SimpleRef <String> > driver4 = new Driver <SimpleRef <String>, SimpleRef <String> >(test); SimpleRef <int>[] ints = new SimpleRef <int>[] { new SimpleRef <int>(1), new SimpleRef <int>(2), new SimpleRef <int>(3) }; SimpleRef <String>[] strings = new SimpleRef <String>[] { new SimpleRef <String>("1"), new SimpleRef <String>("2"), new SimpleRef <String>("3") }; //Scenario 1: Vanilla - Create a SortedList and check that default properties are set driver1.TestVanilla(); driver2.TestVanilla(); driver3.TestVanilla(); driver4.TestVanilla(); //Scenario 2: Vanilla - Make sure that we can add key-value pairs to this driver1.TestCanAdd(ints, strings); driver2.TestCanAdd(strings, ints); driver3.TestCanAdd(ints, ints); driver4.TestCanAdd(strings, strings); Assert.True(test.result); }
private Sequence CreateAbbaRule() { var ruleA = new SimpleRef(new Terminal("A", "A")); var ruleB = new SimpleRef(new Terminal("B", "B")); return(new Sequence("TEST", EnumSequence.Of(ruleA, ruleB, ruleB, ruleA))); }
private Choice CreateAOrBRule() { var ruleA = new SimpleRef(new Terminal("A")); var ruleB = new SimpleRef(new Terminal("B")); return(new Choice("TEST", EnumSequence.Of(ruleA, ruleB))); }
/// <summary>A reference which gets set to provided value before each test.</summary> public SimpleRef <A> let <A>(Fn <A> createInitialValue) { var r = new SimpleRef <A>(createInitialValue()); Action reinit = () => r.value = createInitialValue(); currentContext = currentContext.addBeforeEach(reinit); return(r); }
private static SimpleRef <String>[] GetSimpleStrings(int count) { SimpleRef <String>[] simpleStrings = new SimpleRef <String> [count]; for (int i = 0; i < count; i++) { simpleStrings[i] = new SimpleRef <String>(i.ToString()); } return(simpleStrings); }
private static SimpleRef <int>[] GetSimpleInts(int count) { SimpleRef <int>[] simpleInts = new SimpleRef <int> [count]; for (int i = 0; i < count; i++) { simpleInts[i] = new SimpleRef <int>(i); } return(simpleInts); }
public static void SortedDictionary_ValueCollectionTest2() { IntGenerator intGenerator = new IntGenerator(); StringGenerator stringGenerator = new StringGenerator(); intGenerator.NextValue(); stringGenerator.NextValue(); Driver <int, int> intDriver = new Driver <int, int>(); Driver <SimpleRef <String>, SimpleRef <String> > simpleRef = new Driver <SimpleRef <String>, SimpleRef <String> >(); Driver <SimpleRef <int>, SimpleRef <int> > simpleVal = new Driver <SimpleRef <int>, SimpleRef <int> >(); //Scenario 3: Check the underlying reference. Change the SortedDictionary afterwards and examine ICollection keys and make sure that the //change is reflected int count = 100; SimpleRef <int>[] simpleInts = SortedDictionaryUtils.GetSimpleInts(count); SimpleRef <String>[] simpleStrings = SortedDictionaryUtils.GetSimpleStrings(count); int[] ints = new int[count]; int half = count / 2; SimpleRef <int>[] simpleInts_1 = new SimpleRef <int> [half]; SimpleRef <String>[] simpleStrings_1 = new SimpleRef <String> [half]; SimpleRef <int>[] simpleInts_2 = new SimpleRef <int> [half]; SimpleRef <String>[] simpleStrings_2 = new SimpleRef <String> [half]; for (int i = 0; i < count; i++) { ints[i] = i; } int[] ints_1 = new int[half]; int[] ints_2 = new int[half]; for (int i = 0; i < half; i++) { simpleInts_1[i] = simpleInts[i]; simpleStrings_1[i] = simpleStrings[i]; ints_1[i] = ints[i]; simpleInts_2[i] = simpleInts[i + half]; simpleStrings_2[i] = simpleStrings[i + half]; ints_2[i] = ints[i + half]; } intDriver.TestModify(ints_1, ints_1, ints_2); simpleRef.TestModify(simpleStrings_1, simpleStrings_1, simpleStrings_2); simpleVal.TestModify(simpleInts_1, simpleInts_1, simpleInts_2); intDriver.NonGenericIDictionaryTestModify(ints_1, ints_1, ints_2); simpleRef.NonGenericIDictionaryTestModify(simpleStrings_1, simpleStrings_1, simpleStrings_2); simpleVal.NonGenericIDictionaryTestModify(simpleInts_1, simpleInts_1, simpleInts_2); }
public static void RunTests() { //This mostly follows the format established by the original author of these tests Test test = new Test(); Driver <SimpleRef <int>, SimpleRef <String> > driver1 = new Driver <SimpleRef <int>, SimpleRef <String> >(test); Driver <SimpleRef <String>, SimpleRef <int> > driver2 = new Driver <SimpleRef <String>, SimpleRef <int> >(test); Driver <SimpleRef <int>, SimpleRef <int> > driver3 = new Driver <SimpleRef <int>, SimpleRef <int> >(test); Driver <SimpleRef <String>, SimpleRef <String> > driver4 = new Driver <SimpleRef <String>, SimpleRef <String> >(test); SimpleRef <int>[] ints = new SimpleRef <int>[] { new SimpleRef <int>(1), new SimpleRef <int>(2), new SimpleRef <int>(3) }; SimpleRef <String>[] strings = new SimpleRef <String>[] { new SimpleRef <String>("1"), new SimpleRef <String>("2"), new SimpleRef <String>("3") }; //Scenario 1: Vanilla - Create SortedList using a vanilla capacity value and check int[] validValues = { 0, 1, 2, 5, 10, 16, 32, 50, 500, 5000, 10000 }; for (int i = 0; i < validValues.Length; i++) { driver1.TestVanilla(validValues[i]); driver2.TestVanilla(validValues[i]); driver3.TestVanilla(validValues[i]); driver4.TestVanilla(validValues[i]); driver1.TestCanAdd(ints, strings, validValues[i]); driver2.TestCanAdd(strings, ints, validValues[i]); driver3.TestCanAdd(ints, ints, validValues[i]); driver4.TestCanAdd(strings, strings, validValues[i]); } //Scnenario 2: Parm validation: negative int[] negativeValues = { -1, -2, -5, Int32.MinValue }; for (int i = 0; i < negativeValues.Length; i++) { driver1.TestParm(negativeValues[i]); driver2.TestParm(negativeValues[i]); driver3.TestParm(negativeValues[i]); driver4.TestParm(negativeValues[i]); } Assert.True(test.result); }
public static void SortedDictionary_DefaultCtorTest() { Driver <SimpleRef <int>, SimpleRef <String> > driver1 = new Driver <SimpleRef <int>, SimpleRef <String> >(); Driver <SimpleRef <String>, SimpleRef <int> > driver2 = new Driver <SimpleRef <String>, SimpleRef <int> >(); Driver <SimpleRef <int>, SimpleRef <int> > driver3 = new Driver <SimpleRef <int>, SimpleRef <int> >(); Driver <SimpleRef <String>, SimpleRef <String> > driver4 = new Driver <SimpleRef <String>, SimpleRef <String> >(); SimpleRef <int>[] ints = new SimpleRef <int>[] { new SimpleRef <int>(1), new SimpleRef <int>(2), new SimpleRef <int>(3) }; SimpleRef <String>[] strings = new SimpleRef <String>[] { new SimpleRef <String>("1"), new SimpleRef <String>("2"), new SimpleRef <String>("3") }; //Scenario 1: Vanilla - Create a SortedDictionary and check that default properties are set driver1.TestVanilla(); driver2.TestVanilla(); driver3.TestVanilla(); driver4.TestVanilla(); //Scenario 2: Vanilla - Make sure that we can add key-value pairs to this driver1.TestCanAdd(ints, strings); driver2.TestCanAdd(strings, ints); driver3.TestCanAdd(ints, ints); driver4.TestCanAdd(strings, strings); }
public static void RunTests() { //This mostly follows the format established by the original author of these tests Test test = new Test(); //Scenario 1: Vanilla - check that existing values can be accessed via the key Driver <int, int> IntDriver = new Driver <int, int>(test); Driver <SimpleRef <String>, SimpleRef <String> > simpleRef = new Driver <SimpleRef <String>, SimpleRef <String> >(test); Driver <SimpleRef <int>, SimpleRef <int> > simpleVal = new Driver <SimpleRef <int>, SimpleRef <int> >(test); SimpleRef <int>[] simpleInts; SimpleRef <String>[] simpleStrings; int[] ints; int count; count = 1000; simpleInts = SortedListUtils.GetSimpleInts(count); simpleStrings = SortedListUtils.GetSimpleStrings(count); ints = new int[count]; for (int i = 0; i < count; i++) { ints[i] = i; } IntDriver.TestVanilla(ints, ints); simpleRef.TestVanilla(simpleStrings, simpleStrings); simpleVal.TestVanilla(simpleInts, simpleInts); IntDriver.NonGenericIDictionaryTestVanilla(ints, ints); simpleRef.NonGenericIDictionaryTestVanilla(simpleStrings, simpleStrings); simpleVal.NonGenericIDictionaryTestVanilla(simpleInts, simpleInts); //Scenario 2: Check that the existing values can be modified via the key //Scneario 3: Check that non-existing values are created via set IntDriver.TestModify(ints, ints); simpleRef.TestModify(simpleStrings, simpleStrings); simpleVal.TestModify(simpleInts, simpleInts); IntDriver.NonGenericIDictionaryTestModify(ints, ints); simpleRef.NonGenericIDictionaryTestModify(simpleStrings, simpleStrings); simpleVal.NonGenericIDictionaryTestModify(simpleInts, simpleInts); //Scenario 4: Check the returned value for non existing keys SimpleRef <int>[] simpleInts_1; SimpleRef <String>[] simpleStrings_1; int[] ints_1; SimpleRef <int>[] simpleInts_2; SimpleRef <String>[] simpleStrings_2; int[] ints_2; int half = count / 2; simpleInts_1 = new SimpleRef <int> [half]; simpleStrings_1 = new SimpleRef <String> [half]; ints_2 = new int[half]; simpleInts_2 = new SimpleRef <int> [half]; simpleStrings_2 = new SimpleRef <String> [half]; ints_1 = new int[half]; for (int i = 0; i < half; i++) { simpleInts_1[i] = simpleInts[i]; simpleStrings_1[i] = simpleStrings[i]; ints_1[i] = ints[i]; simpleInts_2[i] = simpleInts[i + half]; simpleStrings_2[i] = simpleStrings[i + half]; ints_2[i] = ints[i + half]; } IntDriver.TestNonExistentKeys(ints_1, ints_1, ints_2); simpleRef.TestNonExistentKeys(simpleStrings_1, simpleStrings_1, simpleStrings_2); simpleVal.TestNonExistentKeys(simpleInts_1, simpleInts_1, simpleInts_2); IntDriver.NonGenericIDictionaryTestNonExistentKeys(ints_1, ints_1, ints_2); simpleRef.NonGenericIDictionaryTestNonExistentKeys(simpleStrings_1, simpleStrings_1, simpleStrings_2); simpleVal.NonGenericIDictionaryTestNonExistentKeys(simpleInts_1, simpleInts_1, simpleInts_2); //Scenario 5: Parm validation: null, Empty string simpleRef.TestParm(simpleStrings, simpleStrings); simpleVal.TestParm(simpleInts, simpleInts); simpleRef.NonGenericIDictionaryTestParm(simpleStrings, simpleStrings); simpleVal.NonGenericIDictionaryTestParm(simpleInts, simpleInts); IntDriver.NonGenericIDictionaryTestParm(ints_1, ints_2); Assert.True(test.result); }
public static void SortedDictionary_KeyCollectionTest1() { IntGenerator intGenerator = new IntGenerator(); StringGenerator stringGenerator = new StringGenerator(); intGenerator.NextValue(); stringGenerator.NextValue(); //Scenario 1: Vanilla - fill in an SortedDictionary with 10 keys and check this property Driver <int, int> IntDriver = new Driver <int, int>(); Driver <SimpleRef <String>, SimpleRef <String> > simpleRef = new Driver <SimpleRef <String>, SimpleRef <String> >(); Driver <SimpleRef <int>, SimpleRef <int> > simpleVal = new Driver <SimpleRef <int>, SimpleRef <int> >(); int count = 1000; SimpleRef <int>[] simpleInts = SortedDictionaryUtils.GetSimpleInts(count); SimpleRef <String>[] simpleStrings = SortedDictionaryUtils.GetSimpleStrings(count); int[] ints = new int[count]; for (int i = 0; i < count; i++) { ints[i] = i; } IntDriver.TestVanilla(ints, ints); simpleRef.TestVanilla(simpleStrings, simpleStrings); simpleVal.TestVanilla(simpleInts, simpleInts); IntDriver.NonGenericIDictionaryTestVanilla(ints, ints); simpleRef.NonGenericIDictionaryTestVanilla(simpleStrings, simpleStrings); simpleVal.NonGenericIDictionaryTestVanilla(simpleInts, simpleInts); //Scenario 2: Check for an empty SortedDictionary IntDriver.TestVanilla(new int[0], new int[0]); simpleRef.TestVanilla(new SimpleRef <String> [0], new SimpleRef <String> [0]); simpleVal.TestVanilla(new SimpleRef <int> [0], new SimpleRef <int> [0]); IntDriver.NonGenericIDictionaryTestVanilla(new int[0], new int[0]); simpleRef.NonGenericIDictionaryTestVanilla(new SimpleRef <String> [0], new SimpleRef <String> [0]); simpleVal.NonGenericIDictionaryTestVanilla(new SimpleRef <int> [0], new SimpleRef <int> [0]); //Scenario 3: Check the underlying reference. Change the SortedDictionary afterwards and examine ICollection keys and make sure that the //change is reflected int half = count / 2; SimpleRef <int>[] simpleInts_1 = new SimpleRef <int> [half]; SimpleRef <String>[] simpleStrings_1 = new SimpleRef <String> [half]; SimpleRef <int>[] simpleInts_2 = new SimpleRef <int> [half]; SimpleRef <String>[] simpleStrings_2 = new SimpleRef <String> [half]; int[] ints_1 = new int[half]; int[] ints_2 = new int[half]; for (int i = 0; i < half; i++) { simpleInts_1[i] = simpleInts[i]; simpleStrings_1[i] = simpleStrings[i]; ints_1[i] = ints[i]; simpleInts_2[i] = simpleInts[i + half]; simpleStrings_2[i] = simpleStrings[i + half]; ints_2[i] = ints[i + half]; } IntDriver.TestModify(ints_1, ints_1, ints_2); simpleRef.TestModify(simpleStrings_1, simpleStrings_1, simpleStrings_2); simpleVal.TestModify(simpleInts_1, simpleInts_1, simpleInts_2); IntDriver.NonGenericIDictionaryTestModify(ints_1, ints_1, ints_2); simpleRef.NonGenericIDictionaryTestModify(simpleStrings_1, simpleStrings_1, simpleStrings_2); simpleVal.NonGenericIDictionaryTestModify(simpleInts_1, simpleInts_1, simpleInts_2); }
private Repeat CreateARepeatedRule(int min = 0, int max = -1) { var ruleA = new SimpleRef(new Terminal("A", "A")); return(new Repeat("TEST", ruleA, min, max)); }
private And CreateAndARule() { var ruleA = new SimpleRef(new Terminal("A")); return(new And("TEST", ruleA)); }
private Not CreateNotARule() { var ruleA = new SimpleRef(new Terminal("A")); return(new Not("TEST", ruleA)); }