The questions should be completed with OCaml. Running screenshots should be provided. The background information is given by the picture. Question 1: Provide 5 good test cases each for eval_success_tests and eval_failure_tests, following the format of: let eval_success_tests : ((truth_assignment * formula) * bool) list = [] let eval_failure_tests : ((truth_assignment * formula) * exn) list = []
The questions should be completed with OCaml. Running screenshots should be provided.
The background information is given by the picture.
Question 1: Provide 5 good test cases each for eval_success_tests and eval_failure_tests, following the format of:
let eval_success_tests : ((truth_assignment * formula) * bool) list = []
let eval_failure_tests : ((truth_assignment * formula) * exn) list = []
Question 2: Implement the function eval : truth_assignment -> formula -> bool.
let eval (state : truth_assignment) (formula : formula) : bool =
raise Not_implemented
You are evaluating boolean formulae instead of float arithmetic. You also need to use the correct boolean value for each variable. We recommend using Variable_map.find_opt to perform lookups in the truth assignment. If a variable is needed but does not appear in the truth assignment, you must raise an Unassigned_variable x exception, where x is the unassigned variable.
Once again, you may use any functions you want and whichever recursive style you prefer.
The test cases you must implement for this problem are split into two lists. eval_success_tests is a list of tests for when eval does not raise an exception and yields a bool, and eval_failure_tests is a list of tests for when eval raises an exception.
Note: "f x && g y" is not the same as "let fx = f x in let gy = g y in fx && gy" if g has side effects (like raising an exception, which it may do in this problem). So you should prefer to use the second option in your implementation. We specifically designed tests that check for this issue.
Step by step
Solved in 4 steps