public void Solve_testSys_ArgumentException() { double[,] testSys = { { 3, -2, 1 }, { 6, -4, 0 } }; LinearEquationsSystem linEquaSys = new LinearEquationsSystem(testSys); var result = linEquaSys.Solve(); }
public void LinearEquationsSystem_sys4x4_FormatException() { //double[,] testSys = { { 2, 5, 4, 0, 20 }, // { 0, 3, 2, 0, 11 }, // { 2, 10, 9, 7, 40 }, // { 3, 8, 9, 2, 37 } }; LinearEquationsSystem linEquaSys = new LinearEquationsSystem(testSys1); }
public void SetCoefficients_sys4x4_FormatException() { double[,] testSys = { { 2, 5, 4 }, { 0, 3, 2 }, { 2, 10, 40 }, { 3, 8, 9 } }; LinearEquationsSystem linEquaSys = new LinearEquationsSystem(); linEquaSys.SetCoefficients(testSys); }
public void TestEquationSystemSetCoefficientsInvalidArrayThrowException() { LinearEquationsSystem system = new LinearEquationsSystem(); Assert.Multiple(() => { Assert.Throws <Exception>(() => system.SetCoefficients(new double[1, 1])); Assert.Throws <Exception>(() => system.SetCoefficients(new double[1, 2])); Assert.Throws <Exception>(() => system.SetCoefficients(new double[2, 1])); Assert.Throws <Exception>(() => system.SetCoefficients(new double[3, 3])); }); }
public void TestEquationSystemSolveZeroDeterminantThrowException() { var stub = new FakeDeterminantSolverZero(); LinearEquationsSystem system = new LinearEquationsSystem() { DeterminantSolver = stub }; system.SetCoefficients(new double[, ] { { 0, 0 }, { 0, 0 } }); Assert.Throws <Exception>(() => system.Solve()); }
public void LinearEquationsSystem_testSys_roots() { double[,] testSys = { { 1, 2, 3, 1 }, { 2, -1, 2, 6 }, { 1, 1, 5, -1 } }; double[] rootsSys = { 4, 0, -1 }; LinearEquationsSystem linEquaSys = new LinearEquationsSystem(testSys); double[] result = linEquaSys.Solve(); CollectionAssert.AreEqual(result, rootsSys); }
public void TestDeterminantSolverGetCalled() { var mock = new FakeDeterminantSolver(); LinearEquationsSystem system = new LinearEquationsSystem() { DeterminantSolver = mock }; system.SetCoefficients(new double[, ] { { 1, 2 }, { 3, 4 } }); system.Solve(); Assert.That(mock.CallsCount, Is.AtLeast(1)); }
public void TestEquationSystemSolveZeroDeterminantThrowException() { var mock = new Mock <IDeterminantSolver>(); mock.Setup(i => i.Determinant(It.IsAny <Matrix>())).Returns(0); LinearEquationsSystem system = new LinearEquationsSystem() { DeterminantSolver = mock.Object }; system.SetCoefficients(new double[, ] { { 1, 2 }, { 3, 4 } }); Assert.Throws <Exception>(() => system.Solve()); }
public void Solve_IndefiniteSystem_HasNoRoots() { var linearEquationsSystem = new LinearEquationsSystem(); var testEquations = new List<LinearEquation> { new LinearEquation(new List<double> { -3.0, 9.0, -7.0, 11.0, -1.0}, 17.0), new LinearEquation(new List<double> { -1.0, 2.0, -4.0, 5.0, -14.0}, 9.0), new LinearEquation(new List<double> { 4.0, -2.0, 19.0, -2.0, 1.0}, -42.0), }; linearEquationsSystem.DeleteEquations(); linearEquationsSystem.AddEquations(testEquations); var expectedRoots = new List<double>(); linearEquationsSystem.Solve(); Assert.IsTrue(linearEquationsSystem.IsCompatible, "System is compatible"); Assert.IsFalse(linearEquationsSystem.IsDefinite, "System is not definite, there is infinite number of roots"); CollectionAssert.AreEqual(expectedRoots, linearEquationsSystem.Roots, "Method shoul not find roots for indefinite system"); }
public void Solve_CorrectRoots_Calculated() { var linearEquationsSystem = new LinearEquationsSystem(); var testEquations = new List<LinearEquation> { new LinearEquation(new List<double> {-3.0, 9.0, -7.0}, 17.0), new LinearEquation(new List<double> {-1.0, 2.0, -4.0}, 9.0), new LinearEquation(new List<double> { 4.0, -2.0, 19.0}, -42.0) }; linearEquationsSystem.DeleteEquations(); linearEquationsSystem.AddEquations(testEquations); var expectedRoots = new List<double> { -1.0, 0.0, -2.0 }; linearEquationsSystem.Solve(); Assert.IsTrue(linearEquationsSystem.IsCompatible, "System is compatible"); Assert.IsTrue(linearEquationsSystem.IsDefinite, "System is definite"); CollectionAssert.AreEqual(expectedRoots, linearEquationsSystem.Roots, "Correct roots are found"); }
public void TestDeterminantSolverCalls() { var mock = new Mock <IDeterminantSolver>(); mock.Setup(i => i.Determinant(It.IsAny <Matrix>())).Returns(1); LinearEquationsSystem system = new LinearEquationsSystem() { DeterminantSolver = mock.Object }; Matrix m = new Matrix(1, 2, 3, 4); var arg = new[, ] { { m.M11, m.M12 }, { m.M21, m.M22 } }; system.SetCoefficients(arg); system.Solve(); mock.Verify(i => i.Determinant(m), Times.Once); }
public void SetCoefficients_ZeroDeterminantMatrix_ArgumentException(double[,] d) { var l = new LinearEquationsSystem(); Assert.Throws <ArgumentException>(() => { l.SetCoefficients(d); }); }
public void LinearEquationsSystemConstructor_NotCorrectSizeMatrix_FormatException(double[,] d) { Assert.Throws <FormatException>(() => { linear = new LinearEquationsSystem(d); }); }
public void Setup() { linear = new LinearEquationsSystem(); }