|
| 1 | +open Jest; |
| 2 | + |
| 3 | +describe("BigInt", () => { |
| 4 | + Random.init(84611); |
| 5 | + |
| 6 | + let fourHundred = 400; |
| 7 | + let randomInt = _ => Random.int(fourHundred); |
| 8 | + |
| 9 | + test("BigInt.(+)", () => { |
| 10 | + let a = randomInt(); |
| 11 | + let b = randomInt(); |
| 12 | + let c = a + b; |
| 13 | + |
| 14 | + Expect.( |
| 15 | + [@ocaml.warning "-44"] expect(BigInt.(fromInt(a) + fromInt(b))) |
| 16 | + |> toEqual(BigInt.fromInt(c)) |
| 17 | + ); |
| 18 | + }); |
| 19 | + |
| 20 | + test("BigInt.(-)", () => { |
| 21 | + let a = randomInt(); |
| 22 | + let b = randomInt(); |
| 23 | + let c = a - b; |
| 24 | + |
| 25 | + Expect.( |
| 26 | + [@ocaml.warning "-44"] expect(BigInt.(fromInt(a) - fromInt(b))) |
| 27 | + |> toEqual(BigInt.fromInt(c)) |
| 28 | + ); |
| 29 | + }); |
| 30 | + |
| 31 | + test("BigInt.(*)", () => { |
| 32 | + let a = randomInt(); |
| 33 | + let b = randomInt(); |
| 34 | + let c = a * b; |
| 35 | + |
| 36 | + Expect.( |
| 37 | + [@ocaml.warning "-44"] expect(BigInt.(fromInt(a) * fromInt(b))) |
| 38 | + |> toEqual(BigInt.fromInt(c)) |
| 39 | + ); |
| 40 | + }); |
| 41 | + |
| 42 | + test("BigInt.(/)", () => { |
| 43 | + let a = randomInt(); |
| 44 | + let b = randomInt(); |
| 45 | + let c = a / b; |
| 46 | + |
| 47 | + Expect.( |
| 48 | + [@ocaml.warning "-44"] expect(BigInt.(fromInt(a) / fromInt(b))) |
| 49 | + |> toEqual(BigInt.fromInt(c)) |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + test("BigInt.(~-)", () => { |
| 54 | + let a = randomInt(); |
| 55 | + let b = - a; |
| 56 | + |
| 57 | + Expect.( |
| 58 | + [@ocaml.warning "-44"] expect(BigInt.(- fromInt(a))) |
| 59 | + |> toEqual(BigInt.fromInt(b)) |
| 60 | + ); |
| 61 | + }); |
| 62 | + |
| 63 | + test("BigInt.(%)", () => { |
| 64 | + let a = randomInt(); |
| 65 | + let b = randomInt(); |
| 66 | + let c = a mod b; |
| 67 | + |
| 68 | + Expect.( |
| 69 | + [@ocaml.warning "-44"] expect(BigInt.(fromInt(a) % fromInt(b))) |
| 70 | + |> toEqual(BigInt.fromInt(c)) |
| 71 | + ); |
| 72 | + }); |
| 73 | + |
| 74 | + test("BigInt.(**)", () => { |
| 75 | + let a = randomInt(); |
| 76 | + let b = Random.int(24); |
| 77 | + |
| 78 | + [@ocaml.warning "-3"] |
| 79 | + let c = Js.Math.pow_int(~base=a, ~exp=b); |
| 80 | + |
| 81 | + Expect.( |
| 82 | + [@ocaml.warning "-44"] expect(BigInt.(fromInt(a) ** fromInt(b))) |
| 83 | + |> toEqual(BigInt.fromInt(c)) |
| 84 | + ); |
| 85 | + }); |
| 86 | + |
| 87 | + test("BigInt.(land)", () => { |
| 88 | + let a = randomInt(); |
| 89 | + let b = randomInt(); |
| 90 | + let c = a land b; |
| 91 | + |
| 92 | + Expect.( |
| 93 | + [@ocaml.warning "-44"] expect(BigInt.(fromInt(a) land fromInt(b))) |
| 94 | + |> toEqual(BigInt.fromInt(c)) |
| 95 | + ); |
| 96 | + }); |
| 97 | + |
| 98 | + test("BigInt.(lor)", () => { |
| 99 | + let a = randomInt(); |
| 100 | + let b = randomInt(); |
| 101 | + let c = a lor b; |
| 102 | + |
| 103 | + Expect.( |
| 104 | + [@ocaml.warning "-44"] expect(BigInt.(fromInt(a) lor fromInt(b))) |
| 105 | + |> toEqual(BigInt.fromInt(c)) |
| 106 | + ); |
| 107 | + }); |
| 108 | + |
| 109 | + test("BigInt.(lxor)", () => { |
| 110 | + let a = randomInt(); |
| 111 | + let b = randomInt(); |
| 112 | + let c = a lxor b; |
| 113 | + |
| 114 | + Expect.( |
| 115 | + [@ocaml.warning "-44"] expect(BigInt.(fromInt(a) lxor fromInt(b))) |
| 116 | + |> toEqual(BigInt.fromInt(c)) |
| 117 | + ); |
| 118 | + }); |
| 119 | + |
| 120 | + test("BigInt.(lnot)", () => { |
| 121 | + let a = randomInt(); |
| 122 | + let b = lnot(a); |
| 123 | + |
| 124 | + Expect.( |
| 125 | + [@ocaml.warning "-44"] expect(BigInt.(lnot(fromInt(a)))) |
| 126 | + |> toEqual(BigInt.fromInt(b)) |
| 127 | + ); |
| 128 | + }); |
| 129 | + |
| 130 | + test("BigInt.(lsl)", () => { |
| 131 | + let a = 26; |
| 132 | + let b = 7; |
| 133 | + let c = a lsl b; |
| 134 | + |
| 135 | + Expect.( |
| 136 | + [@ocaml.warning "-44"] expect(BigInt.(fromInt(a) lsl fromInt(b))) |
| 137 | + |> toEqual(BigInt.fromInt(c)) |
| 138 | + ); |
| 139 | + }); |
| 140 | + |
| 141 | + test("BigInt.(asr)", () => { |
| 142 | + let a = 32; |
| 143 | + let b = 5; |
| 144 | + let c = a asr b; |
| 145 | + |
| 146 | + Expect.( |
| 147 | + [@ocaml.warning "-44"] expect(BigInt.(fromInt(a) asr fromInt(b))) |
| 148 | + |> toEqual(BigInt.fromInt(c)) |
| 149 | + ); |
| 150 | + }); |
| 151 | +}); |
0 commit comments