Some of you who are still working on Project 1 may want to find a way to test your code. One of the joys of Lisp is that it is very easy to set up a testing system. In Java this requires a module such as JUnit. In Lisp you can roll your own in a few lines.
The following code is a testing system for Project 1. Load the code into your version of Lisp, and then call (project1). This module will then test your code against all the examples given in the homework, as follows:
CL-USER 40 > (project1)
CORRECT: The result of (MY-MEMBER (QUOTE A) (QUOTE (B C J A))) is (A)
CORRECT: The result of (MY-MEMBER (QUOTE (C D)) (QUOTE (A B C (A B) (C D) J K))) is ((C D) J K)
CORRECT: The result of (MY-MEMBER (QUOTE A) (QUOTE (B C (A D) E))) is NIL
CORRECT: The result of (MY-INSERT (QUOTE A) (QUOTE (B C D E)) 0) is (A B C D E)
CORRECT: The result of (MY-INSERT (QUOTE A) (QUOTE (B C D E)) 3) is (B C D A E)
CORRECT: The result of (MY-INSERT (QUOTE A) (QUOTE (B C D E)) 14) is (B C D E A)
CORRECT: The result of (MY-REMOVE-DUPS (QUOTE (A B A C A D))) is (D C B A)
CORRECT: The result of (MY-REMOVE-DUPS (QUOTE (A B (A C) A D))) is (D (A C) B A)
CORRECT: The result of (MY-REMOVE-DUPS (QUOTE (A B (B C) A (B C) D))) is (D (B C) B A)
CORRECT: The result of (MY-INTERSECTION (QUOTE (A B C)) (QUOTE (C A E))) is (C A)
CORRECT: The result of (MY-INTERSECTION (QUOTE (A B (A C) C)) (QUOTE (A C B))) is (C B A)
CORRECT: The result of (MY-INTERSECTION (QUOTE (A B (A C) C)) (QUOTE ((A C) B))) is ((A C) B)
CORRECT: The result of (DYADIC-APPLY (FUNCTION +) (QUOTE (1 2 3)) (QUOTE (6 5 4))) is (7 7 7)
CORRECT: The result of (DYADIC-APPLY (FUNCTION LIST) (QUOTE (A B C)) (QUOTE (1 2 3 4))) is ((A 1) (B 2) (C 3))
CORRECT: The result of (TREE-SUM (QUOTE (1 2 3 4 5))) is 15
CORRECT: The result of (TREE-SUM (QUOTE (A 1 B 2))) is 3
CORRECT: The result of (TREE-SUM (QUOTE (A (1 (2 (3 B) C) D E) F 4))) is 10
CORRECT: The result of (MY-FLATTEN (QUOTE (A B (C D)))) is (A B C D)
CORRECT: The result of (MY-FLATTEN (QUOTE (A (B (C (D (E F))) G (H I (J K)) L (M)) (((N)))))) is (A B C D E F G H I J K L M N)
CORRECT: The result of (FULL-REVERSE (QUOTE (A B C D))) is (D C B A)
CORRECT: The result of (FULL-REVERSE (QUOTE (A (B C) D))) is (D (C B) A)
CORRECT: The result of (FULL-REVERSE (QUOTE ((A B) (C (D E) F G (H I) J K) L M))) is (M L (K J (I H) G F (E D) C) (B A))
CORRECT: The result of (MY-SUBST (QUOTE A) (QUOTE B) (QUOTE (T H B D S T B R N E R))) is (T H A D S T A R N E R)
CORRECT: The result of (MY-SUBST (QUOTE A) (QUOTE B) (QUOTE (A B (A B (A B)) (A B)))) is (A A (A A (A A)) (A A))
NIL
Here’s the code (after the jump):
(more…)
Read Full Post »