From 44fcd74a88f5de429b8f28011fe4ad437de97027 Mon Sep 17 00:00:00 2001 From: Alex Dyachenko Date: Thu, 21 May 2015 22:00:31 -0400 Subject: [PATCH] Pre-merge cleanup --- .../HugeFloatTests/Arithmetic.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/mpir.net/mpir.net-tests/HugeFloatTests/Arithmetic.cs b/mpir.net/mpir.net-tests/HugeFloatTests/Arithmetic.cs index 2c3739b6..4b82fac6 100644 --- a/mpir.net/mpir.net-tests/HugeFloatTests/Arithmetic.cs +++ b/mpir.net/mpir.net-tests/HugeFloatTests/Arithmetic.cs @@ -22,6 +22,47 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; namespace MPIR.Tests.HugeFloatTests { + public static class FloatAssert + { + public static void AreEqual(string expected, HugeFloat actual) + { + var actualStr = actual.ToString(); + if(expected[0] == '-') + { + Assert.AreEqual(expected[0], actualStr[0]); + actualStr = actualStr.TrimStart('-'); + expected = expected.TrimStart('-'); + } + + var exponent = expected.IndexOf('.'); + if(exponent < 0) exponent = expected.Length; + expected = expected.Replace(".", ""); + + var exponentStr = "@" + exponent; + + Assert.IsTrue(actualStr.StartsWith("0.")); + actualStr = actualStr.Substring(2); + + Assert.IsTrue(actualStr.EndsWith(exponentStr)); + actualStr = actualStr.Substring(0, actualStr.Length - exponentStr.Length); + + if (expected.Length > actualStr.Length) + { + var roundedUp = expected[actualStr.Length] >= '5'; + expected = expected.Substring(0, actualStr.Length); + if(roundedUp) + { + using (var a = new HugeInt(expected)) + { + a.Value += 1; + expected = a.ToString(10); + } + } + } + Assert.AreEqual(expected, actualStr); + } + } + [TestClass] public class Arithmetic {