Skip to content

Commit

Permalink
GH-142: Migrate added tests of Array
Browse files Browse the repository at this point in the history
  • Loading branch information
zeptometer committed Mar 2, 2024
1 parent ab9d894 commit 46d02a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
19 changes: 0 additions & 19 deletions __test__/satysrc/generic.saty
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,6 @@
@import: ../../src/big-int

open Fn in

let () = Debug.log `==== Array ====` in
let a = Array.make 3 42 in
let () = a |> Array.get 0 |> String.of-int |> Debug.log in
let () = a |> Array.set 0 43 in
let () = a |> Array.get 0 |> String.of-int |> Debug.log in
let a = 10 |> Array.init id in
let is = [0;1;2;3;4;5;6;7;8;9] in
let () = is |> List.iter (fun i -> a |> Array.get i |> String.of-int |> Debug.log) in
let () = is |> List.iter (fun i -> a |> Array.set i (10 - i)) in
let () = is |> List.iter (fun i -> a |> Array.get i |> String.of-int |> Debug.log) in
let () = a |> Array.to-list |> List.iter (fun i -> i |> String.of-int |> Debug.log) in
let () = [0;1;2;3;4;] |> Array.of-list |> Array.sub 2 3 |> Array.to-list |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in % `234`
let a1 = Array.of-list [0;1;2;3;4;] in
let a2 = Array.of-list [5;6;7;8;9] in
let a = Array.append a1 a2 in
let () = Debug.log (String.of-int (Array.get 0 a)) in
let () = Array.append a1 a2 |> Array.to-list |> List.iter (fun i -> i |> String.of-int |> Debug.log) in

let () = Debug.log `==== RegExp ====` in
open RegExp in
%let () = RegExp.test (RegExp.of-string `ab.*ef`) `abcdef` |> String.of-bool |> Debug.log in
Expand Down
39 changes: 21 additions & 18 deletions test/array.test.satyg
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,29 @@

let array-test-cases = open Test in
% Note: We want (Array.eq : Array.t Eq.t)
let int-array-eq a b =
let intaeq a b =
Eq.equal (List.eq Int.eq) (Array.to-list a) (Array.to-list b) in
let eq-to-intl l a = Eq.equal (List.eq Int.eq) l (Array.to-list a) in
describe `Array module` [
it `checks equality of arrays (test util function)` (fun () -> (
intaeq (Array.make 3 2) (Array.make 3 2)
&& not intaeq (Array.make 3 2) (Array.make 4 2)
&& not intaeq (Array.make 3 2) (Array.make 3 1)
|> Expect.is-true
));
it `make array and get contents and length` (fun () -> (
let a = Array.make 3 2 in
(Array.get 0 a == 3)
&& (Array.get 1 a == 3)
&& (Array.length a == 2)
|> Expect.is-true
));
it `initialize array with index` (fun () -> (
let actual = Array.init (fun x -> x + 1) 10 in
actual
|> Array.to-list
|> Eq.equal (List.eq Int.eq) [1;2;3;4;5;6;7;8;9;10]
|> Expect.is-true
));
it `overwrite value by index` (fun () -> (
let actual = Array.init Fn.id 10 in
let is = [0;1;2;3;4;5;6;7;8;9] in
let () = is |> List.iter (fun i -> (Array.set i (10 - i) actual)) in
actual
|> Array.to-list
|> Eq.equal (List.eq Int.eq) [10;9;8;7;6;5;4;3;2;1]
let a = Array.make 3 2 in
let () = a |> Array.set 0 43 in
(Array.get 0 a == 43)
&& (Array.get 1 a == 3)
&& (Array.length a == 2)
|> Expect.is-true
));
it `convert to list` (fun () -> (
Expand All @@ -46,19 +45,23 @@ let array-test-cases = open Test in
let actual = Array.of-list [0;1;2;3;4] in
let expected = Array.init Fn.id 5 in
actual
|> int-array-eq expected
|> intaeq expected
|> Expect.is-true
));
it `make subarray` (fun () -> (
Array.of-list [0;1;2;3;4]
|> Array.sub 2 3
|> eq-to-intl [2;3;4]
|> Expect.is-true
));
it `append arrays` (fun () -> (
let a = Array.of-list [0;1;2;3;4] in
let b = Array.of-list [5;6;7;8;9] in
let expected = Array.of-list [0;1;2;3;4;5;6;7;8;9] in
Array.append a b
|> int-array-eq expected
|> eq-to-intl [0;1;2;3;4;5;6;7;8;9]
|> Expect.is-true
));
% TODO
% * concat
% * sub
% * map
]

0 comments on commit 46d02a8

Please sign in to comment.