// check equality operator public void CheckEquality() { // create two equal FiniteDifference FiniteDifference l = FiniteDifference.GetFiniteDifferenceByOrder(2); FiniteDifference r = FiniteDifference.GetFiniteDifferenceByOrder(2); Assert.True(l == r); // REMOVED AS FiniteDifference indexer changed to read-only // ***************************************************************************************************** ////////// change coefficient ////////l[0] = 2; ////////Assert.False(l == r); ////////// revert coefficient ////////l[0] = 1; ////////Assert.True(l == r); ////////// create FiniteDifference with different order ////////r = FiniteDifference.GetFiniteDifferenceByOrder(3); ////////Assert.False(l == r); ////////// change right's coefficients to match left's ////////r[0] = 1; ////////r[1] = -2; ////////r[2] = 1; ////////Assert.False(l == r); // ***************************************************************************************************** // create FiniteDifference with the same order but another minimumH r = FiniteDifference.GetFiniteDifferenceByOrderAndMinH(2, 1); Assert.False(l == r); // create same FiniteDifference l = FiniteDifference.GetFiniteDifferenceByOrderAndMinH(2, 1); Assert.True(l == r); }
// check parsing simple du public void Order1CheckWithoutH() { FiniteDifference goodDifference = FiniteDifference.GetFiniteDifferenceByOrder(1); string s = "du(x)"; Assert.True(FiniteDifference.Parse(s) == goodDifference); }
// check simple u(x) public void NodNoH() { FiniteDifference goodDifference = FiniteDifference.GetFiniteDifferenceByOrder(0); string s = "u(x)"; Assert.True(FiniteDifference.Parse(s) == goodDifference); }
// just create FiniteDifference with minimumH=0 and check order, minimumH and maximumH public void CheckOrderAfterCreating(int order) { FiniteDifference dif = FiniteDifference.GetFiniteDifferenceByOrder(order); Assert.Equal(order, dif.Order); Assert.Equal(0, dif.MinimumH); Assert.Equal(order, dif.MaximumH); }
// check returning null on creating bad order public void CheckBadOrderCreating() { Assert.Null(FiniteDifference.GetFiniteDifferenceByOrder(-1)); Assert.Null(0 * FiniteDifference.GetFiniteDifferenceByOrder(1)); // check summations Assert.Null(FiniteDifference.GetFiniteDifferenceByOrder(3) - FiniteDifference.GetFiniteDifferenceByOrder(3)); Assert.Null(FiniteDifference.GetFiniteDifferenceByOrderAndMinH(3, 2) - FiniteDifference.GetFiniteDifferenceByOrderAndMinH(2, 3) + FiniteDifference.GetFiniteDifferenceByOrderAndMinH(2, 2)); }
// check parsing d^nu and dnu public void OrderCheckWithoutH(int order) { FiniteDifference goodDifference = FiniteDifference.GetFiniteDifferenceByOrder(order); // check d^nu string s = $"d^{order}u(x)"; Assert.True(FiniteDifference.Parse(s) == goodDifference); // check dnu s = $"d{order}u(x)"; Assert.True(FiniteDifference.Parse(s) == goodDifference); }
public void CheckOperationsWithNotFiniteDifference() { // create normal FiniteDifference and two non-FiniteDifferences FiniteDifference order11 = FiniteDifference.GetFiniteDifferenceByOrder(1); FiniteDifference not1 = FiniteDifference.GetFiniteDifferenceByOrder(-1); FiniteDifference not2 = FiniteDifference.GetFiniteDifferenceByOrder(-1); // check equality Assert.True(order11 != not1); Assert.True(not1 == not2); // check multiplication Assert.Null(not1 * 2); // check summation Assert.True(order11 == order11 + not1); Assert.Null(not1 + not2); }
// check summation of multiple summands with coefficients public void CheckSummation() { string s = " d3 u(x-2*h) - 2 * du(x-h) + u(x+2*h) - 1 * d^2 u(x) "; Assert.True(FiniteDifference.GetFiniteDifferenceByOrderAndMinH(3, -2) - 2 * FiniteDifference.GetFiniteDifferenceByOrderAndMinH(1, -1) + FiniteDifference.GetFiniteDifferenceByOrderAndMinH(0, 2) - FiniteDifference.GetFiniteDifferenceByOrder(2) == DifferenceExpressionEvaluator.Evaluate(s)); s = " - d^3u(x-2*h) - 2 * du(x-h) + u(x+2*h) - 1 * d^2 u(x) "; Assert.True(-FiniteDifference.GetFiniteDifferenceByOrderAndMinH(3, -2) - 2 * FiniteDifference.GetFiniteDifferenceByOrderAndMinH(1, -1) + FiniteDifference.GetFiniteDifferenceByOrderAndMinH(0, 2) - FiniteDifference.GetFiniteDifferenceByOrder(2) == DifferenceExpressionEvaluator.Evaluate(s)); }