<> <> @ As usual, we first define some tests and then use the tests to define the implementation. <>= (add-test (make-test-suite "Boolean Type Test Suite" NIL <> ) max-test-suite ) @ \subsection{Type definition} The boolean type needs to be a type. Test that. <>= (defmethod boolean1 ((nf nullfix)) (unless (eq (addr-type *boolean-type*) (addr-type *types*)) (failure "The type of *boolean-type* is not the type of *types*") )) @ <>= ("Type of *boolean-type*" 'nullfix :test-thunk 'boolean1) @ There are only two values: TRUE and FALSE. Their addresses need to be of the boolean type, so test that. <>= (defmethod boolean2 ((nf nullfix)) (unless (eq (addr-type true) (addr-value *boolean-type*)) (failure "The type of TRUE is not *boolean-type*") )) (defmethod boolean3 ((nf nullfix)) (unless (eq (addr-type false) (addr-value *boolean-type*)) (failure "The type of FALSE is not *boolean-type*") )) @ Add all the tests on TRUE and FALSE to the test suite. <>= ("Type of TRUE" 'nullfix :test-thunk 'boolean2) ("Type of FALSE" 'nullfix :test-thunk 'boolean3) When we implement NOT, we want to make sure it's a function with the right domain and codomain. <>= (defmethod domain-boolean-not ((nf nullfix)) (unless (equal (function-apply *domain* boolean-not) *boolean-type*) (failure "The domain of boolean NOT is not *boolean-type*") )) (defmethod codomain-boolean-not ((nf nullfix)) (unless (equal (function-apply *codomain* boolean-not) *boolean-type*) (failure "The codomain of boolean NOT is not *boolean-type*") )) @ Since booleans are so simple, we can just test all the cases. <>= ; Use EQUAL here instead of EQ because the addresses may get reconstructed ; by the function call, and need not be the same exact list. ; If they contain hash tables, those need to be EQ, which is exactly ; what EQUAL tests. (EQUALP would be wrong) (defmethod boolean-func1 ((nf nullfix)) (unless (equal (function-apply boolean-not true) false) (failure "The boolean NOT of TRUE is not FALSE") )) (defmethod boolean-func2 ((nf nullfix)) (unless (equal (function-apply boolean-not false) true) (failure "The boolean NOT of FALSE is not TRUE") )) @ Add all the tests on Boolean NOT to the test suite. <>= ("Domain of boolean NOT" 'nullfix :test-thunk 'domain-boolean-not) ("Codomain of boolean NOT" 'nullfix :test-thunk 'codomain-boolean-not) ("NOT TRUE" 'nullfix :test-thunk 'boolean-func1) ("NOT FALSE" 'nullfix :test-thunk 'boolean-func2) Boolean identity needs two types, a domain and a codomain: <>= (defmethod domain-boolean-id ((nf nullfix)) (unless (equal (function-apply *domain* boolean-identity) *boolean-type*) (failure "The domain of boolean identity is not *boolean-type*") )) (defmethod codomain-boolean-id ((nf nullfix)) (unless (equal (function-apply *codomain* boolean-identity) *boolean-type*) (failure "The codomain of boolean identity is not *boolean-type*") )) @ It also needs two key/value pairs: <>= (defmethod boolean-func3 ((nf nullfix)) (unless (equal (function-apply boolean-identity true) true) (failure "The boolean identity of TRUE is not TRUE") )) (defmethod boolean-func4 ((nf nullfix)) (unless (equal (function-apply boolean-identity false) false) (failure "The boolean identity of FALSE is not FALSE") )) @ Add all the tests on Boolean IDENTITY to the test suite: <>= ("TRUE identity" 'nullfix :test-thunk 'boolean-func3) ("FALSE identity" 'nullfix :test-thunk 'boolean-func4) ("Domain of boolean identity" 'nullfix :test-thunk 'domain-boolean-id) ("Codomain of boolean identity" 'nullfix :test-thunk 'codomain-boolean-id)