From 7823d9c7e4f3c0485e8d96e44e0d94541762c6d1 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Thu, 28 Dec 2017 19:58:57 +1300 Subject: Move logic tests to test framework --- test/.gitignore | 6 ++++++ test/Makefile | 18 +++++++++++++++--- test/test-logic-and.c | 10 ++++++++++ test/test-logic-nand.c | 10 ++++++++++ test/test-logic-nor.c | 10 ++++++++++ test/test-logic-not.c | 8 ++++++++ test/test-logic-or.c | 10 ++++++++++ test/test-logic-xor.c | 10 ++++++++++ 8 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 test/test-logic-and.c create mode 100644 test/test-logic-nand.c create mode 100644 test/test-logic-nor.c create mode 100644 test/test-logic-not.c create mode 100644 test/test-logic-or.c create mode 100644 test/test-logic-xor.c (limited to 'test') 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 + +#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 + +#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 + +#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 + +#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 + +#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 + +#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 )); +} -- cgit v1.1