summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-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
8 files changed, 79 insertions, 3 deletions
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 ));
+}