/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() { return (Givens.GetHashCode() ^ When.GetHashCode() ^ Thens.GetHashCode()); }
public void Cleanup() { try { foreach (var given in Givens.Select(x => new { Method = x.Key, Text = x.Value })) { if (!Context.CleanUps.ContainsKey(given.Text)) { continue; } var result = Context.TestRunContext[TestType.Name + given.Text]; //if it doesn't take arguments just execute it if (!Context.CleanUps[given.Text].Method.GetParameters().Any()) { Context.CleanUps[given.Text].DynamicInvoke(); continue; } //if it takes one argument pass in the result if (Context.CleanUps[given.Text].Method.GetParameters().Count() == 1) { Context.CleanUps[given.Text].DynamicInvoke(result); continue; } //if it takes multiple arguments parse the tuple and pass them in var count = result.GetType().GetGenericArguments().Count(); if (count > 0) { var type = result.GetType(); var argList = new List <object>(); for (int i = 1; i <= count; i++) { argList.Add(type.GetProperty("Item" + i).GetValue(result, null)); } Context.CleanUps[given.Text].DynamicInvoke(argList.ToArray()); continue; } Console.WriteLine("Found cleanup for {0} but didn't know how to call it", given.Text); } foreach (var teardownMethod in _teardownMethods) { teardownMethod.Invoke(); } } catch { } }
public void When_Transpose_Q(int size) { // Arrange Random device = new Random(); Matrix A = new Matrix(size, size); Matrix I = new Matrix(size, size); for (int i = 0; i < size; i++) { I.Elem[i][i] = 1; for (int j = 0; j < size; j++) { A.Elem[i][j] = device.NextDouble(); } } Matrix Q1 = new Matrix(A.Row, A.Column); Matrix R1 = new Matrix(A.Row, A.Column); Matrix Q2 = new Matrix(A.Row, A.Column); Matrix R2 = new Matrix(A.Row, A.Column); Matrix Q3 = new Matrix(A.Row, A.Column); Matrix R3 = new Matrix(A.Row, A.Column); for (int i = 0; i < A.Row; i++) { Q3.Elem[i][i] = 1.0; } Matrix Q4 = new Matrix(A.Row, A.Column); Matrix R4 = new Matrix(A.Row, A.Column); for (int i = 0; i < A.Row; i++) { Q4.Elem[i][i] = 1.0; } GramSchmidt.Classic(A, Q1, R1); GramSchmidt.Modified(A, Q2, R2); Givens.Orthogon(A, Q3, R3); Householder.Orthogon(A, Q4, R4); // Act Matrix QT1 = Q1.Transpose(); Matrix QT2 = Q2.Transpose(); Matrix QT3 = Q3.Transpose(); Matrix QT4 = Q4.Transpose(); // Assert Assert.That(QT1 * Q1 == I); Assert.That(QT2 * Q2 == I); Assert.That(QT3 * Q3 == I); Assert.That(QT4 * Q4 == I); }
public static void rotate12(SMat3 vtav, Mat3 v) { if (vtav.m12 == 0) { return; } float c = 0, s = 0; Schur2.rot12(vtav, c, s); Givens.rot12_post(v, c, s); }
public static void Rotate01(SMat3 vtav, Mat3 v) { if (vtav.m01 == 0) { return; } double c = 0, s = 0; Schur2.Rot01(vtav, c, s); Givens.Rot01Post(v, c, s); }
public static void rotate01(SMat3 vtav, Mat3 v) { if (vtav.m01 == 0) { return; } float c = 0, s = 0; Schur2.rot01(vtav, c, s); Givens.rot01_post(v, c, s); }
public static void Rotate12(SMat3 vtav, Mat3 v) { if (vtav.m12 == 0) { return; } double c = 0, s = 0; Schur2.Rot12(vtav, c, s); Givens.Rot12Post(v, c, s); }
public static Givens <T> Givens <T>(this ScenarioContext scenario) where T : class { Givens <T> givens; ScenarioContext.Current.TryGetValue(out givens); if (givens == null) { givens = new Givens <T>(); ScenarioContext.Current.Set(givens); } return(givens); }
public static void rotate12(out SMat3 vtav, out Mat3 v, SMat3 ivtav, Mat3 iv) { vtav = ivtav; v = iv; if (vtav.m12 == 0) { return; } float c, s; rot12(out vtav, out c, out s, vtav, c, s); Givens.rot12_post(out v, c, s, v); }
/// <summary> /// Resolves a provided reference of forms "X" or "X.Y" and passes back the first given or /// derivation which matches. /// </summary> /// <param name="reference">The string reference for the given or derivative</param> /// <returns>An IValue representing either the given or derivation the reference points to.</returns> internal IValue ResolveReference(string reference, string ElementScope) { //Find near givens with a full reference first. IValue val = Givens.Find(t => t.Key == ElementScope + "." + reference); if (val == null) { //Ok, try near givens with a partial reference val = Givens.Find(t => t.Key == reference); } //Ok, givens exhausted; find me a derivation with that reference. if (val == null) { string[] references = reference.Split('.'); Element el = Elements.Find(t => t.ElementName == references[0]); if (el == null) { throw new ArgumentException("Unable to reference expression element"); } val = el.Derivations.Find(t => t.Name == references[1]); } return(val); }
public void When_Solve_ORT() { // Arrange Matrix A = new Matrix(3, 3); A.Elem[0][0] = 2; A.Elem[0][1] = 3; A.Elem[0][2] = -1; A.Elem[1][0] = 1; A.Elem[1][1] = -2; A.Elem[1][2] = 1; A.Elem[2][0] = 1; A.Elem[2][1] = 0; A.Elem[2][2] = 2; Vector F = new Vector(3); F.Elem[0] = 9; F.Elem[1] = 3; F.Elem[2] = 2; // Act Vector gramSchmidtC = GramSchmidt.StartModifiedSolverQR(A, F); Vector gramSchmidtM = GramSchmidt.StartModifiedSolverQR(A, F); Vector givens = Givens.StartSolverQR(A, F); Vector householder = Householder.StartSolverQR(A, F); // Assert Assert.That(A * gramSchmidtC == F); Assert.That(A * gramSchmidtM == F); Assert.That(A * givens == F); Assert.That(A * householder == F); }
public void AddGiven(string text, Delegate method) { Givens.Add(method, text); }
public CodeCompletionFeatureSteps Given(string text) { Givens.Add(text); return(this); }
public DictionaryConverterTests() { Given = new Givens(); Then = new Thens(); }
/// <summary> /// Invoke the given invoker /// </summary> /// <returns>the next step</returns> public GivenStep Given(IInvokable invokable) { return(Givens.Given(this, invokable)); }
public void Given(IMatcher notWhatYouWantUseInserterInstead) { throw Givens.NewGivenMatcherError(); }
/// <summary> /// Invoke an inserter /// </summary> /// <returns>the next step</returns> public GivenStep Given(IInserter inserter) { return(Givens.Given(Scenario, inserter)); }
public void OnSetup() { Given = new Givens(); Then = new Thens(); }
/// <summary> /// Invoke an inserter /// </summary> /// <returns>the next step</returns> public GivenStep Given(IInserter inserter) { return(Givens.Given(this, inserter)); }
/// <summary> /// Invoke an action /// </summary> /// <returns>the next step</returns> public GivenStep Given(Action action) { return(Givens.Given(this, action)); }
/// <summary> /// Invoke an updater /// </summary> /// <returns>the next step</returns> public GivenStep Given(IUpdater updater) { return(Givens.Given(Scenario, updater)); }
/// <summary> /// Invoke the given invoker /// </summary> /// <returns>the next step</returns> public GivenStep Given(IInvokable invokable) { return(Givens.Given(Scenario, invokable)); }
/// <summary> /// Invoke an action /// </summary> /// <returns>the next step</returns> public GivenStep Given(Action givenAction) { return(Givens.Given(Scenario, givenAction)); }
/// <summary> /// Pass in an instance which can be passed to the nest step. /// </summary> /// <param name="instance">the instance to pass back</param> /// <returns>a step containing the passed in instance</returns> public GivenStep Given(Object instance) { return(Givens.Given(Scenario, instance)); }
/// <summary> /// Invoke the given action passing in the current scenario /// </summary> /// <param name="scenarioExtensionAction"></param> /// <returns></returns> public GivenStep Given(Action <Scenario> scenarioExtensionAction) { return(Givens.Given(Scenario, scenarioExtensionAction)); }
/// <summary> /// Check that the current state is what is expected before carrying on. Useful when steps are failing. Fails the scenario /// if the matcher fails. Think of this as a sanity test of your test setup code /// </summary> /// <param name="fetcher">retreives the value to check</param> /// <param name="matcher">the matcher to check the value</param> /// <returns>the next step</returns> public GivenStep CheckingAssumption <T>(IFetcher <T> fetcher, IMatcher <T> matcher) { return(Givens.Checking(Scenario, fetcher, matcher)); }
/// <summary> /// Pass in an instance which is dependency injected /// </summary> /// <param name="instance">the instance to pass back</param> /// <returns>the next step</returns> public GivenStep Given(Object instance) { return(Givens.Given(this, instance)); }
internal void AddGiven(Given given) { Givens.Add(given); }
/// <summary> /// Check that the current state is what is expected before carrying on. Useful when steps are failing. Fails the scenario /// if the matcher fails. Think of this as a sanity test of your test setup code /// </summary> /// <param name="actual">the value to check</param> /// <param name="matcher">the matcher to check the value</param> /// <returns>the next step</returns> public GivenStep CheckingAssumption <T>(T actual, IMatcher <T> matcher) { return(Givens.Checking <T>(Scenario, actual, matcher)); }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() => Givens.GetHashCode() ^ When.GetHashCode() ^ Throws.GetHashCode();
/// <summary> /// Check that the current state is what is expected before carrying. Useful when steps are failing. Fails the scenario /// if the matcher fails. Think of this as a sanity test of your test setup code /// </summary> /// <param name="func">retreives the value to check</param> /// <param name="matcher">the matcher to check the value</param> /// <returns>the next step</returns> public GivenStep CheckingAssumption <T>(Func <T> func, IMatcher <T> matcher) { return(Givens.Checking(Scenario, func, matcher)); }