public void RationalMakeAbsolute() { using (var a = new HugeRational("-24092854092874502983745029345723098457209/115756986668303657898962467957")) { a.Value = a.Abs(); Assert.AreEqual("24092854092874502983745029345723098457209/115756986668303657898962467957", a.ToString()); a.Value = a.Abs(); Assert.AreEqual("24092854092874502983745029345723098457209/115756986668303657898962467957", a.ToString()); } }
public void RationalTestAllExpressions() { var baseExpr = typeof(RationalExpression); var allExpressions = baseExpr.Assembly.GetTypes() .Where(x => baseExpr.IsAssignableFrom(x) && !x.IsAbstract) .ToList(); var one = Platform.Ui(1, 1); using (var a = new HugeRational(-9, 1)) using (var b = new HugeRational(4, 1)) using (var c = new HugeInt(3)) using (var r = MpirRandom.Default()) { var expr = a + (-a * 2) * 3 * (a.Abs() * -2 + -64 + a * a) + (one * 116U) + a; VerifyPartialResult(r, expr, 44); expr = expr + a * 5 + (a + b) * (b + 1) * (b + -3) * b + (b * -a) - (b * (one * 25U)) - a + (b << 3) - ((a * b) << 1); VerifyPartialResult(r, expr, -52); expr = expr - 2 - 3U + (b - (a << 1)) + (b * b - (one * 15U)) * (b - a) * (a - 11) * (b - 3U) - (-340 - a) + ((one * 20U) - b); VerifyPartialResult(r, expr, 52); expr = expr + (-7 - 2 * a) + (28U - 4 * b) + -(a + b * 2) + (3 * a).Abs(); VerifyPartialResult(r, expr, 103); expr = 36 * (expr / a + expr / (3 * b) - a / b) - b / (a + 10) + 6; VerifyPartialResult(r, expr, -20); expr = expr + (b >> 1) + ((b / -7) + (a / (one * 7U))) * 7 + (7 / a) - ((one * 2U) / (b + 5)); VerifyPartialResult(r, expr, -32); expr = expr + (((a / b).Invert() * 3) ^ 3) - (b + 13) / a / -3; VerifyPartialResult(r, expr, -35); expr = expr + c + (b - 2 * c) + (-4 * c - a) - (c - 1) * (b - 1) - (a / c) + (c * 2) / (b - 1); VerifyPartialResult(r, expr, -38); MarkExpressionsUsed(allExpressions, expr); } Assert.AreEqual(0, allExpressions.Count, "Expression types not exercised: " + string.Join("", allExpressions.Select(x => Environment.NewLine + x.Name).OrderBy(x => x))); }