summaryrefslogtreecommitdiff
path: root/Source/UnitTests
diff options
context:
space:
mode:
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);
+ }
}
}