/// <summary> Tests the specified expression on all possible caching methods for specified existence of unary operators. </summary> /// <param name="unaidedTestcase"> The expression to test, where each character is converted to the corresponding test domain. </param> /// <param name="cachingMethod"> The setting on which caching method to apply in this test. </param> /// <param name="enableUnaryPlusMinusOperators"> The setting on whether on not to include unary operators in this test. </param> /// <param name="partialExpectations"> Parts of the expected result, which are tested to be part of the result. Specify null to indicate expected failure. </param> private static void Test(Testcase unaidedTestcase, UnaryOperatorEnabledness enableUnaryPlusMinusOperators, TestASTNode[] partialExpectations, bool toExpectOrNotToExpect) { TestDomain.UseOtherNumberTypes = false; UnaryOperators.Enabled = enableUnaryPlusMinusOperators == UnaryOperatorEnabledness.Enabled; SortedReadOnlyList<ICompositeNotationForm<TestDomain>> enabledNotations; var testExpressions = unaidedTestcase.ToExpressions(out enabledNotations).ToList(); Contract.Assert(enabledNotations.Count != 0); ASTBaseNode result = GetAST(testExpressions, enabledNotations); //the actual tests: if (partialExpectations == null) { //check that is failed if failure is expected Contract.Assert(result == null); } else { Contract.Assert(partialExpectations.Any(), "You're testing nothing"); //otherwise, check whether the result contains each partial expectation foreach (TestASTNode partialExpectation in partialExpectations) { if (partialExpectation.Position is LinearPosition) Contract.Assert(((LinearPosition)partialExpectation.Position).EndIndex <= testExpressions.Count, "Test expectations are impossible to begin with"); Contract.Assert(Contains(result, partialExpectation) == toExpectOrNotToExpect); } } }
public static void Test(string aidedTestcase, UnaryOperatorEnabledness enabledUnOp, params TestASTNode[] partialExpectations) { var testcase = Testcase.Create(aidedTestcase); Test(testcase, enabledUnOp, partialExpectations, true); }
public static void TestWithAutomatedExpectations(string aidedTestcase, UnaryOperatorEnabledness a, params TestASTNode[] additionalExpectations) { Test(Testcase.Create(aidedTestcase), a, TestResolution.InferExpectations(aidedTestcase).Concat(additionalExpectations).ToArray(), true); }