summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--logic.c63
-rw-r--r--logic.h3
-rw-r--r--simulator.c1
-rw-r--r--test/.gitignore6
-rw-r--r--test/Makefile18
-rw-r--r--test/test-logic-and.c10
-rw-r--r--test/test-logic-nand.c10
-rw-r--r--test/test-logic-nor.c10
-rw-r--r--test/test-logic-not.c8
-rw-r--r--test/test-logic-or.c10
-rw-r--r--test/test-logic-xor.c10
12 files changed, 81 insertions, 70 deletions
diff --git a/Makefile b/Makefile
index a41403f..3fdfcd2 100644
--- a/Makefile
+++ b/Makefile
@@ -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:
diff --git a/logic.c b/logic.c
index a9f09da..1775de0 100644
--- a/logic.c
+++ b/logic.c
@@ -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();
-}
diff --git a/logic.h b/logic.h
index d791eef..9d160d7 100644
--- a/logic.h
+++ b/logic.h
@@ -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 ));
+}