aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2019-12-25 03:48:11 +0100
committerRenaud G <renaud@rolisteam.org>2019-12-25 03:48:11 +0100
commit825bcda767d2bab9f470d81cd76b9e5985fbea9c (patch)
treed117fe3469822f4bac31725beec5793abf332c4a
parentadf9031cf7ddf06d8806a2b8e4494984a21608b5 (diff)
downloadOneRoll-825bcda767d2bab9f470d81cd76b9e5985fbea9c.tar.gz
OneRoll-825bcda767d2bab9f470d81cd76b9e5985fbea9c.zip
Fix test of IF
-rw-r--r--node/ifnode.cpp36
-rw-r--r--tests/dice/tst_dice.cpp6
2 files changed, 35 insertions, 7 deletions
diff --git a/node/ifnode.cpp b/node/ifnode.cpp
index 43d055c..01b3f81 100644
--- a/node/ifnode.cpp
+++ b/node/ifnode.cpp
@@ -19,6 +19,7 @@
***************************************************************************/
#include "ifnode.h"
#include "result/diceresult.h"
+#include "result/stringresult.h"
PartialDiceRollNode::PartialDiceRollNode() : m_diceResult(new DiceResult)
{
@@ -117,9 +118,11 @@ void IfNode::run(ExecutionNode* previous)
if(m_conditionType == OnEach)
{
- auto diceResult= new DiceResult;
+ auto resultOnEach= m_result;
for(Die* dice : diceList)
{
+ auto diceResult= new DiceResult;
+ StringResult* stringResult= nullptr;
auto diceNode= new PartialDiceRollNode();
auto cpyDice= new Die(*dice);
diceNode->insertDie(cpyDice);
@@ -151,13 +154,34 @@ void IfNode::run(ExecutionNode* previous)
{
delete cpyDice;
auto branchResult= previousLoop->getResult();
- auto val= branchResult->getResult(Dice::RESULT_TYPE::SCALAR).toInt();
- auto valDie= new Die();
- valDie->insertRollValue(val);
- diceResult->insertResult(valDie);
+ if(branchResult->hasResultOfType(Dice::RESULT_TYPE::SCALAR))
+ {
+ auto val= branchResult->getResult(Dice::RESULT_TYPE::SCALAR).toInt();
+ auto valDie= new Die();
+ valDie->insertRollValue(val);
+ diceResult->insertResult(valDie);
+ }
+ else if(branchResult->hasResultOfType(Dice::RESULT_TYPE::STRING))
+ {
+ auto val= branchResult->getResult(Dice::RESULT_TYPE::STRING).toString();
+ stringResult= new StringResult;
+ stringResult->setText(val);
+ }
+ }
+ if(nullptr != stringResult)
+ {
+ stringResult->setPrevious(resultOnEach);
+ resultOnEach= stringResult;
+ delete diceResult;
+ }
+ else
+ {
+ diceResult->setPrevious(resultOnEach);
+ resultOnEach= diceResult;
}
}
- m_result= diceResult;
+
+ m_result= resultOnEach;
}
else if((m_conditionType == OneOfThem) || (m_conditionType == AllOfThem))
{
diff --git a/tests/dice/tst_dice.cpp b/tests/dice/tst_dice.cpp
index 98dcdc1..8d6c1ad 100644
--- a/tests/dice/tst_dice.cpp
+++ b/tests/dice/tst_dice.cpp
@@ -850,7 +850,11 @@ void TestDice::ifTest()
node.run(nullptr);
- auto text= dynamic_cast<StringResult*>(ifNode.getNextNode()->getResult())->getText();
+ QString text;
+ if(nullptr != ifNode.getNextNode())
+ text= dynamic_cast<StringResult*>(ifNode.getNextNode()->getResult())->getText();
+ else
+ text= dynamic_cast<StringResult*>(ifNode.getResult())->getText();
QCOMPARE(expectedResult, text);