Advertisement
ultiprosan

Untitled

May 20th, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.72 KB | None | 0 0
  1. /******************************************
  2.  * Solution template provided to Students *
  3.  ******************************************/
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. /* --- Dispatch types --- */
  9. enum {
  10.   Call_eval = 0
  11. };
  12.  
  13. /* --- Env type def --- */
  14.  
  15. // bind
  16.  
  17. // lookup
  18.  
  19. /* --- Prop --- */
  20.  
  21. typedef struct Prop {
  22.   void (**vtable)();
  23. } Prop;
  24.  
  25. int eval(Prop* prop, Env* env) {
  26.   // ...
  27. }
  28.  
  29. /* --- True/False --- */
  30.  
  31.  
  32. /* --- Atom --- */
  33.  
  34.  
  35. /* --- Not --- */
  36.  
  37.  
  38. /* --- And/Or --- */
  39.  
  40. /******************************
  41.  * Tests provided to students *
  42.  ******************************/
  43. /* import test framework .h */
  44. #include "solution.c"
  45. #include "CuTest.h"
  46. #include "CuJoin.h"
  47.  
  48. /* your imported libraries */
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52.  
  53. * defined tests */
  54.  
  55. void test1b(CuTest *tc){
  56.     Env* env = bind(bind(NULL, "A", 1), "B", 1);
  57.     CuAssertIntEquals(tc, 2, lookup(env, "A") << lookup(env, "B"));
  58. }
  59.  
  60. void test1(CuTest *tc) {
  61.     Prop* prop = (Prop*)
  62.             newOr(
  63.                     newAnd(newTrue(),newFalse()),
  64.                     newAnd(newNot(newFalse()), newNot(newAtom("A"))));
  65.     Env* env = bind(NULL, "A", 0);
  66.     int res = eval(prop,env);
  67.     CuAssertIntEquals(tc, 1, res);
  68. }
  69.  
  70. void test2(CuTest *tc) {
  71.     Prop* prop = (Prop*)
  72.             newOr(
  73.                     newAnd(newAtom("A"),newAtom("B")),
  74.                     newOr(newNot(newAtom("C")), newNot(newAtom("D"))));
  75.     Env* env = bind(bind(bind(bind(NULL, "D", 0), "C", 1), "B", 0), "A", 1);
  76.     int res = eval(prop,env);
  77.     CuAssertIntEquals(tc, 1, res);
  78. }
  79.  
  80.  
  81. /* hook all your tests into the harness */
  82. void testHooker(CuSuite* intoSuite){
  83.     SUITE_ADD_TEST(intoSuite, test1b);
  84.   /*SUITE_ADD_TEST(intoSuite, test1);
  85.   SUITE_ADD_TEST(intoSuite, test2);*/
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement