-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-142: Migrate test cases for Int module
- Loading branch information
1 parent
f2f9a2b
commit 29996cc
Showing
2 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
@require: test/test | ||
@require: test/expect | ||
|
||
@import: ../src/int | ||
@import: ../src/list-ext | ||
@import: ../src/option-ext | ||
|
||
let int-test-cases = open Test in | ||
describe `Int module` [ | ||
it `calculate logical shift left` (fun () -> ( | ||
13 | ||
|> Int.lsl 2 | ||
|> (==) 52 | ||
|> Expect.is-true | ||
)); | ||
it `calculate arithmetic shift right of positive` (fun () -> ( | ||
[0; 1; 2; 3; 4; 5] | ||
|> List.map (fun x -> 13 |> Int.asr x) | ||
|> Eq.equal (List.eq Int.eq) [13; 6; 3; 1; 0; 0] | ||
|> Expect.is-true | ||
)); | ||
it `calculate arithmetic shift right of negative` (fun () -> ( | ||
[0; 1; 2; 3; 4; 5] | ||
|> List.map (fun x -> -13 |> Int.asr x) | ||
|> Eq.equal (List.eq Int.eq) [-13; -7; -4; -2; -1; -1] | ||
|> Expect.is-true | ||
)); | ||
it `calculate logical and` (fun () -> ( | ||
(10 |> Int.land 13) == 8 | ||
&& (31 |> Int.land (-13)) == 19 | ||
|> Expect.is-true | ||
)); | ||
it `calculate logical or` (fun () -> ( | ||
10 | ||
|> Int.lor 13 | ||
|> (==) 15 | ||
|> Expect.is-true | ||
)); | ||
it `calculate logical exclusive or` (fun () -> ( | ||
10 | ||
|> Int.lxor 13 | ||
|> (==) 7 | ||
|> Expect.is-true | ||
)); | ||
it `calculate logical shift right` (fun () -> ( | ||
(13 | ||
|> Int.lsr 2 | ||
|> (==) 3) | ||
&& (-13 | ||
|> Int.lsr 2 | ||
|> (==) 2305843009213693948) | ||
|> Expect.is-true | ||
)); | ||
it `parse decimal number` (fun () -> ( | ||
`12345678` | ||
|> Int.of-string ?:10 | ||
|> (==) 12345678 | ||
|> Expect.is-true | ||
)); | ||
it `parse negative decimal number` (fun () -> ( | ||
`-123` | ||
|> Int.of-string ?:10 | ||
|> (==) (-123) | ||
|> Expect.is-true | ||
)); | ||
it `parse hexadecimal number` (fun () -> ( | ||
`ffff` | ||
|> Int.of-string ?:16 | ||
|> (==) 65535 | ||
|> Expect.is-true | ||
)); | ||
it `calculate power` (fun () -> ( | ||
(2 |> Int.pow 3 |> (==) 8) | ||
&& (2 |> Int.pow 0 |> (==) 1) | ||
|> Expect.is-true | ||
)); | ||
it `calculate supreme from a list of numbers` (fun () -> ( | ||
Int.sup [1; 3; 2] | ||
|> (==) 3 | ||
|> Expect.is-true | ||
)); | ||
it `calculate supreme from an empty list` (fun () -> ( | ||
%% SATySFi compiler fails to parse -4611686018427387904 | ||
let expected = Int.of-string ?:10 `-4611686018427387904` in | ||
Int.sup [] | ||
|> (==) expected | ||
|> Expect.is-true | ||
)); | ||
it `parse maybe decimal` (fun () -> ( | ||
`123` | ||
|> Int.of-string-opt ?:10 | ||
|> Eq.equal (Option.eq Int.eq) (Option.some 123) | ||
|> Expect.is-true | ||
)); | ||
it `parse maybe negative decimal` (fun () -> ( | ||
`-123` | ||
|> Int.of-string-opt ?:10 | ||
|> Eq.equal (Option.eq Int.eq) (Option.some (-123)) | ||
|> Expect.is-true | ||
)); | ||
it `fail to parse non decimal` (fun () -> ( | ||
`12n` | ||
|> Int.of-string-opt ?:10 | ||
|> Eq.equal (Option.eq Int.eq) Option.none | ||
|> Expect.is-true | ||
)); | ||
it `parse maybe hexadecimal` (fun () -> ( | ||
`a` | ||
|> Int.of-string-opt ?:16 | ||
|> Eq.equal (Option.eq Int.eq) (Option.some 10) | ||
|> Expect.is-true | ||
)); | ||
% TODO | ||
% ord | ||
% eq | ||
% equal | ||
% bitsize | ||
% max-value | ||
% min-value | ||
% (<) | ||
% (>) | ||
% (>=) | ||
% (<=) | ||
% (==) | ||
% succ | ||
% pred | ||
% neg | ||
% add | ||
% sub | ||
% mul | ||
% div | ||
% abs | ||
% max | ||
% min | ||
% inf | ||
% to-string | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters