|
|
|
@ -1,4 +1,4 @@ |
|
|
|
// First version copied from the F# Power Pack |
|
|
|
// First version copied from the F# Power Pack |
|
|
|
// https://raw.github.com/fsharp/powerpack/master/src/FSharp.PowerPack.Unittests/BigRationalTests.fs |
|
|
|
|
|
|
|
namespace MathNet.Numerics.Tests |
|
|
|
@ -69,14 +69,14 @@ type public BigRationalTests() = |
|
|
|
points |
|
|
|
let pointsNonZero = [for p,q in points do if p<>0I then yield p,q] // non zero points |
|
|
|
|
|
|
|
let makeQs p q = |
|
|
|
let makeQs p q = |
|
|
|
if q = 1I && minIntI <= p && p <= maxIntI then |
|
|
|
// (p,1) where p is int32 |
|
|
|
let p32 = int32 p |
|
|
|
[natA p32;natB p32;BigRational.FromBigInt p] // two reprs for int32 |
|
|
|
[natA p32;natB p32;BigRational.FromBigInt p] // two reprs for int32 |
|
|
|
else |
|
|
|
[BigRational.FromBigInt p / BigRational.FromBigInt q] |
|
|
|
|
|
|
|
|
|
|
|
let miscQs = [for p,q in points do yield! makeQs p q] |
|
|
|
|
|
|
|
let product xs ys = [for x in xs do for y in ys do yield x,y] |
|
|
|
@ -84,7 +84,7 @@ type public BigRationalTests() = |
|
|
|
let vector2s = product points points |
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.BasicTests1() = |
|
|
|
member this.BasicTests1() = |
|
|
|
check "generic format h" "1N" (sprintf "%A" 1N) |
|
|
|
check "generic format q" "-1N" (sprintf "%A" (-1N)) |
|
|
|
|
|
|
|
@ -92,7 +92,7 @@ type public BigRationalTests() = |
|
|
|
test "d3oc002" (LanguagePrimitives.GenericZero<bignum> = 0N) |
|
|
|
test "d3oc112w" (LanguagePrimitives.GenericOne<bignum> = 1N) |
|
|
|
|
|
|
|
check "weioj3h" (sprintf "%O" 3N) "3" |
|
|
|
check "weioj3h" (sprintf "%O" 3N) "3" |
|
|
|
check "weioj3k" (sprintf "%O" (3N / 4N)) "3/4" |
|
|
|
check "weioj3k" (sprintf "%O" (3N / 400000000N)) "3/400000000" |
|
|
|
check "weioj3l" (sprintf "%O" (3N / 3N)) "1" |
|
|
|
@ -105,21 +105,21 @@ type public BigRationalTests() = |
|
|
|
let v = -30000000000000000000000000000000000000000000000000000000000000N |
|
|
|
check "weioj3r" (sprintf "%O" v) ((box v).ToString()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.BasicTests2() = |
|
|
|
member this.BasicTests2() = |
|
|
|
|
|
|
|
|
|
|
|
// Test arithmetic ops: tests |
|
|
|
let test2One name f check ((p,q),(pp,qq)) = |
|
|
|
let test2One name f check ((p,q),(pp,qq)) = |
|
|
|
// There may be several ways to construct the test rationals |
|
|
|
let zs = makeQs p q |
|
|
|
let zzs = makeQs pp qq |
|
|
|
let results = [for z in zs do for zz in zzs do yield f (z,zz)] |
|
|
|
let refP,refQ = check (p,q) (pp,qq) |
|
|
|
let results = [for z in zs do for zz in zzs do yield f (z,zz)] |
|
|
|
let refP,refQ = check (p,q) (pp,qq) |
|
|
|
let refResult = BigRational.FromBigInt refP / BigRational.FromBigInt refQ |
|
|
|
let resOK (result:BigRational) = |
|
|
|
result.Numerator * refQ = refP * result.Denominator && |
|
|
|
let resOK (result:BigRational) = |
|
|
|
result.Numerator * refQ = refP * result.Denominator && |
|
|
|
BigRational.Equals(refResult,result) |
|
|
|
match List.tryFind (fun result -> not (resOK result)) results with |
|
|
|
| None -> () // ok |
|
|
|
@ -135,9 +135,9 @@ type public BigRationalTests() = |
|
|
|
test2All "div" (BigRational.(/)) (fun (p,q) (pp,qq) -> (p*qq,q*pp)) (product points pointsNonZero) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.RangeTests() = |
|
|
|
member this.RangeTests() = |
|
|
|
// Test x0 .. dx .. x1 |
|
|
|
let checkRange3 (x0:BigRational) dx x1 k = |
|
|
|
let f (x:BigRational) = x * BigRational.FromBigInt k |> BigRational.ToBigInt |
|
|
|
@ -146,7 +146,7 @@ type public BigRationalTests() = |
|
|
|
//printf "Length=%d\n" (Seq.length rangeA) |
|
|
|
let same = Seq.forall2 (=) rangeA rangeB |
|
|
|
check (sprintf "Range3 %A .. %A .. %A scaled to %A" x0 dx x1 k) same true |
|
|
|
|
|
|
|
|
|
|
|
checkRange3 (0I /% 1I) (1I /% 7I) (100I /% 1I) (7I*1I) |
|
|
|
checkRange3 (0I /% 1I) (1I /% 7I) (100I /% 11I) (7I*11I) |
|
|
|
checkRange3 (1I /% 13I) (1I /% 7I) (100I /% 11I) (7I*11I*13I) |
|
|
|
@ -161,15 +161,15 @@ type public BigRationalTests() = |
|
|
|
// Test x0 .. x1 |
|
|
|
let checkRange2 (x0:BigRational) x1 = |
|
|
|
let z0 = BigRational.ToBigInt x0 |
|
|
|
let z01 = BigRational.ToBigInt (x1 - x0) |
|
|
|
let z01 = BigRational.ToBigInt (x1 - x0) |
|
|
|
let f (x:BigRational) = x |> BigRational.ToBigInt |
|
|
|
let rangeA = [x0 .. x1] |> List.map f // range with each item rounded down |
|
|
|
let rangeB = [z0 .. z0 + z01] // range of same length from the round down start point |
|
|
|
check (sprintf "Range2: %A .. %A" x0 x1) rangeA rangeB |
|
|
|
|
|
|
|
checkRange2 (0I /% 1I) (100I /% 1I) |
|
|
|
checkRange2 (0I /% 1I) (100I /% 11I) |
|
|
|
checkRange2 (1I /% 13I) (100I /% 11I) |
|
|
|
checkRange2 (0I /% 1I) (100I /% 1I) |
|
|
|
checkRange2 (0I /% 1I) (100I /% 11I) |
|
|
|
checkRange2 (1I /% 13I) (100I /% 11I) |
|
|
|
for i = 0 to 1000 do |
|
|
|
let m = 10000 // max steps is -m to m in steps of 1 i.e. 2.m |
|
|
|
let p0,q0 = nextZ m ,nextZ m + 1I |
|
|
|
@ -178,7 +178,7 @@ type public BigRationalTests() = |
|
|
|
|
|
|
|
// ToString() |
|
|
|
// Cases: integer, computed integer, rational<1, rational>1, +/-infinity, nan |
|
|
|
(natA 1).ToString() |> check "ToString" "1" |
|
|
|
(natA 1).ToString() |> check "ToString" "1" |
|
|
|
(natA 0).ToString() |> check "ToString" "0" |
|
|
|
(natA (-12)).ToString() |> check "ToString" "-12" |
|
|
|
(natB 1).ToString() |> check "ToString" "1" |
|
|
|
@ -211,29 +211,29 @@ type public BigRationalTests() = |
|
|
|
check "OneB" BigRational.One (natB 1) |
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.BinaryAndUnaryOperators() = |
|
|
|
member this.BinaryAndUnaryOperators() = |
|
|
|
// Test: generic bop |
|
|
|
let testR2One name f check ((p,q),(pp,qq)) = |
|
|
|
let testR2One name f check ((p,q),(pp,qq)) = |
|
|
|
// There may be several ways to construct the test rationals |
|
|
|
let zs = makeQs p q |
|
|
|
let zzs = makeQs pp qq |
|
|
|
let resultRef = check (p,q) (pp,qq) // : bool |
|
|
|
let args = [for z in zs do for zz in zzs do yield (z,zz)] |
|
|
|
let resultRef = check (p,q) (pp,qq) // : bool |
|
|
|
let args = [for z in zs do for zz in zzs do yield (z,zz)] |
|
|
|
match List.tryFind (fun (z,zz) -> resultRef <> f (z,zz)) args with |
|
|
|
| None -> () // ok |
|
|
|
| Some (z,zz) -> printf "Test failed. %s (%A,%A) (%A,%A) = %s %A %A. Expected %A.\n" name p q pp qq name z zz resultRef |
|
|
|
reportFailure "cknwe9" |
|
|
|
|
|
|
|
// Test: generic uop |
|
|
|
let testR1One name f check (p,q) = |
|
|
|
let testR1One name f check (p,q) = |
|
|
|
// There may be several ways to construct the test rationals |
|
|
|
let zs = makeQs p q |
|
|
|
let resultRef = check (p,q) //: bool |
|
|
|
let zs = makeQs p q |
|
|
|
let resultRef = check (p,q) //: bool |
|
|
|
match List.tryFind (fun z -> resultRef <> f z) zs with |
|
|
|
| None -> () // ok |
|
|
|
| Some z -> printf "Test failed. %s (%A,%A) = %s %A. Expected %A.\n" name p q name z resultRef |
|
|
|
reportFailure "vekjkrejvre0" |
|
|
|
|
|
|
|
|
|
|
|
let testR2All name f check vectors = List.iter (testR2One name f check) vectors |
|
|
|
let testR1All name f check vectors = List.iter (testR1One name f check) vectors |
|
|
|
|
|
|
|
@ -260,14 +260,14 @@ type public BigRationalTests() = |
|
|
|
testR1All "IsZero" (fun (x:BigRational) -> x = q0) (fun (p,q) -> sign p = 0I) vector1s |
|
|
|
|
|
|
|
|
|
|
|
let test1One name f check (p,q) = |
|
|
|
let test1One name f check (p,q) = |
|
|
|
// There may be several ways to construct the test rationals |
|
|
|
let zs = makeQs p q |
|
|
|
let zs = makeQs p q |
|
|
|
let results = [for z in zs -> f z] |
|
|
|
let refP,refQ = check (p,q) |
|
|
|
let refP,refQ = check (p,q) |
|
|
|
let refResult = BigRational.FromBigInt refP / BigRational.FromBigInt refQ |
|
|
|
let resOK (result:BigRational) = |
|
|
|
result.Numerator * refQ = refP * result.Denominator && |
|
|
|
let resOK (result:BigRational) = |
|
|
|
result.Numerator * refQ = refP * result.Denominator && |
|
|
|
BigRational.Equals(refResult,result) |
|
|
|
match List.tryFind (fun result -> not (resOK result)) results with |
|
|
|
| None -> () // ok |
|
|
|
@ -275,7 +275,7 @@ type public BigRationalTests() = |
|
|
|
reportFailure "klcwe09wek" |
|
|
|
|
|
|
|
let test1All name f check vectors = List.iter (test1One name f check) vectors |
|
|
|
|
|
|
|
|
|
|
|
test1All "neg" (BigRational.(~-)) (fun (p,q) -> (-p,q)) vector1s |
|
|
|
test1All "pos" (BigRational.(~+)) (fun (p,q) -> (p,q)) vector1s // why have ~+ ??? |
|
|
|
|
|
|
|
@ -312,27 +312,27 @@ type BigNumType() = |
|
|
|
let g_normal = 88N |
|
|
|
let g_bigintpositive = 1000000000000000000000000000000000018I |
|
|
|
let g_bigintnegative = -1000000000000000000000000000000000018I |
|
|
|
|
|
|
|
|
|
|
|
// Interfaces |
|
|
|
[<Test>] |
|
|
|
member this.IComparable() = |
|
|
|
member this.IComparable() = |
|
|
|
// Legit IC |
|
|
|
let ic = g_positive1 :> IComparable |
|
|
|
Assert.AreEqual(ic.CompareTo(g_positive1),0) |
|
|
|
let ic = g_positive1 :> IComparable |
|
|
|
Assert.AreEqual(ic.CompareTo(g_positive1),0) |
|
|
|
checkThrowsArgumentException( fun () -> ic.CompareTo(g_bigintpositive) |> ignore) |
|
|
|
|
|
|
|
|
|
|
|
// Base class methods |
|
|
|
[<Test>] |
|
|
|
member this.ObjectToString() = |
|
|
|
|
|
|
|
|
|
|
|
// Currently the CLR 4.0 and CLR 2.0 behavior of BigInt.ToString is different, causing this test to fail. |
|
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(g_positive1.ToString(), |
|
|
|
"1000000000000000000000000000000000018") |
|
|
|
Assert.AreEqual(g_zero.ToString(),"0") |
|
|
|
Assert.AreEqual(g_zero.ToString(),"0") |
|
|
|
Assert.AreEqual(g_normal.ToString(),"88") |
|
|
|
|
|
|
|
// Static methods |
|
|
|
|
|
|
|
// Static methods |
|
|
|
[<Test>] |
|
|
|
member this.Abs() = |
|
|
|
Assert.AreEqual(bignum.Abs(g_negative1), g_positive1) |
|
|
|
@ -341,7 +341,7 @@ type BigNumType() = |
|
|
|
Assert.AreEqual(bignum.Abs(g_normal), g_normal) |
|
|
|
Assert.AreEqual(bignum.Abs(g_zero), g_zero) |
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.FromBigInt() = |
|
|
|
Assert.AreEqual(bignum.FromBigInt(g_bigintpositive), |
|
|
|
@ -351,7 +351,7 @@ type BigNumType() = |
|
|
|
Assert.AreEqual(bignum.FromBigInt(0I),g_zero) |
|
|
|
Assert.AreEqual(bignum.FromBigInt(88I),g_normal) |
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.FromInt() = |
|
|
|
Assert.AreEqual(bignum.FromInt(2147483647), 2147483647N) |
|
|
|
@ -359,12 +359,12 @@ type BigNumType() = |
|
|
|
Assert.AreEqual(bignum.FromInt(0), 0N) |
|
|
|
Assert.AreEqual(bignum.FromInt(88), 88N) |
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.One() = |
|
|
|
Assert.AreEqual(bignum.One,1N) |
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.Parse() = |
|
|
|
Assert.AreEqual(bignum.Parse("100"), 100N) |
|
|
|
@ -372,7 +372,7 @@ type BigNumType() = |
|
|
|
Assert.AreEqual(bignum.Parse("0"), g_zero) |
|
|
|
Assert.AreEqual(bignum.Parse("88"), g_normal) |
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.PowN() = |
|
|
|
Assert.AreEqual(bignum.PowN(100N,2), 10000N) |
|
|
|
@ -380,8 +380,8 @@ type BigNumType() = |
|
|
|
Assert.AreEqual(bignum.PowN(g_zero,2147483647), 0N) |
|
|
|
Assert.AreEqual(bignum.PowN(g_normal,0), 1N) |
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.Sign() = |
|
|
|
Assert.AreEqual(g_positive1.Sign, 1) |
|
|
|
@ -389,9 +389,9 @@ type BigNumType() = |
|
|
|
Assert.AreEqual(g_zero.Sign, 0) |
|
|
|
Assert.AreEqual(g_normal.Sign, 1) |
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.ToBigInt() = |
|
|
|
Assert.AreEqual(bignum.ToBigInt(g_positive1), g_bigintpositive) |
|
|
|
@ -399,9 +399,9 @@ type BigNumType() = |
|
|
|
Assert.AreEqual(bignum.ToBigInt(g_zero), 0I) |
|
|
|
Assert.AreEqual(bignum.ToBigInt(g_normal), 88I) |
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.ToDouble() = |
|
|
|
Assert.AreEqual(bignum.ToDouble(179769N*1000000000000000N), 1.79769E+20) |
|
|
|
@ -413,8 +413,8 @@ type BigNumType() = |
|
|
|
Assert.AreEqual(double(0N),0.0) |
|
|
|
Assert.AreEqual(double(88N),88.0) |
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.ToInt32() = |
|
|
|
Assert.AreEqual(bignum.ToInt32(2147483647N), 2147483647) |
|
|
|
@ -425,18 +425,18 @@ type BigNumType() = |
|
|
|
Assert.AreEqual(int32(-2147483648N), -2147483648) |
|
|
|
Assert.AreEqual(int32(0N), 0) |
|
|
|
Assert.AreEqual(int32(88N), 88) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.Zero() = |
|
|
|
Assert.AreEqual(bignum.Zero,0N) |
|
|
|
() |
|
|
|
|
|
|
|
// operator methods |
|
|
|
|
|
|
|
// operator methods |
|
|
|
[<Test>] |
|
|
|
member this.test_op_Addition() = |
|
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(100N + 200N, 300N) |
|
|
|
Assert.AreEqual((-100N) + (-200N), -300N) |
|
|
|
Assert.AreEqual(g_positive1 + g_negative1, 0N) |
|
|
|
@ -444,163 +444,163 @@ type BigNumType() = |
|
|
|
Assert.AreEqual(g_normal + g_normal, 176N) |
|
|
|
Assert.AreEqual(g_normal + g_normal, 176N) |
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.test_op_Division() = |
|
|
|
Assert.AreEqual(g_positive1 / g_positive1, 1N) |
|
|
|
Assert.AreEqual(-100N / 2N, -50N) |
|
|
|
Assert.AreEqual(g_zero / g_positive1, 0N) |
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.test_op_Equality() = |
|
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue((g_positive1 = g_positive1)) |
|
|
|
Assert.IsTrue((g_negative1 = g_negative1)) |
|
|
|
Assert.IsTrue((g_zero = g_zero)) |
|
|
|
Assert.IsTrue((g_normal = g_normal)) |
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.test_op_GreaterThan() = |
|
|
|
member this.test_op_GreaterThan() = |
|
|
|
Assert.AreEqual((g_positive1 > g_positive2), true) |
|
|
|
Assert.AreEqual((g_negative1 > g_negative2), false) |
|
|
|
Assert.AreEqual((g_zero > g_zero), false) |
|
|
|
Assert.AreEqual((g_normal > g_normal), false) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
() |
|
|
|
[<Test>] |
|
|
|
member this.test_op_GreaterThanOrEqual() = |
|
|
|
member this.test_op_GreaterThanOrEqual() = |
|
|
|
Assert.AreEqual((g_positive1 >= g_positive2), true) |
|
|
|
Assert.AreEqual((g_positive2 >= g_positive1), false) |
|
|
|
Assert.AreEqual((g_positive2 >= g_positive1), false) |
|
|
|
Assert.AreEqual((g_negative1 >= g_negative1), true) |
|
|
|
Assert.AreEqual((0N >= g_zero), true) |
|
|
|
|
|
|
|
|
|
|
|
() |
|
|
|
[<Test>] |
|
|
|
member this.test_op_LessThan() = |
|
|
|
[<Test>] |
|
|
|
member this.test_op_LessThan() = |
|
|
|
Assert.AreEqual((g_positive1 < g_positive2), false) |
|
|
|
Assert.AreEqual((g_negative1 < g_negative3), false) |
|
|
|
Assert.AreEqual((0N < g_zero), false) |
|
|
|
|
|
|
|
|
|
|
|
() |
|
|
|
[<Test>] |
|
|
|
member this.test_op_LessThanOrEqual() = |
|
|
|
member this.test_op_LessThanOrEqual() = |
|
|
|
Assert.AreEqual((g_positive1 <= g_positive2), false) |
|
|
|
Assert.AreEqual((g_positive2 <= g_positive1), true) |
|
|
|
Assert.AreEqual((g_positive2 <= g_positive1), true) |
|
|
|
Assert.AreEqual((g_negative1 <= g_negative1), true) |
|
|
|
Assert.AreEqual((0N <= g_zero), true) |
|
|
|
|
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.test_op_Multiply() = |
|
|
|
member this.test_op_Multiply() = |
|
|
|
Assert.AreEqual(3N * 5N, 15N) |
|
|
|
Assert.AreEqual((-3N) * (-5N), 15N) |
|
|
|
Assert.AreEqual((-3N) * 5N, -15N) |
|
|
|
Assert.AreEqual(0N * 5N, 0N) |
|
|
|
|
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.test_op_Range() = |
|
|
|
member this.test_op_Range() = |
|
|
|
let resultPos = [0N .. 2N] |
|
|
|
let seqPos = [0N; 1N; 2N] |
|
|
|
let seqPos = [0N; 1N; 2N] |
|
|
|
verifySeqsEqual resultPos seqPos |
|
|
|
|
|
|
|
let resultNeg = [-2N .. 0N] |
|
|
|
let seqNeg = [-2N; -1N; 0N] |
|
|
|
|
|
|
|
let resultNeg = [-2N .. 0N] |
|
|
|
let seqNeg = [-2N; -1N; 0N] |
|
|
|
verifySeqsEqual resultNeg seqNeg |
|
|
|
|
|
|
|
|
|
|
|
let resultSmall = [0N ..5N] |
|
|
|
let seqSmall = [0N; 1N; 2N; 3N; 4N; 5N] |
|
|
|
let seqSmall = [0N; 1N; 2N; 3N; 4N; 5N] |
|
|
|
verifySeqsEqual resultSmall seqSmall |
|
|
|
|
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.test_op_RangeStep() = |
|
|
|
member this.test_op_RangeStep() = |
|
|
|
let resultPos = [0N .. 3N .. 6N] |
|
|
|
let seqPos = [0N; 3N; 6N] |
|
|
|
let seqPos = [0N; 3N; 6N] |
|
|
|
verifySeqsEqual resultPos seqPos |
|
|
|
|
|
|
|
let resultNeg = [-6N .. 3N .. 0N] |
|
|
|
let seqNeg = [-6N; -3N; 0N] |
|
|
|
|
|
|
|
let resultNeg = [-6N .. 3N .. 0N] |
|
|
|
let seqNeg = [-6N; -3N; 0N] |
|
|
|
verifySeqsEqual resultNeg seqNeg |
|
|
|
|
|
|
|
|
|
|
|
let resultSmall = [0N .. 3N .. 9N] |
|
|
|
let seqSmall = [0N; 3N; 6N; 9N] |
|
|
|
let seqSmall = [0N; 3N; 6N; 9N] |
|
|
|
verifySeqsEqual resultSmall seqSmall |
|
|
|
|
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.test_op_Subtraction() = |
|
|
|
member this.test_op_Subtraction() = |
|
|
|
Assert.AreEqual(g_positive1 - g_positive2,18N) |
|
|
|
Assert.AreEqual(g_negative1 - g_negative3,18N) |
|
|
|
Assert.AreEqual(0N-g_positive1, g_negative1) |
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.test_op_UnaryNegation() = |
|
|
|
member this.test_op_UnaryNegation() = |
|
|
|
Assert.AreEqual(-g_positive1, g_negative1) |
|
|
|
Assert.AreEqual(-g_negative1, g_positive1) |
|
|
|
Assert.AreEqual(-0N,0N) |
|
|
|
|
|
|
|
Assert.AreEqual(-0N,0N) |
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.test_op_UnaryPlus() = |
|
|
|
member this.test_op_UnaryPlus() = |
|
|
|
Assert.AreEqual(+g_positive1,g_positive1) |
|
|
|
Assert.AreEqual(+g_negative1,g_negative1) |
|
|
|
Assert.AreEqual(+0N, 0N) |
|
|
|
|
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
// instance methods |
|
|
|
[<Test>] |
|
|
|
member this.Denominator() = |
|
|
|
member this.Denominator() = |
|
|
|
Assert.AreEqual(g_positive1.Denominator, 1I) |
|
|
|
Assert.AreEqual(g_negative1.Denominator, 1I) |
|
|
|
Assert.AreEqual(0N.Denominator, 1I) |
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.IsNegative() = |
|
|
|
member this.IsNegative() = |
|
|
|
Assert.IsFalse(g_positive1.IsNegative) |
|
|
|
Assert.IsTrue(g_negative1.IsNegative) |
|
|
|
|
|
|
|
Assert.IsFalse( 0N.IsNegative) |
|
|
|
Assert.IsFalse(-0N.IsNegative) |
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.IsPositive() = |
|
|
|
member this.IsPositive() = |
|
|
|
|
|
|
|
Assert.IsTrue(g_positive1.IsPositive) |
|
|
|
Assert.IsFalse(g_negative1.IsPositive) |
|
|
|
|
|
|
|
Assert.IsFalse( 0N.IsPositive) |
|
|
|
Assert.IsFalse(-0N.IsPositive) |
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
[<Test>] |
|
|
|
member this.Numerator() = |
|
|
|
member this.Numerator() = |
|
|
|
Assert.AreEqual(g_positive1.Numerator, g_bigintpositive) |
|
|
|
Assert.AreEqual(g_negative1.Numerator, g_bigintnegative) |
|
|
|
Assert.AreEqual(0N.Numerator, 0I) |
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|