Mini-project: Functional abstraction and instantiations

The goal of this mini-project is to revisit the unit-test functions for boolean functions from the chapter about test coverage in Week 04 in the light of the chapter about functional abstraction and instantiations.

From implementing conjunction (Exercise 02) to implementing exclusive disjunction (Exercise 06), there was a common pattern:

  1. start from the truth table of the boolean function at hand;

  2. implement a function that enumerates this truth table:

    let boolean_function_at_hand b1 b2 =
      if b1
      then (if b2
            then cell_in_the_truth_table_for_true_and_true
            else cell_in_the_truth_table_for_true_and_false)
      else (if b2
            then cell_in_the_truth_table_for_false_and_true
            else cell_in_the_truth_table_for_false_and_false);;
    
  3. simplify the implementation on the ground that for any boolean value b,

    • if b then true else true and true are observationally equivalent,
    • if b then false else false and false are observationally equivalent,
    • if b then true else false and b are observationally equivalent, and
    • if b then false else true and not b are observationally equivalent.

Task

In the spirit of the chapter about functional abstraction and instantiations, implement a maker of boolean functions that is parameterized with the 4 cells of their truth table and solve Exercise 02.c to Exercise 06.c in the chapter about test coverage with instances of this maker. Verify that each of your implementations passes the unit tests of each of the exercises.

Subsidiary question: Are your implementations correct? Why?

Resource

Version

Created [10 Jan 2023]

Table Of Contents

Previous topic

Mini projects

Next topic

Mini-project: The underlying determinism of OCaml