Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
artoy committed Oct 10, 2023
1 parent d690b0b commit 89d7a7e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/test/list/append.imp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ append(l, r){
let n = ( _ : ~ >= 0) in
let l1 = mklist(m) in
let l2 = mklist(n) in
let l = append(l1, l2) in
let sum_length = len(l1) + len(l2) in {
alias(l = l1);
assert(len(l) = sum_length)
let sum_length = len(l1) + len(l2) in
let l = append(l1, l2) in {
alias(l = l1);
assert(len(l) = sum_length)
}
}
36 changes: 36 additions & 0 deletions src/test/list/mochi/append.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
let rec mklist n =
if n > 0 then
let h = Random.int 0 in
let t = mklist (n - 1) in
h :: t
else []

and len (l: int list) =
match l with
[] -> 0
| _ :: t -> 1 + len t

and append (l1: int list) (l2: int list) =
match l1 with
[] -> l2
| h :: t -> h :: (append t l2)

let main () =
let m =
let rec nd' () =
let _' = Random.int 0 in
if _' >= 0 then _' else nd' ()
in nd' ()
in
let n =
let rec nd' () =
let _' = Random.int 0 in
if _' >= 0 then _' else nd' ()
in nd' ()
in
let l1 = mklist m in
let l2 = mklist n in
let sum_length = len l1 + len l2 in
let l = append l1 l2 in
assert (len(l) = sum_length);
(())
34 changes: 34 additions & 0 deletions src/test/list/mochi/reverse2.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
let rec mklist n =
if n > 0 then
let h = Random.int 0 in
let t = mklist (n - 1) in
h :: t
else []

and _reverse (l: int list) (acc: int list) =
match l with
[] -> acc
| h :: t -> _reverse t (h :: acc)

and reverse (l: int list) =
_reverse l []

and len (l: int list) =
match l with
[] -> 0
| _ :: t -> 1 + len t

let main () =
let n =
let rec nd' () =
let _' = Random.int 0 in
if _' >= 0 then _' else nd' ()
in nd' ()
in
let l = mklist n in
let __t0 = len l in
let rev_l = reverse l in
let __t1 = len rev_l in
assert (__t0 = __t1);
let __t2 = 0 in
(())
7 changes: 3 additions & 4 deletions src/test/list/reverse2.imp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ len(l) {
{
let n = ( _ : ~ >= 0) in
let l = mklist(n) in
let rev_l = reverse(l) in {
alias(l = rev_l);
assert(len(l) = len(rev_l))
}
let len_l = len(l) in
let rev_l = reverse(l) in
assert(len_l = len(rev_l))
}

0 comments on commit 89d7a7e

Please sign in to comment.