게시판 인덱스

 
 FAQFAQ   검색검색   멤버리스트멤버리스트   사용자 그룹사용자 그룹   사용자 등록하기사용자 등록하기 
 개인 정보개인 정보   비공개 메시지를 확인하려면 로그인하십시오비공개 메시지를 확인하려면 로그인하십시오   로그인로그인 

HW2 테스트 케이스 모음

 
이 게시판은 잠겼으므로 글을 올리거나, 답변을 하거나 수정을 할 수 없습니다   이 주제는 잠겼으므로 답변을 하거나 수정을 할 수 없습니다     게시판 인덱스 -> 4190.310 Programming Languages (Fall 2017)
이전 주제 보기 :: 다음 주제 보기  
글쓴이 메시지
하비홍



가입: 2017년 9월 7일
올린 글: 8

올리기올려짐: 2017년9월15일 11:10    주제: HW2 테스트 케이스 모음 인용과 함께 답변

테스트셋은 기존 게시판에 존재하는 테스트셋 + 문제에서 주는 예시들 + @로 구성되어 있습니다.
(9/15 16:33 HW2-5 추가)
(9/18 전체적으로 수정)

2-1 참거짓

코드:
let _ =
  let test_case : int * bool -> unit = fun (n, x) ->
    print_endline ("Case " ^ string_of_int(n) ^ " : " ^ string_of_bool(x)) in
  test_case(1, true = eval TRUE);
  test_case(2, false = eval FALSE);
  test_case(3, false = eval (NOT TRUE));
  test_case(4, true = eval (NOT FALSE));
  test_case(5, true = eval (ANDALSO (TRUE, TRUE)));
  test_case(6, false = eval (ANDALSO (TRUE, FALSE)));
  test_case(7, false = eval (ANDALSO (FALSE, TRUE)));
  test_case(8, false = eval (ANDALSO (FALSE, FALSE)));
  test_case(9, true = eval (ORELSE (TRUE, TRUE)));
  test_case(10, true = eval (ORELSE (TRUE, FALSE)));
  test_case(11, true = eval (ORELSE (FALSE, TRUE)));
  test_case(12, false = eval (ORELSE (FALSE, FALSE)));
  test_case(13, false = eval (IMPLY (TRUE, FALSE)));
  test_case(14, true = eval (IMPLY (TRUE, TRUE)));
  test_case(15, true = eval (IMPLY (FALSE, TRUE)));
  test_case(16, true = eval (IMPLY (FALSE, FALSE)));
  test_case(17, true = eval (LESS (NUM 3, NUM 5)));
  test_case(18, false = eval (LESS (NUM 3, NUM 3)));
  test_case(19, false = eval (LESS (NUM 3, NUM 1)));
  test_case(20, false = eval (LESS (PLUS (NUM 3, NUM 4), MINUS (NUM 5, NUM 1))));
  test_case(21, true = eval (LESS (PLUS (NUM 10, NUM 12), MINUS (NUM 10, NUM (-13)))));


2-2 k친수

코드:
let mtwo = ZERO(ONE(MONE NIL))
let one = ONE(NIL)
let five = ONE(ZERO(ONE NIL))
let mone = ONE(MONE NIL)
let mnine = ONE(MONE(ZERO(MONE NIL)))
let zero = ZERO(ZERO(ZERO NIL))
let big1 = ZERO(ONE(ZERO(ONE(ZERO(MONE(MONE(ONE(MONE(ONE NIL)))))))))
let big2 = ONE(MONE(MONE(ZERO(ONE(ZERO(MONE(MONE(ONE(MONE NIL)))))))))

let _ =
  let test_case : int * int * int -> unit = fun (n, x, y) ->
    let result : int * int -> string = fun(x, y) ->
      if(x == y) then "Pass"
      else "Failure -> " ^ string_of_int(x) ^ " vs " ^ string_of_int(y) in
    print_endline ("Case " ^ string_of_int(n) ^ " : " ^ result(x, y)) in
  test_case(1, -2, crazy2val(mtwo));
  test_case(2, 1, crazy2val(one));
  test_case(3, 5, crazy2val(five));
  test_case(4, -1, crazy2val(mone));
  test_case(5, -9, crazy2val(mnine));
  test_case(6, 0, crazy2val(zero));
  test_case(7, 298, crazy2val(big1));
  test_case(8, -437, crazy2val(big2));


2-3 친수의 합 : 간편하게 테스트를 하기 위해서 2-2에서 구현한 crazy2val을 이용합니다. 본인이 구현한 crazy2val 코드에 넣어주세요.

코드:
let mtwo = ZERO(ONE(MONE NIL))
let one = ONE(NIL)
let five = ONE(ZERO(ONE NIL))
let mone = ONE(MONE NIL)
let mnine = ONE(MONE(ZERO(MONE NIL)))
let zero = ZERO(ZERO(ZERO(ZERO(ZERO(ZERO(ZERO(ZERO NIL)))))))
let five2 = ONE(ZERO(ONE(ZERO(ZERO(ZERO(ZERO(ZERO NIL)))))))
let big1 = ZERO(ONE(ZERO(ONE(ZERO(MONE(MONE(ONE(MONE(ONE NIL)))))))))
let big2 = ONE(MONE(MONE(ZERO(ONE(ZERO(MONE(MONE(ONE(MONE NIL)))))))))

let _ =
  let test_case : int * int * int -> unit = fun (n, x, y) ->
    let result : int * int -> string = fun(x, y) ->
      if(x == y) then "Pass"
      else "Failure -> " ^ string_of_int(x) ^ " vs " ^ string_of_int(y) in
    print_endline ("Case " ^ string_of_int(n) ^ " : " ^ result(x, y)) in
  let test_nocrazy2val : bool -> unit = fun x ->
    let detector = fun x -> if(x = true) then "Pass" else "crazy2val detected" in
    print_endline ("crazy2val detector : " ^ detector(x)) in
  test_nocrazy2val (crazy2add(zero, five) = five2);
  test_case (1, crazy2val(crazy2add(mnine, mtwo)), crazy2val(crazy2add(mtwo, mnine)));
  test_case (2, crazy2val(mtwo) + crazy2val(mnine), crazy2val(crazy2add(mtwo, mnine)));
  test_case (3, crazy2val(five) + crazy2val(mnine), crazy2val(crazy2add(five, mnine)));
  test_case (4, crazy2val(crazy2add(mnine, one)) + crazy2val(five), crazy2val(mnine) + crazy2val(crazy2add(one, five)));
  test_case (5, crazy2val(crazy2add(crazy2add(mnine, mtwo), crazy2add(five, mtwo))), crazy2val(mnine) + crazy2val(mtwo) + crazy2val(five) + crazy2val(mtwo));
  test_case (6, crazy2val(crazy2add(zero, mnine)), crazy2val(mnine));
  test_case (7, crazy2val(crazy2add(big1, big2)), crazy2val(crazy2add(big2, big1)));
  test_case (8, crazy2val(crazy2add(big1, crazy2add(big1, big2))), crazy2val(crazy2add(crazy2add(big1, big1), big2)));


2-4 CheckMetroMap

코드:
let _ =
  let test_case : int * bool -> unit = fun (n, x) ->
    print_endline ("Case " ^ string_of_int(n) ^ " : " ^ string_of_bool(x)) in
  test_case(1, true == checkMetro(AREA("a", STATION "a")));
  test_case(2, true == checkMetro(AREA("a", AREA("a", STATION "a"))));
  test_case(3, true == checkMetro(AREA("a", AREA("b", CONNECT(STATION "a", STATION "b")))));
  test_case(4, true == checkMetro(AREA("a", CONNECT(STATION "a", AREA("b", STATION "a")))));
  test_case(5, false == checkMetro(AREA("a", STATION "b")));
  test_case(6, false == checkMetro(AREA("a", CONNECT(STATION "a", AREA("b", STATION "c")))));
  test_case(7, false == checkMetro(AREA("a", AREA("b", CONNECT(STATION "a", STATION "c")))));
  test_case(8, true == checkMetro(CONNECT(AREA("a", STATION "a"), AREA("b", AREA("a", CONNECT(STATION "b", STATION "a"))))));
  test_case(9, false == checkMetro(CONNECT(AREA("c", STATION "c"), AREA("b", AREA("a", CONNECT(STATION "b", STATION "c"))))));
  test_case(10, false == checkMetro(STATION "a"))


2-5 짚-짚-나무

코드:
let x = LOC (NODE [LEAF "c"; LEAF "*"; LEAF "d"], HAND ([LEAF "+" ; NODE [LEAF "a"; LEAF "*"; LEAF "b"]], TOP, []))
let y = LOC (NODE [NODE [LEAF "a"; LEAF "*"; LEAF "b"]; LEAF "+" ; NODE [LEAF "c"; LEAF "*"; LEAF "d"]], TOP)
let z = LOC (LEAF "*", HAND([LEAF "c"], HAND([LEAF "+"; NODE [LEAF "a"; LEAF "*"; LEAF "b"]], TOP, []), [LEAF "d"]))
let empty = LOC(NODE[], TOP)

let (|>) f g = g f

let _ =
  let test_case : int * bool -> unit = fun (n, x) ->
    print_endline ("Case " ^ string_of_int(n) ^ " : " ^ string_of_bool(x)) in
  let test_errorcase : int * bool -> unit = fun (n, x) ->
    let error_check = fun e -> if(e = true) then "OK" else "Failure" in
    print_endline ("Error Case " ^ string_of_int(n) ^ " : " ^ error_check(x)) in
  test_case(1, y |> goDown = LOC (NODE [LEAF "a"; LEAF "*"; LEAF "b"], HAND ([], TOP, [LEAF "+"; NODE [LEAF "c"; LEAF "*"; LEAF "d"]])));
  test_case(2, y |> goDown |> goDown = LOC (LEAF "a", HAND ([], HAND ([], TOP, [LEAF "+"; NODE [LEAF "c"; LEAF "*"; LEAF "d"]]), [LEAF "*"; LEAF "b"])));
  test_case(3, y |> goDown |> goUp |> goDown = LOC (NODE [LEAF "a"; LEAF "*"; LEAF "b"], HAND ([], TOP, [LEAF "+"; NODE [LEAF "c"; LEAF "*"; LEAF "d"]])));
  test_case(4, y |> goDown |> goDown |> goRight = LOC (LEAF "*", HAND ([LEAF "a"], HAND ([], TOP, [LEAF "+"; NODE [LEAF "c"; LEAF "*"; LEAF "d"]]), [LEAF "b"])));
  test_case(5, y |> goDown |> goDown |> goRight |> goLeft |> goRight |> goRight = LOC (LEAF "b", HAND ([LEAF "*"; LEAF "a"], HAND ([], TOP, [LEAF "+"; NODE [LEAF "c"; LEAF "*"; LEAF "d"]]), [])));
  test_case(6, y |> goDown |> goRight |> goRight |> goDown |> goRight = LOC (LEAF "*", HAND ([LEAF "c"], HAND ([LEAF "+"; NODE [LEAF "a"; LEAF "*"; LEAF "b"]], TOP, []), [LEAF "d"])));
  test_case(7, x |> goDown |> goRight |> goRight |> goUp |> goUp = y);
  test_case(8, y |> goDown |> goRight |> goRight |> goDown |> goRight = z);
  test_errorcase(1, try (goUp(y) = z) with NOMOVE _ -> true);
  test_errorcase(2, try (goDown(empty) = z) with NOMOVE _ -> true)



2-6 Queue = 2 Stacks

코드:
let q1 = IntListQ.emptyQ
let q2 = IntListQ.enQ(q1, [1])
let q3 = IntListQ.enQ(q2, [2;3])
let q4 = IntListQ.enQ(q3, [4;5;6])
let (l1, q5) = IntListQ.deQ q4
let q6 = IntListQ.enQ(q5, [7;8;9;10])
let (l2, q7) = IntListQ.deQ q6
let q8 = IntListQ.enQ(q7, [11;13;20;100])
let (l3, q9) = IntListQ.deQ q8
let (l4, q10) = IntListQ.deQ q9
let (l5, q11) = IntListQ.deQ q10
let q12 = IntListQ.enQ(q11, [4;5;6;7])
let (l6, q13) = IntListQ.deQ q12

let _ =
  let test_case : int * bool -> unit = fun (n, x) ->
    print_endline ("Case " ^ string_of_int(n) ^ " : " ^ string_of_bool(x)) in
  test_case (1, ([1] = l1));
  test_case (2, ([2;3] = l2));
  test_case (3, ([4;5;6] = l3));
  test_case (4, ([7;8;9;10] = l4));
  test_case (5, ([11;13;20;100] = l5));
  test_case (6, ([4;5;6;7] = l6));
  test_case (7, q13 = IntListQ.emptyQ)

let (x, y) = try IntListQ.deQ q13 with IntListQ.EMPTY_Q -> ([19682934], IntListQ.emptyQ)
let _ = if(x = [19682934]) then print_endline ("Error Case : Pass")
  else print_endline("Error Case : Failure")


2-7 계산실행

코드:
let print = fun x -> Zexpr.print_value(Zexpr.eval(Zexpr.emptyEnv, x))
let var = fun x -> Zexpr.VAR x
let num = fun x -> Zexpr.NUM x
let set = fun (x, y, z) -> Zexpr.LET(x, y, z)
let plus = fun (x, y) -> Zexpr.PLUS(x, y)
let minus = fun (x, y) -> Zexpr.MINUS(x, y)
let div = fun (x, y) -> Zexpr.DIVIDE(x, y)
let mul = fun (x, y) -> Zexpr.MULT(x, y)
let max = fun x -> Zexpr.MAX x

let _ = print(num 1), print_string "Case 1 : 1 vs "
let _ = print(set("x", num 1, plus(set("x", num 2, plus(var "x", var "x")), var "x"))), print_string "Case 2 : 5 vs "
let _ = print(max []), print_string "Case 3 : 0 vs "
let _ = print(max [num(-1); num(-2); num(-3)]), print_string "Case 4 : -1 vs "
let _ = print(div(num 3, num 2)), print_string "Case 5 : 1 vs "
let _ = print(plus(num 7, num 9)), print_string "Case 6 : 16 vs "
let _ = print(minus(num 7, num 9)), print_string "Case 7 : -2 vs "
let _ = print(mul(num 7, num 9)), print_string "Case 8 : 63 vs "
let _ = print(set("x", num 1, plus(set("y", num 2, plus(var "x", var "y")), var "x"))), print_string "Case 9 : 4 vs "
let _ = print(set("x", num 1, set("y", num 2, set("z", num(-1), max[var "x"; var "y"; var "z"])))), print_string "Case 10 : 2 vs "
let _ = try print(set("x", num 1, set("y", num 2, set("z", num(-1), max[var "x"; var "y"; var "z"; var "a"])))) with Zexpr.Error x ->
          if (x = "FreeVariable") then print_endline("Error Case 1 : Pass")
          else print_endline("Error Case 1 : Failure")
let _ = try print(set("x", num 1, plus(set("y", num 2, plus(var "x", var "y")), var "y"))) with Zexpr.Error x ->
          if (x = "FreeVariable") then print_endline("Error Case 2 : Pass")
          else print_endline("Error Case 2 : Failure")


하비홍 가 2017년9월18일 18:23에 수정함, 총 2 번 수정됨
위로
사용자 정보 보기 비밀 메시지 보내기
박찬양



가입: 2017년 9월 11일
올린 글: 6

올리기올려짐: 2017년9월16일 13:58    주제: 인용과 함께 답변

감사합니다!
위로
사용자 정보 보기 비밀 메시지 보내기
신현선



가입: 2017년 9월 10일
올린 글: 4

올리기올려짐: 2017년9월24일 9:46    주제: 테스트 케이스 감사합니다! 인용과 함께 답변

덕분에 도움이 많이 되었습니다.
감사합니다!
위로
사용자 정보 보기 비밀 메시지 보내기
이전 글 표시:   
이 게시판은 잠겼으므로 글을 올리거나, 답변을 하거나 수정을 할 수 없습니다   이 주제는 잠겼으므로 답변을 하거나 수정을 할 수 없습니다     게시판 인덱스 -> 4190.310 Programming Languages (Fall 2017) 시간대: GMT + 9 시간(한국)
페이지 11

 
건너뛰기:  
새로운 주제를 올릴 수 없습니다
답글을 올릴 수 없습니다
주제를 수정할 수 없습니다
올린 글을 삭제할 수 없습니다
투표를 할 수 없습니다


Powered by phpBB 2.0.21-7 (Debian) © 2001, 2005 phpBB Group
Translated by kss & drssay