Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************
- * Solution template provided to Students *
- ******************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /* --- Dispatch types --- */
- enum {
- Call_eval = 0
- };
- /* --- Env type def --- */
- // bind
- // lookup
- /* --- Prop --- */
- typedef struct Prop {
- void (**vtable)();
- } Prop;
- int eval(Prop* prop, Env* env) {
- // ...
- }
- /* --- True/False --- */
- /* --- Atom --- */
- /* --- Not --- */
- /* --- And/Or --- */
- /******************************
- * Tests provided to students *
- ******************************/
- /* import test framework .h */
- #include "solution.c"
- #include "CuTest.h"
- #include "CuJoin.h"
- /* your imported libraries */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- * defined tests */
- void test1b(CuTest *tc){
- Env* env = bind(bind(NULL, "A", 1), "B", 1);
- CuAssertIntEquals(tc, 2, lookup(env, "A") << lookup(env, "B"));
- }
- void test1(CuTest *tc) {
- Prop* prop = (Prop*)
- newOr(
- newAnd(newTrue(),newFalse()),
- newAnd(newNot(newFalse()), newNot(newAtom("A"))));
- Env* env = bind(NULL, "A", 0);
- int res = eval(prop,env);
- CuAssertIntEquals(tc, 1, res);
- }
- void test2(CuTest *tc) {
- Prop* prop = (Prop*)
- newOr(
- newAnd(newAtom("A"),newAtom("B")),
- newOr(newNot(newAtom("C")), newNot(newAtom("D"))));
- Env* env = bind(bind(bind(bind(NULL, "D", 0), "C", 1), "B", 0), "A", 1);
- int res = eval(prop,env);
- CuAssertIntEquals(tc, 1, res);
- }
- /* hook all your tests into the harness */
- void testHooker(CuSuite* intoSuite){
- SUITE_ADD_TEST(intoSuite, test1b);
- /*SUITE_ADD_TEST(intoSuite, test1);
- SUITE_ADD_TEST(intoSuite, test2);*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement