Skip to content

Commit

Permalink
GH-142: Migrate test cases for Int module
Browse files Browse the repository at this point in the history
  • Loading branch information
zeptometer committed Mar 1, 2021
1 parent f2f9a2b commit 29996cc
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
137 changes: 137 additions & 0 deletions test/int.test.satyg
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
]
2 changes: 2 additions & 0 deletions test/main.test.saty
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@import: ../src/string

@import: array.test
@import: int.test
@import: list.test
@import: ref.test
@import: regex.test
Expand All @@ -19,5 +20,6 @@ describe `base` [
list-test-cases;
array-test-cases;
regex-test-cases;
int-test-cases;
]
|> run

0 comments on commit 29996cc

Please sign in to comment.