Skip to content

Commit

Permalink
evol(tests): add IO tests and coverage in Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesmadjeri committed Feb 19, 2024
1 parent e6e158e commit 50b7b2b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 15 deletions.
35 changes: 20 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,31 @@ CXX = g++
CFLAGS = -std=c++20 -Wall -Wextra
V_FLAG = --leak-check=full --show-leak-kinds=all --track-origins=yes
EXE = nanotekspice
TEST_EXE = nanotester
TEST_EXE = unit_tests
SAN = -g3
COV = --coverage

all: $(EXE)

%.o: %.cpp
$(CXX) -o $@ -c $< $(CFLAGS) $(SAN)
$(CXX) -o $@ -c $< $(CFLAGS) $(SAN) $(COV)

$(EXE): $(OBJ)
$(CXX) -o $(EXE) $^
$(CXX) -o $(EXE) $^ $(COV)

$(TEST_EXE): $(TEST_OBJ)
$(CXX) -o $(TEST_EXE) $^ -lcriterion --coverage

test: $(TEST_EXE)
gcovr --exclude ./test
./$(TEST_EXE)
$(CXX) -o $(TEST_EXE) $^ -lcriterion $(COV)

clean:
@rm -rf $(OBJ)
@rm -rf $(TEST_OBJ)
@rm -rf vgcore*
@rm -rf *.gcda
@rm -rf *.gcno
@rm -rf $(OBJ)
@rm -rf $(TEST_OBJ)
@rm -rf vgcore*
@find . -type f -name '*.gcda' -delete
@find . -type f -name '*.gcno' -delete

fclean: clean
@rm -rf $(EXE)
@rm -rf $(TEST_EXE)
@rm -rf $(EXE)
@rm -rf $(TEST_EXE)

re: fclean all

Expand All @@ -44,3 +41,11 @@ val:

val_full:
make re && valgrind $(V_FLAG) ./$(EXE)

test: $(TEST_EXE)
./$(TEST_EXE)

tests_run: test # for mouli
gcovr --exclude ./test

.PHONY: all clean fclean re val val_full test tests_run
61 changes: 61 additions & 0 deletions test/Special/TestInputOutput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <criterion/criterion.h>
#include <criterion/redirect.h>
#include "../../include/paths.hpp"
#include "../../src/Manager/Manager.hpp"

nts::Manager IOManager;

void IOSetup() {
IOManager.initializeTruthTables(TRUTH_TABLE_PATH);
IOManager.createComponent("input", "input1");
IOManager.createComponent("output", "output1");
}

void IOTeardown() {
IOManager.clearComponents();
}

TestSuite(InputOutput, .init = IOSetup, .fini = IOTeardown);

Test(InputOutput, should_create_input) {
nts::IComponent *component = IOManager.getComponent("input1");

cr_assert_eq(component->getLabel(), "input1");
cr_assert_eq(component->getType(), nts::ComponentType::Input);
cr_assert_eq(component->getValue(1), nts::Tristate::Undefined);
}

Test(InputOutput, should_create_output) {
nts::IComponent *component = IOManager.getComponent("output1");

cr_assert_eq(component->getLabel(), "output1");
cr_assert_eq(component->getType(), nts::ComponentType::Output);
cr_assert_eq(component->getValue(1), nts::Tristate::Undefined);
}

Test(InputOutput, should_set_value_input) {
nts::IComponent *component = IOManager.getComponent("input1");

component->setValue(nts::Tristate::True);
IOManager.simulate(1);
cr_assert_eq(component->getValue(1), nts::Tristate::True);

component->setValue(nts::Tristate::False);
IOManager.simulate(2);
cr_assert_eq(component->getValue(1), nts::Tristate::False);
}

Test(InputOutput, should_compute_behaviour_output) {
nts::IComponent *input = IOManager.getComponent("input1");
nts::IComponent *output = IOManager.getComponent("output1");

IOManager.addLink("input1", 1, "output1", 1);

input->setValue(nts::Tristate::True);
IOManager.simulate(1);
cr_assert_eq(output->getValue(1), nts::Tristate::True);

input->setValue(nts::Tristate::False);
IOManager.simulate(2);
cr_assert_eq(output->getValue(1), nts::Tristate::False);
}

0 comments on commit 50b7b2b

Please sign in to comment.