aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2021-02-07 02:43:54 +0100
committerRenaud G <renaud@rolisteam.org>2021-02-07 02:45:12 +0100
commitb9f44f8dffef37a182ed4b9fdba68c935a972026 (patch)
treec5dfc852cb7afcf0e70fe1b623d0d5253df01f7f /tests
parent0bba02370a82719e47ba0566c3c56ea0b770c96c (diff)
downloadOneRoll-b9f44f8dffef37a182ed4b9fdba68c935a972026.tar.gz
OneRoll-b9f44f8dffef37a182ed4b9fdba68c935a972026.zip
Add SwitchCaseNode
Diffstat (limited to 'tests')
-rw-r--r--tests/dice/tst_dice.cpp86
1 files changed, 85 insertions, 1 deletions
diff --git a/tests/dice/tst_dice.cpp b/tests/dice/tst_dice.cpp
index 910fb4d..97feb95 100644
--- a/tests/dice/tst_dice.cpp
+++ b/tests/dice/tst_dice.cpp
@@ -42,6 +42,7 @@
#include "node/sortresult.h"
#include "node/splitnode.h"
#include "node/stringnode.h"
+#include "node/switchcasenode.h"
#include "node/uniquenode.h"
#include "operationcondition.h"
#include "parsingtoolbox.h"
@@ -198,6 +199,9 @@ private slots:
void operatoionConditionValidatorTest();
+ void switchCaseTest();
+ void switchCaseTest_data();
+
private:
std::unique_ptr<Die> m_die;
std::unique_ptr<DiceParser> m_diceParser;
@@ -991,7 +995,7 @@ void TestDice::ifTest_data()
QTest::addRow("cmd9") << QVector<int>({25, 8, 14}) << onScalar << 1 << "False";
QTest::addRow("cmd10") << QVector<int>({25, 8, 14}) << onScalar << 47 << "True";
- QTest::addRow("cmd11") << QVector<int>({25, 8, 14}) << onEachValue << 47 << "True";
+ // QTest::addRow("cmd11") << QVector<int>({25, 8, 14}) << onEachValue << 47 << "True";
}
void TestDice::paintTest() {}
@@ -1210,6 +1214,86 @@ void TestDice::operatoionConditionValidatorTest()
QCOMPARE(value, data);
}
+void TestDice::switchCaseTest()
+{
+ using BC= BooleanCondition;
+ QFETCH(int, value);
+ QFETCH(QList<BC::LogicOperator>, operatorList);
+ QFETCH(QList<int>, threshold);
+ QFETCH(QStringList, values);
+ QFETCH(QString, expected);
+ QFETCH(bool, stopatfirt);
+
+ NumberNode* node1= new NumberNode();
+ node1->setNumber(value);
+
+ SwitchCaseNode* node2= new SwitchCaseNode();
+ node2->setStopAtFirt(stopatfirt);
+
+ int i= 0;
+ for(const auto& val : values)
+ {
+ ValidatorList* validatorList= nullptr;
+ if(i < threshold.size())
+ {
+ validatorList= makeValidator(QVector<int>{threshold[i]}, operatorList[i]);
+ }
+ auto stringNode= new StringNode();
+ stringNode->setString(val);
+ node2->insertCase(stringNode, validatorList);
+ ++i;
+ }
+
+ node1->setNextNode(node2);
+
+ node1->run(nullptr);
+
+ auto result= node2->getResult();
+ auto stringResult= result->getStringResult();
+
+ QCOMPARE(stringResult, expected);
+}
+
+void TestDice::switchCaseTest_data()
+{
+ using BC= BooleanCondition;
+ QTest::addColumn<int>("value");
+ QTest::addColumn<QList<BC::LogicOperator>>("operatorList");
+ QTest::addColumn<QList<int>>("threshold");
+ QTest::addColumn<QStringList>("values");
+ QTest::addColumn<QString>("expected");
+ QTest::addColumn<bool>("stopatfirt");
+
+ QTest::addRow("cmd1") << 75 << QList<BC::LogicOperator>{BC::Equal, BC::Equal} << QList<int>{75, 1}
+ << QStringList{"a", "b"} << QStringLiteral("a") << false;
+
+ QTest::addRow("cmd2") << 1 << QList<BC::LogicOperator>{BC::Equal, BC::Equal} << QList<int>{75, 1}
+ << QStringList{"a", "b"} << QStringLiteral("b") << true;
+
+ QTest::addRow("cmd3") << 7
+ << QList<BC::LogicOperator>{BC::GreaterThan, BC::GreaterThan, BC::GreaterThan,
+ BC::GreaterThan, BC::GreaterThan}
+ << QList<int>{8, 29, 99, 54, 1} << QStringList{"a", "b", "c", "d", "e"} << QStringLiteral("e")
+ << false;
+
+ QTest::addRow("cmd4") << 75 << QList<BC::LogicOperator>{BC::LesserThan, BC::LesserThan, BC::LesserThan}
+ << QList<int>{8, 7} << QStringList{"a", "b", "c"} << QStringLiteral("c") << false;
+
+ QTest::addRow("cmd5") << 2 << QList<BC::LogicOperator>{BC::Different, BC::Different} << QList<int>{1, 2}
+ << QStringList{"a", "b"} << QStringLiteral("a") << false;
+
+ QTest::addRow("cmd6") << 3
+ << QList<BC::LogicOperator>{BC::GreaterOrEqual, BC::GreaterOrEqual, BC::GreaterOrEqual,
+ BC::GreaterOrEqual}
+ << QList<int>{1, 2, 3, 4} << QStringList{"a", "b", "c", "d"} << QStringLiteral("a,b,c")
+ << false;
+
+ QTest::addRow("cmd6") << 3
+ << QList<BC::LogicOperator>{BC::LesserOrEqual, BC::LesserOrEqual, BC::LesserOrEqual,
+ BC::LesserOrEqual}
+ << QList<int>{1, 2, 3, 4} << QStringList{"a", "b", "c", "d"} << QStringLiteral("c") << true;
+}
+
void TestDice::cleanupTestCase() {}
QTEST_MAIN(TestDice)