add more tests

This commit is contained in:
Lesenechal Remi 2019-10-29 11:57:15 +01:00
parent c288f3c81e
commit fd901548af
2 changed files with 88 additions and 28 deletions

View File

@ -46,17 +46,66 @@ function for_collection_set (var nee : unit) : (int * string) is block {
end
} with (acc, st)
// function for_collection_assignements_in_ifs (var nee : unit) : int is block {
// var acc : int := 0 ;
// var myset : set(int) := set 1 ; 2 ; 3 end ;
// for x : int in set myset
// begin
// if (x=1) then
// acc := acc + x ;
// else
// acc := acc + 10 ;
// end
// } with acc
function for_collection_if_and_local_var (var nee : unit) : int is block {
var acc : int := 0 ;
const theone : int = 1 ;
var myset : set(int) := set 1 ; 2 ; 3 end ;
for x : int in set myset
begin
const thetwo : int = 2 ;
if (x=theone) then
acc := acc + x ;
else if (x=thetwo) then
acc := acc + thetwo ;
else
acc := acc + 10 ;
end
} with acc
function for_collection_rhs_capture (var nee : unit) : int is block {
var acc : int := 0 ;
const mybigint : int = 1000 ;
var myset : set(int) := set 1 ; 2 ; 3 end ;
for x : int in set myset
begin
if (x=1) then
acc := acc + mybigint ;
else
acc := acc + 10 ;
end
} with acc
function for_collection_proc_call (var nee : unit) : int is block {
var acc : int := 0 ;
var myset : set(int) := set 1 ; 2 ; 3 end ;
for x : int in set myset
begin
if (x=1) then
acc := acc + for_collection_rhs_capture(unit) ;
else
acc := acc + 10 ;
end
} with acc
function for_collection_comp_with_acc (var nee : unit) : int is block {
var myint : int := 0 ;
var mylist : list(int) := list 1 ; 10 ; 15 end;
for x : int in list mylist
begin
if (x < myint) then skip ;
else myint := myint + 10 ;
end
} with myint
function for_collection_with_patches (var nee : unit) : map(string,int) is block {
var myint : int := 12 ;
var mylist : list(string) := list "I" ; "am" ; "foo" end;
var mymap : map(string,int) := map end;
for x : string in list mylist
begin
patch mymap with map [ x -> myint ];
end
} with mymap
function for_collection_empty (var nee : unit) : int is block {
var acc : int := 0 ;

View File

@ -647,38 +647,49 @@ let loop () : unit result =
let%bind () =
let make_input = e_nat in
let make_expected = e_nat in
expect_eq_n_pos program "dummy" make_input make_expected
in
expect_eq_n_pos program "dummy" make_input make_expected in
let%bind () =
let make_input = e_nat in
let make_expected = e_nat in
expect_eq_n_pos_mid program "counter" make_input make_expected
in
expect_eq_n_pos_mid program "counter" make_input make_expected in
let%bind () =
let make_input = e_nat in
let make_expected = fun n -> e_nat (n * (n + 1) / 2) in
expect_eq_n_pos_mid program "while_sum" make_input make_expected
in
expect_eq_n_pos_mid program "while_sum" make_input make_expected in
let%bind () =
let make_input = e_nat in
let make_expected = fun n -> e_int (n * (n + 1) / 2) in
expect_eq_n_pos_mid program "for_sum" make_input make_expected
in
expect_eq_n_pos_mid program "for_sum" make_input make_expected in
let input = e_unit () in
let%bind () =
let input = e_unit () in
let expected = e_pair (e_int 3) (e_string "totototo") in
expect_eq program "for_collection_list" input expected
in
expect_eq program "for_collection_list" input expected in
let%bind () =
let input = e_unit () in
let expected = e_pair (e_int 6) (e_string "totototo") in
expect_eq program "for_collection_set" input expected
in
expect_eq program "for_collection_set" input expected in
let%bind () =
let input = e_unit () in
let expected = (e_int 0) in
expect_eq program "for_collection_empty" input expected
in
expect_eq program "for_collection_empty" input expected in
let%bind () =
let expected = (e_int 13) in
expect_eq program "for_collection_if_and_local_var" input expected in
let%bind () =
let expected = (e_int 1020) in
expect_eq program "for_collection_rhs_capture" input expected in
let%bind () =
let expected = (e_int 1040) in
expect_eq program "for_collection_proc_call" input expected in
let%bind () =
let expected = (e_int 20) in
expect_eq program "for_collection_comp_with_acc" input expected in
let%bind () =
let ez lst =
let open Ast_simplified.Combinators in
let lst' = List.map (fun (x, y) -> e_string x, e_int y) lst in
e_typed_map lst' t_string t_int
in
let expected = ez [ ("I" , 12) ; ("am" , 12) ; ("foo" , 12) ] in
expect_eq program "for_collection_with_patches" input expected in
ok ()
(* Don't know how to assert parse error happens in this test framework