1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
using Microsoft.Basetypes;
using NUnit.Framework;
using System.Numerics;
namespace BasetypesTests
{
[TestFixture()]
public class BigDecTests {
[Test()]
public void FromStringNegative() {
// This tests for a Bug in Boogie that used to be present where BigDec
// would not parse strings with negative numbers correctly
//
// If this bug is present this test will fail when checking the mantissa
var v = BigDec.FromString("-1.5");
Assert.AreEqual(-1, v.Exponent);
Assert.AreEqual(new BigInteger(-15.0), v.Mantissa);
}
[Test()]
public void FromStringPositive() {
var v = BigDec.FromString("1.5");
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);
}
}
}
|