Skip to content

Commit ef511b9

Browse files
committed
Refactor tests 0-30 with assertions
1 parent ff8f416 commit ef511b9

20 files changed

Lines changed: 135 additions & 365 deletions

src/Ninja/G1CP/Content/Tests/test0003.d

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ func void G1CP_Test_0003() {
2020
var string wp; wp = Npc_GetNearestWp(hero);
2121
Wld_InsertNpc(G1CP_Test_0003_Npc, wp);
2222
var C_Npc test; test = Hlp_GetNpc(G1CP_Test_0003_Npc);
23-
if (!Hlp_IsValidNpc(test)) {
24-
G1CP_TestsuiteErrorDetail("Failed to insert NPC");
25-
return;
26-
};
23+
G1CP_Testsuite_Assert(Hlp_IsValidNpc(test), TRUE);
2724

2825
// Insert items
2926
wp = Npc_GetNearestWp(hero);

src/Ninja/G1CP/Content/Tests/test0007.d

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ func void G1CP_Test_0007() {
2323
var string wp; wp = Npc_GetNearestWp(hero);
2424
Wld_InsertNpc(G1CP_Test_0007_Npc, wp);
2525
var C_Npc test; test = Hlp_GetNpc(G1CP_Test_0007_Npc);
26-
if (!Hlp_IsValidNpc(test)) {
27-
G1CP_TestsuiteErrorDetail("Failed to insert NPC");
28-
return;
29-
};
26+
G1CP_Testsuite_Assert(Hlp_IsValidNpc(test), TRUE);
3027

3128
// Second pass
3229
Wld_InsertNpc(G1CP_Test_0007_Npc, wp);

src/Ninja/G1CP/Content/Tests/test0010.d

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ func void G1CP_Test_0010() {
1515
var string wp; wp = Npc_GetNearestWp(hero);
1616
Wld_InsertNpc(G1CP_Test_0010_Npc, wp);
1717
var C_Npc test; test = Hlp_GetNpc(G1CP_Test_0010_Npc);
18-
if (!Hlp_IsValidNpc(test)) {
19-
G1CP_TestsuiteErrorDetail("Failed to insert NPC");
20-
return;
21-
};
18+
G1CP_Testsuite_Assert(Hlp_IsValidNpc(test), TRUE);
2219

2320
// Update state dynamically (to make sure it exists)
2421
MEM_WriteInt(_@(test.bodymass)+8, symbId);

src/Ninja/G1CP/Content/Tests/test0012.d

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ func void G1CP_Test_0012() {
1717
var string wp; wp = Npc_GetNearestWp(hero);
1818
Wld_InsertNpc(G1CP_Test_0012_Npc, wp);
1919
var C_Npc test; test = Hlp_GetNpc(G1CP_Test_0012_Npc);
20-
if (!Hlp_IsValidNpc(test)) {
21-
G1CP_TestsuiteErrorDetail("Failed to insert NPC");
22-
return;
23-
};
20+
G1CP_Testsuite_Assert(Hlp_IsValidNpc(test), TRUE);
2421

2522
// Give bow and arrow to player
2623
CreateInvItem(hero, bowId);

src/Ninja/G1CP/Content/Tests/test0015.d

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,22 @@ func int G1CP_Test_0015() {
99
var int funcId; funcId = G1CP_Testsuite_CheckDialogFunc("DIA_Horatio_HelpSTR_LEARN_NOW");
1010
G1CP_Testsuite_CheckPassed();
1111

12-
// Define possibly missing symbols locally
1312
const int ATR_STRENGTH = 4;
1413

15-
// Check status of the test
16-
var int passed; passed = TRUE;
17-
18-
// Backup values
1914
var int strengthBak; strengthBak = hero.attribute[ATR_STRENGTH];
15+
if (final()) {
16+
hero.attribute[ATR_STRENGTH] = strengthBak;
17+
};
2018

21-
// First pass: strength < 100
19+
// Strength should increase when strength < 100
2220
hero.attribute[ATR_STRENGTH] = 10;
2321
G1CP_Testsuite_Call(funcId, 0, 0, TRUE);
24-
if (hero.attribute[ATR_STRENGTH] <= 10) {
25-
G1CP_TestsuiteErrorDetail("Strength was not increased when below 100");
26-
passed = FALSE;
27-
};
22+
G1CP_Testsuite_AssertGt(hero.attribute[ATR_STRENGTH], 10);
2823

29-
// Second pass: strength > 100
24+
// Strength should not decrease when strength > 100
3025
hero.attribute[ATR_STRENGTH] = 1000;
3126
G1CP_Testsuite_Call(funcId, 0, 0, TRUE);
32-
if (hero.attribute[ATR_STRENGTH] < 1000) {
33-
G1CP_TestsuiteErrorDetail("Strength was decreased when above 100");
34-
passed = FALSE;
35-
};
36-
37-
// Restore original strength
38-
hero.attribute[ATR_STRENGTH] = strengthBak;
27+
G1CP_Testsuite_AssertGe(hero.attribute[ATR_STRENGTH], 1000);
3928

40-
// At last
41-
return passed;
29+
return TRUE;
4230
};

src/Ninja/G1CP/Content/Tests/test0016.d

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,35 @@
66
*
77
* Expected behavior: The condition functions will return FALSE.
88
*/
9-
func int G1CP_Test_0016_RunDialog(var string dialogConditionName, var string infoName) {
9+
func int G1CP_Test_0016() {
1010
var C_Npc npc; npc = G1CP_Testsuite_FindNpc("Grd_212_Torwache");
11-
var int funcId; funcId = G1CP_Testsuite_CheckDialogConditionFunc(dialogConditionName);
12-
var int infoId; infoId = G1CP_Testsuite_CheckInfo(infoName);
11+
var int func1Id; func1Id = G1CP_Testsuite_CheckDialogConditionFunc("Info_Thorus_Give1000Ore_Condition");
12+
var int func2Id; func2Id = G1CP_Testsuite_CheckDialogConditionFunc("Info_Thorus_LetterForMages_Condition");
13+
var int info1Id; info1Id = G1CP_Testsuite_CheckInfo("Info_Thorus_BribeGuard");
14+
var int info2Id; info2Id = G1CP_Testsuite_CheckInfo("Info_Thorus_EnterCastle");
1315
var int aiVarId; aiVarId = G1CP_Testsuite_CheckIntConst("AIV_PASSGATE");
1416
G1CP_Testsuite_CheckPassed();
1517

16-
// Backup values
1718
var int aiVarBak; aiVarBak = G1CP_NpcGetAiVarI(npc, aiVarId, 0);
18-
var int toldBak; toldBak = Npc_KnowsInfo(hero, infoId);
19+
var int told1Bak; told1Bak = Npc_KnowsInfo(hero, info1Id);
20+
var int told2Bak; told2Bak = Npc_KnowsInfo(hero, info2Id);
21+
if (final()) {
22+
G1CP_NpcSetAiVarI(npc, aiVarId, aiVarBak);
23+
G1CP_SetInfoToldI(info1Id, told1Bak);
24+
G1CP_SetInfoToldI(info2Id, told2Bak);
25+
};
1926

20-
// Set new values
27+
// First dialog
2128
G1CP_NpcSetAiVarI(npc, aiVarId, TRUE);
22-
G1CP_SetInfoTold(infoName, TRUE);
29+
G1CP_SetInfoToldI(info1Id, TRUE);
30+
G1CP_Testsuite_Call(func1Id, 0, 0, FALSE);
31+
G1CP_Testsuite_Assert(MEM_PopIntResult(), FALSE);
2332

24-
// Call dialog condition function
25-
G1CP_Testsuite_Call(funcId, 0, 0, FALSE);
26-
var int ret; ret = MEM_PopIntResult();
27-
28-
// Restore values
29-
G1CP_NpcSetAiVarI(npc, aiVarId, aiVarBak);
30-
G1CP_SetInfoTold(infoName, toldBak);
31-
32-
// Check return value
33-
if (ret) {
34-
G1CP_TestsuiteErrorDetailSSS("Dialog condition '", dialogConditionName, "' failed");
35-
return FALSE;
36-
};
33+
// Second dialog
34+
G1CP_NpcSetAiVarI(npc, aiVarId, TRUE);
35+
G1CP_SetInfoToldI(info2Id, TRUE);
36+
G1CP_Testsuite_Call(func2Id, 0, 0, FALSE);
37+
G1CP_Testsuite_Assert(MEM_PopIntResult(), FALSE);
3738

3839
return TRUE;
3940
};
40-
func int G1CP_Test_0016() {
41-
var int passed; passed = FALSE;
42-
43-
// First dialog
44-
passed += G1CP_Test_0016_RunDialog("Info_Thorus_Give1000Ore_Condition", "Info_Thorus_BribeGuard");
45-
passed += G1CP_Test_0016_RunDialog("Info_Thorus_LetterForMages_Condition", "Info_Thorus_EnterCastle");
46-
47-
return (passed == 2);
48-
};

src/Ninja/G1CP/Content/Tests/test0017.d

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,15 @@ func int G1CP_Test_0017() {
99
var int funcId; funcId = G1CP_Testsuite_CheckDialogConditionFunc("Info_Jackal_Hello_Condition");
1010
G1CP_Testsuite_CheckPassed();
1111

12-
// Backup values
1312
var int guildBak; guildBak = Npc_GetTrueGuild(hero);
13+
if (final()) {
14+
Npc_SetTrueGuild(hero, guildBak);
15+
};
1416

15-
// Set new values
1617
Npc_SetTrueGuild(hero, 4); // Random guild
1718

18-
// Call dialog condition function
1919
G1CP_Testsuite_Call(funcId, 0, 0, FALSE);
20-
var int ret; ret = MEM_PopIntResult();
21-
22-
// Restore values
23-
Npc_SetTrueGuild(hero, guildBak);
20+
G1CP_Testsuite_Assert(MEM_PopIntResult(), FALSE);
2421

25-
// Check return value
26-
if (ret) {
27-
G1CP_TestsuiteErrorDetail("Dialog condition failed");
28-
return FALSE;
29-
} else {
30-
return TRUE;
31-
};
22+
return TRUE;
3223
};

src/Ninja/G1CP/Content/Tests/test0018.d

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,15 @@ func int G1CP_Test_0018() {
99
var int funcId; funcId = G1CP_Testsuite_CheckDialogConditionFunc("Info_Bloodwyn_Hello_Condition");
1010
G1CP_Testsuite_CheckPassed();
1111

12-
// Backup values
1312
var int guildBak; guildBak = Npc_GetTrueGuild(hero);
13+
if (final()) {
14+
Npc_SetTrueGuild(hero, guildBak);
15+
};
1416

15-
// Set new values
1617
Npc_SetTrueGuild(hero, 4); // Random guild
1718

18-
// Call dialog condition function
1919
G1CP_Testsuite_Call(funcId, 0, 0, FALSE);
20-
var int ret; ret = MEM_PopIntResult();
21-
22-
// Restore values
23-
Npc_SetTrueGuild(hero, guildBak);
20+
G1CP_Testsuite_Assert(MEM_PopIntResult(), FALSE);
2421

25-
// Check return value
26-
if (ret) {
27-
G1CP_TestsuiteErrorDetail("Dialog condition failed");
28-
return FALSE;
29-
} else {
30-
return TRUE;
31-
};
22+
return TRUE;
3223
};

src/Ninja/G1CP/Content/Tests/test0019.d

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,21 @@ func int G1CP_Test_0019() {
1212
var int chptrId; chptrId = G1CP_Testsuite_CheckIntVar("Kapitel");
1313
G1CP_Testsuite_CheckPassed();
1414

15-
// Backup values
1615
var int chapterBak; chapterBak = G1CP_GetIntVarI(chptrId, 0, 0);
1716
var int guildBak; guildBak = Npc_GetTrueGuild(hero);
1817
var int toldBak; toldBak = Npc_KnowsInfo(hero, infoId);
18+
if (final()) {
19+
G1CP_SetIntVarI(chptrId, 0, chapterBak);
20+
Npc_SetTrueGuild(hero, guildBak);
21+
G1CP_SetInfoToldI(infoId, toldBak);
22+
};
1923

20-
// Set new values
2124
G1CP_SetIntVarI(chptrId, 0, 4);
2225
Npc_SetTrueGuild(hero, GIL_NONE);
2326
G1CP_SetInfoToldI(infoId, TRUE);
2427

25-
// Call dialog condition function
2628
G1CP_Testsuite_Call(funcId, 0, 0, FALSE);
27-
var int ret; ret = MEM_PopIntResult();
28-
29-
// Restore values
30-
G1CP_SetIntVarI(chptrId, 0, chapterBak);
31-
Npc_SetTrueGuild(hero, guildBak);
32-
G1CP_SetInfoToldI(infoId, toldBak);
29+
G1CP_Testsuite_Assert(MEM_PopIntResult(), FALSE);
3330

34-
// Check return value
35-
if (ret) {
36-
G1CP_TestsuiteErrorDetail("Dialog condition failed");
37-
return FALSE;
38-
} else {
39-
return TRUE;
40-
};
31+
return TRUE;
4132
};

src/Ninja/G1CP/Content/Tests/test0020.d

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,15 @@ func int G1CP_Test_0020() {
1212
var int beerId; beerId = G1CP_Testsuite_CheckItem("ItFoBeer");
1313
G1CP_Testsuite_CheckPassed();
1414

15-
// Remember the number of beers the player has before
15+
var int r;
1616
CreateInvItem(hero, beerId); // Have at least one (to see if the number decreases)
1717
var int beersBefore; beersBefore = Npc_HasItems(hero, beerId);
18+
if (final()) {
19+
G1CP_Testsuite_NpcSetInvItemAmount(hero, beerId, beersBefore-1);
20+
};
1821

19-
// Just run the dialog and see what happens
2022
G1CP_Testsuite_Call(funcId, npc, hero, TRUE);
23+
G1CP_Testsuite_Assert(Npc_HasItems(hero, beerId), beersBefore+1);
2124

22-
// Check how many beers the player has now
23-
var int beersAfter; beersAfter = Npc_HasItems(hero, beerId);
24-
25-
// Revert to the previous number
26-
if (beersAfter < beersBefore-1) {
27-
CreateInvItems(hero, beerId, (beersBefore-1) - beersAfter);
28-
} else if (beersAfter > beersBefore-1) {
29-
Npc_RemoveInvItems(hero, beerId, beersAfter - (beersBefore-1));
30-
};
31-
32-
// Confirm that the fix worked
33-
if (beersAfter == beersBefore) {
34-
G1CP_TestsuiteErrorDetail("The hero did not receive a beer");
35-
return FALSE;
36-
} else if (beersAfter > beersBefore+1) {
37-
G1CP_TestsuiteErrorDetailSIS("The hero received ", beersAfter - (beersBefore+1), " beers too many");
38-
return FALSE;
39-
} else if (beersAfter < beersBefore) {
40-
G1CP_TestsuiteErrorDetailSIS("The hero lost ", beersBefore - beersAfter, " beers");
41-
return FALSE;
42-
} else { // (beersAfter == beersBefore+1)
43-
return TRUE;
44-
};
25+
return TRUE;
4526
};

0 commit comments

Comments
 (0)