While loop testing conditions now included

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 07a4c5bbfa
commit 570d2ac5a1
  1. BIN
      C++ProjectTemplate
  2. 47
      test/test.cpp

Binary file not shown.

@ -23,6 +23,9 @@
#include "../SeasonI.h" #include "../SeasonI.h"
#include "../map.h" #include "../map.h"
#define TestWhileMax(testname,condition,maxIterations) _TestWait(testname);while(_TestResolve(condition,maxIterations))
#define TestWhile(testname,condition) TestWhileMax(testname,condition,1000)
extern int frameCount; extern int frameCount;
extern double CUTSCENE_FADE_VALUE; extern double CUTSCENE_FADE_VALUE;
extern Cutscene*CurrentCutscene; extern Cutscene*CurrentCutscene;
@ -40,6 +43,8 @@ extern std::map<Property,BattleProperty*> BATTLE_PROPERTIES;
extern std::map<MapName::Map,Map*> MAPS; extern std::map<MapName::Map,Map*> MAPS;
int testCount=0; int testCount=0;
int MAX_ITERATIONS=1000;
int iterations=0;
void Test(std::string name,bool success) { void Test(std::string name,bool success) {
testCount++; testCount++;
@ -48,6 +53,24 @@ void Test(std::string name,bool success) {
std::cout<<" Passed"<<std::endl; std::cout<<" Passed"<<std::endl;
}; };
void _TestWait(std::string name) {
testCount++;
std::cout<<"Test ("<<testCount<<") "<<name<<"..."<<std::endl;
iterations=0;
};
bool _TestResolve(bool testCase,int maxIterations=MAX_ITERATIONS) {
if (!testCase) {
std::cout<<" Passed"<<std::endl;
return false;
}
if (iterations++>MAX_ITERATIONS) {
std::cout<<" FAILED! (Iterations>"<<maxIterations<<")"<<std::endl;
assert(!testCase);
}
return true;
};
void TestSpriteUndefined(std::vector<std::string> sprList) { void TestSpriteUndefined(std::vector<std::string> sprList) {
for (int i=0;i<sprList.size();i++) { for (int i=0;i<sprList.size();i++) {
Test("Sprite "+sprList[i]+" should not be initialized", Test("Sprite "+sprList[i]+" should not be initialized",
@ -231,7 +254,7 @@ bool SeasonI::OnUserCreate(){
Test("HandleCutscenes should get called in updateGame(), updating the current action", Test("HandleCutscenes should get called in updateGame(), updating the current action",
CurrentAction!=ActionType::NONE); CurrentAction!=ActionType::NONE);
int startFrame=frameCount; int startFrame=frameCount;
while (CurrentAction!=ActionType::NONE) { TestWhile("Cutscene should complete entirely",CurrentAction!=ActionType::NONE) {
updateGame(); updateGame();
} }
std::cout<<"Frame Count: "<<(frameCount-startFrame)<<std::endl; std::cout<<"Frame Count: "<<(frameCount-startFrame)<<std::endl;
@ -292,7 +315,7 @@ bool SeasonI::OnUserCreate(){
CUTSCENE_FADE_VALUE>previous_fade_value); CUTSCENE_FADE_VALUE>previous_fade_value);
Test("There should be no objects in the game", Test("There should be no objects in the game",
OBJECTS.size()==0); OBJECTS.size()==0);
while (CurrentAction==ActionType::FADE) { TestWhile("Fade out should finish",CurrentAction==ActionType::FADE) {
updateGame(); updateGame();
} }
Test("When faded out, CUTSCENE_FADE_VALUE should be 255", Test("When faded out, CUTSCENE_FADE_VALUE should be 255",
@ -310,7 +333,7 @@ bool SeasonI::OnUserCreate(){
updateGame(); updateGame();
Test("Fading in causes CUTSCENE_FADE_VALUE to decrease", Test("Fading in causes CUTSCENE_FADE_VALUE to decrease",
CUTSCENE_FADE_VALUE<previous_fade_value); CUTSCENE_FADE_VALUE<previous_fade_value);
while (CurrentAction==ActionType::FADE) { TestWhile("Fade in should finish",CurrentAction==ActionType::FADE) {
updateGame(); updateGame();
} }
Test("Next cutscene action should be setting a flag when the cutscene ends", Test("Next cutscene action should be setting a flag when the cutscene ends",
@ -332,11 +355,27 @@ bool SeasonI::OnUserCreate(){
CurrentAction==ActionType::PAN_CAMERA); CurrentAction==ActionType::PAN_CAMERA);
Test("Camera position should be moving towards {128,128}", Test("Camera position should be moving towards {128,128}",
cameraPos.x>0&&cameraPos.y>0); cameraPos.x>0&&cameraPos.y>0);
while (CurrentAction==ActionType::PAN_CAMERA) { Test("Temporary cutscene object 1 is at position {136,136}",
CurrentCutscene->GetCutsceneObjects()[1]->GetPos().x==136&&CurrentCutscene->GetCutsceneObjects()[1]->GetPos().y==136);
TestWhile("Panning Camera should finish",CurrentAction==ActionType::PAN_CAMERA) {
updateGame(); updateGame();
} }
Test("Camera position should be {128,128}", Test("Camera position should be {128,128}",
cameraPos.x==128&&cameraPos.y==128); cameraPos.x==128&&cameraPos.y==128);
Test("Next cutscene action is the async cutscene object movement",
CurrentAction==ActionType::MOVE_CUTSCENE_OBJ_ASYNC);
vd2d prevCutsceneObjPosition=CurrentCutscene->GetCutsceneObjects()[1]->GetPos();
updateGame();
Test("Cutscene object is moving towards {80,64}",
CurrentCutscene->GetCutsceneObjects()[1]->GetPos().x<prevCutsceneObjPosition.x&&CurrentCutscene->GetCutsceneObjects()[1]->GetPos().y<prevCutsceneObjPosition.y);
vd2d prevCameraPos=cameraPos;
Test("Due to async actions, next cutscene action should be Pan Camera Async",
CurrentAction==ActionType::PAN_CAMERA_ASYNC);
updateGame();
Test("Camera is moving towards {64,0}",
prevCameraPos.x>cameraPos.x&&prevCameraPos.y>cameraPos.y);
Test("Due to async actions, next cutscene action should be Dialog Box Async",
CurrentAction==ActionType::DIALOG_ASYNC);
return true; return true;
} }

Loading…
Cancel
Save