-
Notifications
You must be signed in to change notification settings - Fork 156
/
test_contextfree.ml
35 lines (27 loc) · 1.68 KB
/
test_contextfree.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
open Contextfree
open Types
open Grammar
open Exercises
let to_string = string_of_sentform
let%test "example_test" = derive todo [ 0; 1; 0; 1; 2 ] |> to_string = "01011010"
(** Following the example test, complete the tests below.
For each test, provide the right sequence of productions
to generate the word on the right of the "=".
*)
(* #### Exercise 1 *)
let%test "zero_n_one_n_1" = derive zero_n_one_n [ (* FILL IN HERE *) ] |> to_string = ""
let%test "zero_n_one_n_2" = derive zero_n_one_n [ (* FILL IN HERE *) ] |> to_string = "01"
let%test "zero_n_one_n_3" = derive zero_n_one_n [ (* FILL IN HERE *) ] |> to_string = "00000000001111111111"
(* #### Exercise 2 *)
let%test "palindromes_1" = derive palindromes [ (* FILL IN HERE *) ] |> to_string = "11011"
let%test "palindromes_2" = derive palindromes [ (* FILL IN HERE *) ] |> to_string = "0110"
let%test "palindromes_3" = derive palindromes [ (* FILL IN HERE *) ] |> to_string = "011101110"
(* #### Exercise 3 *)
let%test "balanced_parentheses_1" = derive balanced_parentheses [ (* FILL IN HERE *) ] |> to_string = "()[]{}"
let%test "balanced_parentheses_2" = derive balanced_parentheses [ (* FILL IN HERE *) ] |> to_string = "({})[]"
let%test "balanced_parentheses_3" = derive balanced_parentheses [ (* FILL IN HERE *) ] |> to_string = "({[][{}()]})"
(* #### Exercise 4 *)
let%test "zero_one_same_1" = derive same_amount [ (* FILL IN HERE *) ] |> to_string = ""
let%test "zero_one_same_2" = derive same_amount [ (* FILL IN HERE *) ] |> to_string = "1001"
let%test "zero_one_same_3" = derive same_amount [ (* FILL IN HERE *) ] |> to_string = "00110101"
let%test "zero_one_same_4" = derive same_amount [ (* FILL IN HERE *) ] |> to_string = "10001110"