summaryrefslogtreecommitdiff
path: root/Source/UnitTests
diff options
context:
space:
mode:
authorGravatar Dan Liew <daniel.liew@imperial.ac.uk>2015-03-10 11:40:54 +0000
committerGravatar Dan Liew <daniel.liew@imperial.ac.uk>2015-03-10 11:40:54 +0000
commitdca03793b807bbd066d6886c97ac7131f80508d4 (patch)
treef32587d9d48d6e048d3eb57cd864ed46a6b3ed67 /Source/UnitTests
parent1550a8112d172a37a168b048b5c78642bc39bf90 (diff)
Fix bug in BigDec.FloorCeiling() which gave the wrong answers for
negative numbers. I have decided that this method will floor towards negative infinity rather than zero to match SMT-LIBv2's to_int function.
Diffstat (limited to 'Source/UnitTests')
-rw-r--r--Source/UnitTests/BasetypesTests/BigDecTests.cs31
1 files changed, 31 insertions, 0 deletions
diff --git a/Source/UnitTests/BasetypesTests/BigDecTests.cs b/Source/UnitTests/BasetypesTests/BigDecTests.cs
index cee80216..4c26a21a 100644
--- a/Source/UnitTests/BasetypesTests/BigDecTests.cs
+++ b/Source/UnitTests/BasetypesTests/BigDecTests.cs
@@ -24,6 +24,37 @@ namespace BasetypesTests
Assert.AreEqual(-1, v.Exponent);
Assert.AreEqual(new BigInteger(15.0), v.Mantissa);
}
+
+ [TestCase("0.0", 0, 0)]
+ [TestCase("5.0", 5, 5)]
+ [TestCase("5.5", 5, 6)]
+ [TestCase("5.9", 5, 6)]
+ [TestCase("15e1", 150, 150)]
+ [TestCase("15e-1", 1, 2)]
+ // Negative values
+ // Note we expect floor to round towards negative infinity
+ // and ceiling to round towards positive infinity
+ [TestCase("-15e-1", -2, -1)]
+ [TestCase("-5.0", -5, -5)]
+ [TestCase("-5e0", -5, -5)]
+ [TestCase("-5e1", -50, -50)]
+ [TestCase("-5e-1", -1, 0)]
+ [TestCase("-5.5", -6, -5)]
+ [TestCase("-5.9", -6, -5)]
+ public void FloorAndCeil(string value, int expectedFloor, int expectedCeiling)
+ {
+ var v = BigDec.FromString(value);
+ if (value.StartsWith ("-"))
+ Assert.IsTrue(v.IsNegative);
+ else
+ Assert.IsTrue(v.IsPositive || v.IsZero);
+
+ BigInteger floor = 0;
+ BigInteger ceiling = 0;
+ v.FloorCeiling(out floor, out ceiling);
+ Assert.AreEqual(new BigInteger(expectedFloor), floor);
+ Assert.AreEqual(new BigInteger(expectedCeiling), ceiling);
+ }
}
}