static void Succeed <TData>( Func <TData, IndexValuePair>[] operators, TData data, IndexValuePair expected) where TData : class { for (int i = 0; i < operators.Length; i++) { var actual = operators[i](data); IndexValuePairAssert.AreEqual( expected: expected, actual: actual, delta: DoubleMatrixTest.Accuracy); } }
public static List<Token> ParseInput(string input) { var indexes = new Dictionary<int, IndexValuePair>(); var index = 0; foreach (var token in Entries) { var r = new Regex(token.CommandLineEntryAttribute.Token); var m = r.Match(input); if (m.Success) { indexes[index++] = new IndexValuePair() { Index = m.Index, MethodInfo = token }; } } var orderedIndexes = indexes.OrderBy(i => i.Value.Index).ToArray(); var inputTokens = new List<Token>(); for (int i = 0; i < orderedIndexes.Length - 1; i++) { var length = orderedIndexes[i + 1].Value.Index - orderedIndexes[i].Value.Index; inputTokens.Add(new Token() { Parameter = orderedIndexes[i].Value.MethodInfo.CommandLineEntryAttribute.Token, Value = input.Substring(orderedIndexes[i].Value.Index, length).Substring(2), Description = orderedIndexes[i].Value.MethodInfo.CommandLineEntryAttribute.Description, TimeoutInSeconds = orderedIndexes[i].Value.MethodInfo.CommandLineEntryAttribute.TimeoutInSeconds, MethodInfo = orderedIndexes[i].Value.MethodInfo.MethodInfo } ); } var lastLength = input.Length - orderedIndexes[orderedIndexes.Length - 1].Value.Index; inputTokens.Add(new Token() { Parameter = orderedIndexes[orderedIndexes.Length - 1].Value.MethodInfo.CommandLineEntryAttribute.Token, Value = input.Substring(orderedIndexes[orderedIndexes.Length - 1].Value.Index, lastLength).Substring(2), Description = orderedIndexes[orderedIndexes.Length - 1].Value.MethodInfo.CommandLineEntryAttribute.Description, MethodInfo = orderedIndexes[orderedIndexes.Length - 1].Value.MethodInfo.MethodInfo, TimeoutInSeconds = orderedIndexes[orderedIndexes.Length - 1].Value.MethodInfo.CommandLineEntryAttribute.TimeoutInSeconds }); return inputTokens; }
/// <summary> /// Asserts that the specified /// <see cref="IndexValuePair"/> instances are equal. /// </summary> /// <param name="expected">The expected instance.</param> /// <param name="actual">The actual instance.</param> /// <param name="delta">The required accuracy.</param> /// <param name="message">The message to include in the exception /// if the instances are not equal.</param> /// <exception cref="AssertFailedException"> /// A value is unexpected.</br> /// -or-</br> /// An index is unexpected</br> /// </exception> public static void AreEqual( IndexValuePair expected, IndexValuePair actual, double delta, string message = null) { // IndexValuePair state Assert.AreEqual( expected.Index, actual.Index, "Wrong index in IndexValuePair. " + message); Assert.AreEqual( expected.Value, actual.Value, delta, "Wrong value in IndexValuePair. " + message); }