Exemplo n.º 1
0
		/// <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);
				}
			}
		}
Exemplo n.º 2
0
		/// <summary> Returns a sequence of objects which are either testcases or strings, which each represent an element in linear positional conjuction. </summary>
		private static Testcase DivideLinearBox(string aidedTestcase)
		{
			int indexInUnaidedTestcase = 0;//TODO: Simplify: is identical to i right?
			var leaves = new List<object>();
			for (int i = 0; i < aidedTestcase.Length; i++)
			{
				char c = aidedTestcase[i];
				if (c == '[')
				{
					string boxCompositionSubstring = GetStringUntilNextClosingSquareBracket(aidedTestcase, i);
					var scriptBoxes = DivideScriptBoxComposition(boxCompositionSubstring);
					var tc = new Testcase((SortedReadOnlyList<ICompositeNotationForm<TestDomain>>)ScriptNotations.EnabledNotations, scriptBoxes.ToArray());
					leaves.Add(new Tuple<object, IPosition>(tc, new LinearPosition(indexInUnaidedTestcase)));


					i += "[".Length + boxCompositionSubstring.Length;//length of [ is added in regular for-loop increment
					indexInUnaidedTestcase++;
				}
				else if (c == ']')
				{
					Contract.Assert(false, "Unmatched ']'");
					//Contract.Assert(expressionConstruction != null);
					//expressions.Add(new string(expressionConstruction.ToArray()));
					//expressionConstruction = null;
				}
				else if (c != '(' && c != ')')
				{
					leaves.Add(new Tuple<object, IPosition>(c.ToString(), new LinearPosition(indexInUnaidedTestcase)));
					indexInUnaidedTestcase++;
				}
			}

			//LinearPositionCollection positionCollection = new LinearPositionCollection(0, leaves.Count);
			//return new Testcase(LinearNotations.EnabledNotations, leaves.Select((o, i) => new Tuple<object, IPosition>(o, positionCollection[i])).ToArray());
			return new Testcase(LinearNotations.EnabledNotations, leaves.ToArray());
		}