diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | logic.c | 63 | ||||
-rw-r--r-- | logic.h | 3 | ||||
-rw-r--r-- | simulator.c | 1 | ||||
-rw-r--r-- | test/.gitignore | 6 | ||||
-rw-r--r-- | test/Makefile | 18 | ||||
-rw-r--r-- | test/test-logic-and.c | 10 | ||||
-rw-r--r-- | test/test-logic-nand.c | 10 | ||||
-rw-r--r-- | test/test-logic-nor.c | 10 | ||||
-rw-r--r-- | test/test-logic-not.c | 8 | ||||
-rw-r--r-- | test/test-logic-or.c | 10 | ||||
-rw-r--r-- | test/test-logic-xor.c | 10 |
12 files changed, 81 insertions, 70 deletions
@@ -5,7 +5,7 @@ all: simulator simulator: simulator.o gate.o logic.o parser.o .PHONY: test -test: +test: all $(MAKE) -C test all test clean: @@ -1,4 +1,3 @@ -#include <assert.h> #include <stdlib.h> #include "logic.h" @@ -51,65 +50,3 @@ enum BINARY logic_nor(enum BINARY a, enum BINARY b) { return logic_not(logic_or(a, b)); } - -void -logic_test_and() { - emit_info("Testing AND\n"); - assert(LOGIC_HIGH == logic_and(LOGIC_HIGH, LOGIC_HIGH)); - assert(LOGIC_LOW == logic_and(LOGIC_HIGH, LOGIC_LOW )); - assert(LOGIC_LOW == logic_and(LOGIC_LOW , LOGIC_HIGH)); - assert(LOGIC_LOW == logic_and(LOGIC_LOW , LOGIC_LOW )); -} - -void -logic_test_or() { - emit_info("Testing OR\n"); - assert(LOGIC_HIGH == logic_or(LOGIC_HIGH, LOGIC_HIGH)); - assert(LOGIC_HIGH == logic_or(LOGIC_HIGH, LOGIC_LOW )); - assert(LOGIC_HIGH == logic_or(LOGIC_LOW , LOGIC_HIGH)); - assert(LOGIC_LOW == logic_or(LOGIC_LOW , LOGIC_LOW )); -} - -void -logic_test_xor() { - emit_info("Testing XOR\n"); - assert(LOGIC_HIGH == logic_xor(LOGIC_HIGH, LOGIC_LOW )); - assert(LOGIC_HIGH == logic_xor(LOGIC_LOW , LOGIC_HIGH)); - assert(LOGIC_LOW == logic_xor(LOGIC_HIGH, LOGIC_HIGH)); - assert(LOGIC_LOW == logic_xor(LOGIC_LOW , LOGIC_LOW )); -} - -void -logic_test_nand() { - emit_info("Testing NAND\n"); - assert(LOGIC_LOW == logic_nand(LOGIC_HIGH, LOGIC_HIGH)); - assert(LOGIC_HIGH == logic_nand(LOGIC_HIGH, LOGIC_LOW )); - assert(LOGIC_HIGH == logic_nand(LOGIC_LOW , LOGIC_HIGH)); - assert(LOGIC_HIGH == logic_nand(LOGIC_LOW , LOGIC_LOW )); -} - -void -logic_test_nor() { - emit_info("Testing NOR\n"); - assert(LOGIC_HIGH == logic_nor(LOGIC_LOW , LOGIC_LOW )); - assert(LOGIC_LOW == logic_nor(LOGIC_LOW , LOGIC_HIGH)); - assert(LOGIC_LOW == logic_nor(LOGIC_HIGH, LOGIC_LOW )); - assert(LOGIC_LOW == logic_nor(LOGIC_HIGH, LOGIC_HIGH)); -} - -void -logic_test_not() { - emit_info("Testing NOT\n"); - assert(LOGIC_HIGH == logic_not(LOGIC_LOW )); - assert(LOGIC_LOW == logic_not(LOGIC_HIGH)); -} - -void -logic_test() { - logic_test_and(); - logic_test_or(); - logic_test_nand(); - logic_test_nor(); - logic_test_xor(); - logic_test_not(); -} @@ -6,12 +6,11 @@ enum BINARY { LOGIC_LOW }; +enum BINARY logic_not(enum BINARY a); enum BINARY logic_and(enum BINARY a, enum BINARY b); enum BINARY logic_or(enum BINARY a, enum BINARY b); enum BINARY logic_xor(enum BINARY a, enum BINARY b); enum BINARY logic_nand(enum BINARY a, enum BINARY b); enum BINARY logic_nor(enum BINARY a, enum BINARY b); -void logic_test(); - #endif diff --git a/simulator.c b/simulator.c index 657355f..c6462ea 100644 --- a/simulator.c +++ b/simulator.c @@ -12,7 +12,6 @@ int main(int argc, char **argv) { (void)argc; (void)argv; - logic_test(); gate_init(); while (NULL != fgets(buf, sizeof(buf), fd)) { diff --git a/test/.gitignore b/test/.gitignore index 2674822..04d77d8 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,2 +1,8 @@ +test-logic-and +test-logic-nand +test-logic-nor +test-logic-not +test-logic-or +test-logic-xor test-whitespace-input *.log diff --git a/test/Makefile b/test/Makefile index 25c1690..053552f 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,14 +1,26 @@ CFLAGS += -I../ TESTS = \ - test-whitespace-input + test-whitespace-input \ + test-logic-and \ + test-logic-or \ + test-logic-nand \ + test-logic-nor \ + test-logic-xor \ + test-logic-not \ -all: clean $(TESTS) -test-whitespace-input: ../gate.o ../parser.o ../logic.o +all: $(TESTS) +test-%: test-%.c ../gate.o ../parser.o ../logic.o + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ + +.PHONY: clean clean: rm -f $(TESTS) + for i in $(TESTS) ; do \ + rm -f $$i.std{out,err}.log ; \ + done .PHONY: test test: diff --git a/test/test-logic-and.c b/test/test-logic-and.c new file mode 100644 index 0000000..ce44ee8 --- /dev/null +++ b/test/test-logic-and.c @@ -0,0 +1,10 @@ +#include <assert.h> + +#include "logic.h" + +int main(void) { + assert(LOGIC_HIGH == logic_and(LOGIC_HIGH, LOGIC_HIGH)); + assert(LOGIC_LOW == logic_and(LOGIC_HIGH, LOGIC_LOW )); + assert(LOGIC_LOW == logic_and(LOGIC_LOW , LOGIC_HIGH)); + assert(LOGIC_LOW == logic_and(LOGIC_LOW , LOGIC_LOW )); +} diff --git a/test/test-logic-nand.c b/test/test-logic-nand.c new file mode 100644 index 0000000..ce44ee8 --- /dev/null +++ b/test/test-logic-nand.c @@ -0,0 +1,10 @@ +#include <assert.h> + +#include "logic.h" + +int main(void) { + assert(LOGIC_HIGH == logic_and(LOGIC_HIGH, LOGIC_HIGH)); + assert(LOGIC_LOW == logic_and(LOGIC_HIGH, LOGIC_LOW )); + assert(LOGIC_LOW == logic_and(LOGIC_LOW , LOGIC_HIGH)); + assert(LOGIC_LOW == logic_and(LOGIC_LOW , LOGIC_LOW )); +} diff --git a/test/test-logic-nor.c b/test/test-logic-nor.c new file mode 100644 index 0000000..20ddcb7 --- /dev/null +++ b/test/test-logic-nor.c @@ -0,0 +1,10 @@ +#include <assert.h> + +#include "logic.h" + +int main(void) { + assert(LOGIC_LOW == logic_nor(LOGIC_HIGH, LOGIC_HIGH)); + assert(LOGIC_LOW == logic_nor(LOGIC_HIGH, LOGIC_LOW )); + assert(LOGIC_LOW == logic_nor(LOGIC_LOW , LOGIC_HIGH)); + assert(LOGIC_HIGH == logic_nor(LOGIC_LOW , LOGIC_LOW )); +} diff --git a/test/test-logic-not.c b/test/test-logic-not.c new file mode 100644 index 0000000..a3a3e4d --- /dev/null +++ b/test/test-logic-not.c @@ -0,0 +1,8 @@ +#include <assert.h> + +#include "logic.h" + +int main(void) { + assert(LOGIC_HIGH == logic_not(LOGIC_LOW )); + assert(LOGIC_LOW == logic_not(LOGIC_HIGH)); +} diff --git a/test/test-logic-or.c b/test/test-logic-or.c new file mode 100644 index 0000000..7af3cbd --- /dev/null +++ b/test/test-logic-or.c @@ -0,0 +1,10 @@ +#include <assert.h> + +#include "logic.h" + +int main(void) { + assert(LOGIC_HIGH == logic_or(LOGIC_HIGH, LOGIC_HIGH)); + assert(LOGIC_HIGH == logic_or(LOGIC_HIGH, LOGIC_LOW )); + assert(LOGIC_HIGH == logic_or(LOGIC_LOW , LOGIC_HIGH)); + assert(LOGIC_LOW == logic_or(LOGIC_LOW , LOGIC_LOW )); +} diff --git a/test/test-logic-xor.c b/test/test-logic-xor.c new file mode 100644 index 0000000..9828ee9 --- /dev/null +++ b/test/test-logic-xor.c @@ -0,0 +1,10 @@ +#include <assert.h> + +#include "logic.h" + +int main(void) { + assert(LOGIC_LOW == logic_xor(LOGIC_HIGH, LOGIC_HIGH)); + assert(LOGIC_HIGH == logic_xor(LOGIC_HIGH, LOGIC_LOW )); + assert(LOGIC_HIGH == logic_xor(LOGIC_LOW , LOGIC_HIGH)); + assert(LOGIC_LOW == logic_xor(LOGIC_LOW , LOGIC_LOW )); +} |