김민석
가입: 2012년 9월 15일 올린 글: 40
|
올려짐: 2014년9월14일 13:26 주제: hw1 테스트케이스입니다 |
|
|
hw1
let _ =
let print_bool x =
print_endline (string_of_bool x) in
print_bool (385 = sigma (1, 10, (fun x -> x * x)));
print_bool (0 = sigma (3, 1, fun x -> x * x));
print_bool (27 = sigma(3, 3, fun x -> x * x * x));
print_bool (385 = sigma(-10, -1, fun x -> x * x))
hw2
let _ =
let print_bool x =
print_endline (string_of_bool x) in
print_bool (true = eval TRUE);
print_bool (false = eval FALSE);
print_bool (false = eval (NOT TRUE));
print_bool (true = eval (NOT FALSE));
print_bool (true = eval (ANDALSO (TRUE, TRUE)));
print_bool (false = eval (ANDALSO (TRUE, FALSE)));
print_bool (false = eval (ANDALSO (FALSE, TRUE)));
print_bool (false = eval (ANDALSO (FALSE, FALSE)));
print_bool (true = eval (ORELSE (TRUE, TRUE)));
print_bool (true = eval (ORELSE (TRUE, FALSE)));
print_bool (true = eval (ORELSE (FALSE, TRUE)));
print_bool (false = eval (ORELSE (FALSE, FALSE)));
print_bool (false = eval (IMPLY (TRUE, FALSE)));
print_bool (true = eval (IMPLY (TRUE, TRUE)));
print_bool (true = eval (IMPLY (FALSE, TRUE)));
print_bool (true = eval (IMPLY (FALSE, FALSE)));
print_bool (true = eval (LESS (NUM 3, NUM 5)));
print_bool (false = eval (LESS (NUM 3, NUM 3)));
print_bool (false = eval (LESS (NUM 3, NUM 1)));
print_bool (false = eval
(LESS (PLUS (NUM 3, NUM 4), MINUS (NUM 5, NUM 1))));
print_bool (true = eval
(LESS (PLUS (NUM 10, NUM 12), MINUS (NUM 10, NUM (-13)))));
hw3
let _ =
let rec nat_to_int : nat -> int =
fun n ->
match n with
| ZERO -> 0
| SUCC n1 -> 1 + nat_to_int n1
in
let print_bool x =
print_endline (string_of_bool x)
in
let three = SUCC (SUCC (SUCC ZERO))
in
let four = SUCC three
in
print_bool (7 = nat_to_int (natadd (three, four)));
print_bool (0 = nat_to_int (natadd (ZERO, ZERO)));
print_bool (3 = nat_to_int (natadd (ZERO, three)));
print_bool (4 = nat_to_int (natadd (four, ZERO)));
print_bool (12 = nat_to_int (natmul (three, four)));
print_bool (0 = nat_to_int (natmul (ZERO, three)));
print_bool (0 = nat_to_int (natmul (four, ZERO)));
print_bool (0 = nat_to_int (natmul (ZERO, ZERO)));
print_bool (3 = nat_to_int (natmul (SUCC ZERO, three)));
print_bool (4 = nat_to_int (natmul (four, SUCC ZERO)));
숙제파일 밑에 붙여넣고 실행했을 때 모두 true가 나오면 됩니다.
테스트케이스는 처음 만들어봐서 많이 부족하네요. 간단한 경우들만 돌려봤어요 |
|