-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
evol(Tests): add test on Icomp and And
Signed-off-by: Mael-RABOT <[email protected]>
- Loading branch information
1 parent
8b9bb7d
commit 4fad731
Showing
8 changed files
with
141 additions
and
25 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <criterion/criterion.h> | ||
#include <criterion/redirect.h> | ||
|
||
#include "../include/paths.hpp" | ||
#include "../src/Manager/Manager.hpp" | ||
|
||
nts::Manager AndManager; | ||
|
||
void AndSetup() { | ||
AndManager.initializeTruthTables(TRUTH_TABLE_PATH); | ||
AndManager.createComponent("and", "and1"); | ||
AndManager.createComponent("input", "in1"); | ||
AndManager.createComponent("input", "in2"); | ||
AndManager.createComponent("output", "out1"); | ||
AndManager.addLink("in1", 1, "and1", 1); | ||
AndManager.addLink("in2", 1, "and1", 2); | ||
AndManager.addLink("and1", 3, "out1", 1); | ||
} | ||
|
||
void AndTeardown() { | ||
AndManager.clearComponents(); | ||
} | ||
|
||
TestSuite(And, .init = AndSetup, .fini = AndTeardown); | ||
|
||
Test(And, should_create_and) { | ||
nts::IComponent *component = AndManager.getComponent("and1"); | ||
|
||
cr_assert_eq(component->getLabel(), "and1"); | ||
cr_assert_eq(component->getType(), nts::ComponentType::Standard); | ||
} | ||
|
||
Test(And, should_link_and) { | ||
nts::IComponent *output = AndManager.getComponent("out1"); | ||
cr_assert_eq(output->getValue(1), nts::Tristate::Undefined); | ||
|
||
AndManager.simulate(0); | ||
cr_assert_eq(output->getValue(1), nts::Tristate::Undefined); | ||
|
||
AndManager.getComponent("in1")->setValue(nts::Tristate::True); | ||
AndManager.getComponent("in2")->setValue(nts::Tristate::True); | ||
AndManager.simulate(1); | ||
|
||
cr_assert_eq(output->getValue(1), nts::Tristate::True); | ||
|
||
AndManager.getComponent("in2")->setValue(nts::Tristate::False); | ||
AndManager.simulate(2); | ||
|
||
cr_assert_eq(output->getValue(1), nts::Tristate::False); | ||
} | ||
|
||
Test(And, and_truth_table) { | ||
std::vector<nts::Tristate> states = {nts::Tristate::True, nts::Tristate::False, nts::Tristate::Undefined}; | ||
|
||
for (auto state1 : states) { | ||
for (auto state2 : states) { | ||
AndManager.getComponent("in1")->setValue(state1); | ||
AndManager.getComponent("in2")->setValue(state2); | ||
AndManager.simulate(); | ||
|
||
nts::Tristate expectedOutput; | ||
if (state1 == nts::Tristate::False || state2 == nts::Tristate::False) { | ||
expectedOutput = nts::Tristate::False; | ||
} else if (state1 == nts::Tristate::True && state2 == nts::Tristate::True) { | ||
expectedOutput = nts::Tristate::True; | ||
} else { | ||
expectedOutput = nts::Tristate::Undefined; | ||
} | ||
|
||
nts::IComponent *output = AndManager.getComponent("out1"); | ||
cr_assert_eq(output->getValue(1), expectedOutput); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <criterion/criterion.h> | ||
#include <criterion/redirect.h> | ||
|
||
#include "../include/paths.hpp" | ||
#include "../src/Manager/Manager.hpp" | ||
|
||
nts::Manager IComponentManager; | ||
|
||
void IComponentSetup() { | ||
IComponentManager.initializeTruthTables(TRUTH_TABLE_PATH); | ||
} | ||
|
||
void IComponentTeardown() { | ||
IComponentManager.clearComponents(); | ||
} | ||
|
||
TestSuite(IComponent, .init = IComponentSetup, .fini = IComponentTeardown); | ||
|
||
Test(IComponent, should_create_component) | ||
{ | ||
IComponentManager.createComponent("input", "in1"); | ||
nts::IComponent *component = IComponentManager.getComponent("in1"); | ||
|
||
cr_assert_eq(component->getLabel(), "in1"); | ||
cr_assert_eq(component->getType(), nts::ComponentType::Input); | ||
} | ||
|
||
Test(IComponent, should_link_input_and_output) | ||
{ | ||
IComponentManager.createComponent("input", "in1"); | ||
IComponentManager.createComponent("output", "out1"); | ||
IComponentManager.addLink("in1", 1, "out1", 1); | ||
|
||
nts::IComponent *output = IComponentManager.getComponent("out1"); | ||
cr_assert_eq(output->getValue(1), nts::Tristate::Undefined); | ||
|
||
IComponentManager.simulate(0); | ||
cr_assert_eq(output->getValue(1), nts::Tristate::Undefined); | ||
|
||
IComponentManager.getComponent("in1")->setValue(nts::Tristate::True); | ||
IComponentManager.simulate(1); | ||
cr_assert_eq(output->getValue(1), nts::Tristate::True); | ||
} |