Fixed MPIR.Net unit tests

This commit is contained in:
Alex Dyachenko 2019-06-28 12:18:50 -04:00
parent 5aab0cf7b0
commit 0aacd623e9
6 changed files with 27 additions and 12 deletions

View File

@ -65,14 +65,14 @@ namespace MPIR.Tests.HugeFloatTests
[TestClass] [TestClass]
public class Arithmetic public class Arithmetic
{ {
[ClassInitialize] [TestInitialize]
public static void Setup(TestContext context) public void Setup()
{ {
HugeFloat.DefaultPrecision = 128; HugeFloat.DefaultPrecision = 128;
} }
[ClassCleanup] [TestCleanup]
public static void Cleanup() public void Cleanup()
{ {
HugeFloat.DefaultPrecision = 64; HugeFloat.DefaultPrecision = 64;
} }

View File

@ -69,6 +69,9 @@ namespace MPIR.Tests.HugeFloatTests
[TestMethod] [TestMethod]
public void FloatCompareToHugeIntExpression() public void FloatCompareToHugeIntExpression()
{ {
var previousDefaultPrecision = HugeFloat.DefaultPrecision;
HugeFloat.DefaultPrecision = 256;
using (var a = new HugeFloat("-222509832503450298345039835740293845721345345354")) using (var a = new HugeFloat("-222509832503450298345039835740293845721345345354"))
using (var b = new HugeInt("222509832503450298345039835740293845721345345353")) using (var b = new HugeInt("222509832503450298345039835740293845721345345353"))
{ {
@ -82,6 +85,8 @@ namespace MPIR.Tests.HugeFloatTests
Assert.AreEqual(-1, Math.Sign((a + 1).CompareTo(1 - b))); Assert.AreEqual(-1, Math.Sign((a + 1).CompareTo(1 - b)));
Assert.AreEqual(1, Math.Sign((a + 1).CompareTo(-b - 1))); Assert.AreEqual(1, Math.Sign((a + 1).CompareTo(-b - 1)));
} }
HugeFloat.DefaultPrecision = previousDefaultPrecision;
} }
[TestMethod] [TestMethod]

View File

@ -32,11 +32,16 @@ namespace MPIR.Tests.HugeFloatTests
public static void Init(TestContext context) public static void Init(TestContext context)
{ {
AlmostOne = new HugeFloat(0.99999); AlmostOne = new HugeFloat(0.99999);
}
[TestInitialize]
public void TestInit()
{
HugeFloat.DefaultPrecision = 128; HugeFloat.DefaultPrecision = 128;
} }
[ClassCleanup] [TestCleanup]
public static void Cleanup() public void Cleanup()
{ {
HugeFloat.DefaultPrecision = 64; HugeFloat.DefaultPrecision = 64;
} }

View File

@ -30,8 +30,8 @@ namespace MPIR.Tests.HugeFloatTests
[TestClass] [TestClass]
public class ExpressionTests public class ExpressionTests
{ {
[ClassInitialize] [TestInitialize]
public static void Setup(TestContext context) public void Setup()
{ {
HugeFloat.DefaultPrecision = 64; HugeFloat.DefaultPrecision = 64;
} }

View File

@ -28,14 +28,14 @@ namespace MPIR.Tests.HugeFloatTests
[TestClass] [TestClass]
public class Precision public class Precision
{ {
[ClassInitialize] [TestInitialize]
public static void Setup(TestContext context) public void Setup()
{ {
HugeFloat.DefaultPrecision = 128; HugeFloat.DefaultPrecision = 128;
} }
[ClassCleanup] [TestCleanup]
public static void Cleanup() public void Cleanup()
{ {
HugeFloat.DefaultPrecision = 64; HugeFloat.DefaultPrecision = 64;
} }

View File

@ -69,6 +69,9 @@ namespace MPIR.Tests.HugeIntTests
[TestMethod] [TestMethod]
public void IntCompareToHugeFloatExpression() public void IntCompareToHugeFloatExpression()
{ {
var previousPrecision = HugeFloat.DefaultPrecision;
HugeFloat.DefaultPrecision = 256;
using (var a = new HugeInt("-222509832503450298345039835740293845721345345354")) using (var a = new HugeInt("-222509832503450298345039835740293845721345345354"))
using (var b = new HugeFloat("222509832503450298345039835740293845721345345353")) using (var b = new HugeFloat("222509832503450298345039835740293845721345345353"))
{ {
@ -82,6 +85,8 @@ namespace MPIR.Tests.HugeIntTests
Assert.AreEqual(-1, System.Math.Sign((a + 1).CompareTo(1 - b))); Assert.AreEqual(-1, System.Math.Sign((a + 1).CompareTo(1 - b)));
Assert.AreEqual(1, System.Math.Sign((a + 1).CompareTo(-b - 1))); Assert.AreEqual(1, System.Math.Sign((a + 1).CompareTo(-b - 1)));
} }
HugeFloat.DefaultPrecision = previousPrecision;
} }
[TestMethod] [TestMethod]