From cf3d337fec048af89512e4b0bd49a201718cac47 Mon Sep 17 00:00:00 2001 From: kaya123 Date: Sun, 19 May 2019 20:21:15 +1000 Subject: [PATCH 1/2] Added testGetCampus and started on testGetStudents --- testGame.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 106 insertions(+), 15 deletions(-) diff --git a/testGame.c b/testGame.c index 94f67f1..59577be 100644 --- a/testGame.c +++ b/testGame.c @@ -36,10 +36,34 @@ int main(int argc, char *argv[]) { testGetDiscipline (); testGetDiceValue (); + /*Checklist: + + **** DONE Game newGame (int discipline[], int dice[]); Tested in every function + **** DONE void disposeGame (Game g); Tested in every function + ** void makeAction (Game g, action a); Tested in every function. Needs more tests. + **** void throwDice (Game g, int diceScore); testThrowDice (); + **** int getDiscipline (Game g, int regionID); testGetDiscipline (); + **** int getDiceValue (Game g, int regionID); testGetDiceValue (); + **** int getMostARCs (Game g); testGetMostARCs (); + **** int getMostPublications (Game g); testgetMostPublications (); + **** int getTurnNumber (Game g); testThrowDice (); + **** int getWhoseTurn (Game g); testThrowDice (); + **** int getCampus(Game g, path pathToVertex); + int getARC(Game g, path pathToEdge); + int isLegalAction (Game g, action a); + **** int getARCs (Game g, int player);testGetMostARCs (); + int getGO8s (Game g, int player); + **** int getCampuses (Game g, int player); + int getIPs (Game g, int player); + **** int getPublications (Game g, int player); + int getStudents (Game g, int player, int discipline); + int getExchangeRate (Game g, int player, + int disciplineFrom, int disciplineTo); + */ + //clean up: keep your memory beautiful //disposeGame(testGame); - //TODO: all tests passed message :) printf("All tests passed!!!\nYou are awesome!"); @@ -52,8 +76,8 @@ int main(int argc, char *argv[]) { // This also tests "getWhoseTurn" and "getTurnNumber" void testThrowDice () { - int disciplines[] = DEFAULT_DISCIPLINES; - int dice[] = DEFAULT_DICE; + int disciplines[NUM_REGIONS] = DEFAULT_DISCIPLINES; + int dice[NUM_REGIONS] = DEFAULT_DICE; Game testGame = newGame(disciplines, dice); assert (getWhoseTurn (testGame) == 0); @@ -75,8 +99,8 @@ void testThrowDice () { } void testGetWhoseTurn () { - int disciplines[] = DEFAULT_DISCIPLINES; - int dice[] = DEFAULT_DICE; + int disciplines[NUM_REGIONS] = DEFAULT_DISCIPLINES; + int dice[NUM_REGIONS] = DEFAULT_DICE; Game testGame = newGame(disciplines, dice); assert (getWhoseTurn (testGame) == NO_ONE); @@ -92,13 +116,14 @@ void testGetWhoseTurn () { disposeGame (testGame); } +// Also tests getARCs void testGetMostARCs () { - int disciplines[] = DEFAULT_DISCIPLINES; - int dice[] = DEFAULT_DICE; + int disciplines[NUM_REGIONS] = DEFAULT_DISCIPLINES; + int dice[NUM_REGIONS] = DEFAULT_DICE; Game testGame = newGame(disciplines, dice); assert (getMostARCs (testGame) == NO_ONE); - assert (getARCs (testGame, UNI_A) == NO_ONE); + assert (getARCs (testGame, UNI_A) == 0); action createARC; createARC.actionCode = OBTAIN_ARC; @@ -107,6 +132,7 @@ void testGetMostARCs () { makeAction (testGame, createARC); int currentMostARCs = getWhoseTurn (testGame); assert (getMostARCs (testGame) == getWhoseTurn (testGame)); + assert (getARCs (testGame, getWhoseTurn (testGame)) == 1); throwDice (testGame, 3); @@ -116,6 +142,8 @@ void testGetMostARCs () { makeAction (testGame, createARC); int currentMostARCs = getWhoseTurn (testGame); assert (getMostARCs (testGame) == currentMostARCs); + assert (getARCs (testGame, currentMostARCs) == 2); + throwDice (testGame, 2); @@ -124,24 +152,29 @@ void testGetMostARCs () { createARC.path = {'RL'}; makeAction (testGame, createARC); assert (getMostARCs (testGame) == currentMostARCs); + assert (getARCs (testGame, getWhoseTurn (testGame)) == 2); createARC.path = {'RLR'}; makeAction (testGame, createARC); - assert (getMostARCs (testGame) == getWhoseTurn (testGame)); + assert (getMostARCs (testGame) == getWhoseTurn (testGame)); + assert (getARCs (testGame, getWhoseTurn (testGame)) == 3); printf("getMostARCs works\n"); disposeGame (testGame); } +// Also tests getPublications void testgetMostPublications () { Game testGame = newGame(disciplines, dice); assert (getMostPublications (testGame) == NO_ONE); + assert (getPublications (testGame, UNI_A) == 0); action obtainPublication; obtainPublication.actionCode = OBTAIN_PUBLICATION; makeAction (testGame, obtainPublication); assert (getMostPublications (testGame) == getWhoseTurn (testGame)); + assert (getPublications (testGame, getWhoseTurn (testGame)) == 1); throwDice (testGame, 3); @@ -149,22 +182,25 @@ void testgetMostPublications () { makeAction (testGame, obtainPublication); int currentMostARCs = getWhoseTurn (testGame); assert (getMostPublications (testGame) == currentMostARCs); + assert (getPublications (testGame, currentMostARCs) == 2); throwDice (testGame, 2); makeAction (testGame, obtainPublication); makeAction (testGame, obtainPublication); assert (getMostPublications (testGame) == currentMostARCs); + assert (getPublications (testGame, getWhoseTurn (testGame)) == 2); makeAction (testGame, obtainPublication); - assert (getMostPublications (testGame) == getWhoseTurn (testGame)); + assert (getMostPublications (testGame) == getWhoseTurn (testGame)); + assert (getPublications (testGame, getWhoseTurn (testGame)) == 3); disposeGame (testGame); } void testGetDiscipline () { - int disciplines[] = DEFAULT_DISCIPLINES; - int dice[] = DEFAULT_DICE; + int disciplines[NUM_REGIONS] = DEFAULT_DISCIPLINES; + int dice[NUM_REGIONS] = DEFAULT_DICE; Game testGame = newGame(disciplines, dice); assert (getDiscipline (testGame, 0) == DEFAULT_DISCIPLINES[0]); @@ -219,8 +255,8 @@ void testGetDiscipline () { void testGetDiceValue () { - int disciplines[] = DEFAULT_DISCIPLINES; - int dice[] = DEFAULT_DICE; + int disciplines[NUM_REGIONS] = DEFAULT_DISCIPLINES; + int dice[NUM_REGIONS] = DEFAULT_DICE; Game testGame = newGame(disciplines, dice); assert (getDiceValue (testGame, 0) == DEFAULT_DICE[0]); @@ -273,6 +309,61 @@ void testGetDiceValue () { } -void testGetCampus(Game g, path pathToVertex) { +// This also tests getCampuses +void testGetCampus () { + int disciplines[NUM_REGIONS] = DEFAULT_DISCIPLINES; + int dice[NUM_REGIONS] = DEFAULT_DICE; + Game testGame = newGame(disciplines, dice); + + path currentPoint = "R"; + assert (getCampus (testGame, currentPoint) == VACANT_VERTEX); + assert (GetCampuses (testGame, UNI_A) == 2); + + action createCampus; + createCampus.actionCode = OBTAIN_CAMPUS; + createCampus.path = "R"; + makeAction (createCampus); + int currentTurn = getWhoseTurn (testGame); + assert (getCampus (testGame, currentPoint) == currentTurn); + assert (GetCampuses (testGame, currentTurn) == 3); + + currentPoint = "L"; + assert (getCampus (testGame, currentPoint) == VACANT_VERTEX); + + throwDice (testGame, 8); + + currentPoint = "R"; + assert (getCampus (testGame, currentPoint) == currentTurn); + assert (GetCampuses (testGame, getWhoseTurn (testGame)) == 1); + + + createCampus.path = "RL"; + makeAction (createCampus); + currentTurn = getWhoseTurn (testGame); + assert (getCampus (testGame, currentPoint) == currentTurn); + assert (GetCampuses (testGame, currentTurn) == 2); + printf("getMostARCs works\n"); + + disposeGame (testGame); +} + +void testGetStudents () { + int disciplines[NUM_REGIONS] = DEFAULT_DISCIPLINES; + int dice[NUM_REGIONS] = DEFAULT_DICE; + Game testGame = newGame(disciplines, dice); + + assert (getStudents (testGame, UNI_A, STUDENT_THD) == 0); + assert (getStudents (testGame, UNI_A, STUDENT_BPS) == 3); + assert (getStudents (testGame, UNI_A, STUDENT_BQN) == 3); + assert (getStudents (testGame, UNI_A, STUDENT_MJ) == 1); + assert (getStudents (testGame, UNI_A, STUDENT_MT) == 1); + assert (getStudents (testGame, UNI_A, STUDENT_MTV) == 1); + assert (getStudents (testGame, UNI_A, STUDENT_MMONEY) == 1); + + throwDice (testGame, 12); + + + + disposeGame (testGame); } From 3b67ca200beb1a9dbc9da1357b5ada2c6cde924e Mon Sep 17 00:00:00 2001 From: kaya123 Date: Fri, 24 May 2019 08:10:25 +1000 Subject: [PATCH 2/2] added fill resources and updated testStudents --- testGame.c | 166 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 138 insertions(+), 28 deletions(-) diff --git a/testGame.c b/testGame.c index 59577be..7ed3b5e 100644 --- a/testGame.c +++ b/testGame.c @@ -9,14 +9,18 @@ STUDENT_MTV, STUDENT_BPS,STUDENT_MTV, STUDENT_BQN, \ STUDENT_MJ, STUDENT_BQN, STUDENT_THD, STUDENT_MJ, \ STUDENT_MMONEY, STUDENT_MTV, STUDENT_BQN, STUDENT_BPS} -#define DEFAULT_DICE {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5} +#define DEFAULT_DICE {9,10,8, \ + 12,6,5,3, \ + 11,3,11,4, \ + 6,4,7,9, \ + 2,8,10,5} #define TEST_DISCIPLINES {STUDENT_BQN, STUDENT_BPS, STUDENT_MMONEY, \ STUDENT_MJ, STUDENT_MTV, STUDENT_MMONEY, STUDENT_BPS, \ - STUDENT_MJ, STUDENT_BPS, STUDENT_MTV, STUDENT_BQN, \ + STUDENT_MJ, STUDENT_BPS, STUDENT_THD, STUDENT_BQN, \ STUDENT_MJ, STUDENT_BQN, STUDENT_BQN, STUDENT_MJ, \ - STUDENT_MMONEY, STUDENT_MTV, STUDENT_THD, STUDENT_MT} + STUDENT_MMONEY, STUDENT_MTV, STUDENT_MTV, STUDENT_MT} #define TEST_DICE {2,3,3,4,4,5,5,6,6,7,8,8,9,9,10,10,11,11,12} void testThrowDice(); @@ -56,9 +60,9 @@ int main(int argc, char *argv[]) { **** int getCampuses (Game g, int player); int getIPs (Game g, int player); **** int getPublications (Game g, int player); - int getStudents (Game g, int player, int discipline); - int getExchangeRate (Game g, int player, - int disciplineFrom, int disciplineTo); + int getStudents (Game g, int player, int discipline); KAYA + int getExchangeRate (Game g, int player, RUBY + int disciplineFrom, int disciplineTo); */ //clean up: keep your memory beautiful @@ -73,7 +77,7 @@ int main(int argc, char *argv[]) { // void testMakeAction () { // } - + // This also tests "getWhoseTurn" and "getTurnNumber" void testThrowDice () { int disciplines[NUM_REGIONS] = DEFAULT_DISCIPLINES; @@ -229,26 +233,10 @@ void testGetDiscipline () { dice[] = TEST_DICE; Game testGame2 = newGame(disciplines, dice); - assert (getDiscipline (testGame2, 0) == DEFAULT_DISCIPLINES[0]); - assert (getDiscipline (testGame2, 1) == DEFAULT_DISCIPLINES[1]); - assert (getDiscipline (testGame2, 2) == DEFAULT_DISCIPLINES[2]); - assert (getDiscipline (testGame2, 3) == DEFAULT_DISCIPLINES[3]); - assert (getDiscipline (testGame2, 4) == DEFAULT_DISCIPLINES[4]); - assert (getDiscipline (testGame2, 5) == DEFAULT_DISCIPLINES[5]); - assert (getDiscipline (testGame2, 6) == DEFAULT_DISCIPLINES[6]); - assert (getDiscipline (testGame2, 7) == DEFAULT_DISCIPLINES[7]); - assert (getDiscipline (testGame2, 9) == DEFAULT_DISCIPLINES[9]); - assert (getDiscipline (testGame2, 10) == DEFAULT_DISCIPLINES[10]); - assert (getDiscipline (testGame2, 11) == DEFAULT_DISCIPLINES[11]); - assert (getDiscipline (testGame2, 12) == DEFAULT_DISCIPLINES[12]); - assert (getDiscipline (testGame2, 13) == DEFAULT_DISCIPLINES[13]); - assert (getDiscipline (testGame2, 14) == DEFAULT_DISCIPLINES[14]); - assert (getDiscipline (testGame2, 15) == DEFAULT_DISCIPLINES[15]); - assert (getDiscipline (testGame2, 16) == DEFAULT_DISCIPLINES[16]); - assert (getDiscipline (testGame2, 17) == DEFAULT_DISCIPLINES[17]); - assert (getDiscipline (testGame2, 18) == DEFAULT_DISCIPLINES[18]); - assert (getDiscipline (testGame2, 19) == DEFAULT_DISCIPLINES[19]); - + while (i < 20) { + assert (getDiscipline (testGame2, i) == DEFAULT_DISCIPLINES[i]); + i ++; + } disposeGame (testGame2); } @@ -361,9 +349,131 @@ void testGetStudents () { assert (getStudents (testGame, UNI_A, STUDENT_MTV) == 1); assert (getStudents (testGame, UNI_A, STUDENT_MMONEY) == 1); - throwDice (testGame, 12); + assert (getStudents (testGame, UNI_B, STUDENT_THD) == 0); + assert (getStudents (testGame, UNI_B, STUDENT_BPS) == 3); + assert (getStudents (testGame, UNI_B, STUDENT_BQN) == 3); + assert (getStudents (testGame, UNI_B, STUDENT_MJ) == 1); + assert (getStudents (testGame, UNI_B, STUDENT_MT) == 1); + assert (getStudents (testGame, UNI_B, STUDENT_MTV) == 1); + assert (getStudents (testGame, UNI_B, STUDENT_MMONEY) == 1); + + assert (getStudents (testGame, UNI_C, STUDENT_THD) == 0); + assert (getStudents (testGame, UNI_C, STUDENT_BPS) == 3); + assert (getStudents (testGame, UNI_C, STUDENT_BQN) == 3); + assert (getStudents (testGame, UNI_C, STUDENT_MJ) == 1); + assert (getStudents (testGame, UNI_C, STUDENT_MT) == 1); + assert (getStudents (testGame, UNI_C, STUDENT_MTV) == 1); + assert (getStudents (testGame, UNI_C, STUDENT_MMONEY) == 1); + + throwDice (testGame, 11); + + assert (getStudents (testGame, UNI_A, STUDENT_THD) == 0); + assert (getStudents (testGame, UNI_A, STUDENT_BPS) == 3); + assert (getStudents (testGame, UNI_A, STUDENT_BQN) == 3); + assert (getStudents (testGame, UNI_A, STUDENT_MJ) == 1); + assert (getStudents (testGame, UNI_A, STUDENT_MT) == 1); + assert (getStudents (testGame, UNI_A, STUDENT_MTV) == 3); + assert (getStudents (testGame, UNI_A, STUDENT_MMONEY) == 1); + + assert (getStudents (testGame, UNI_B, STUDENT_THD) == 0); + assert (getStudents (testGame, UNI_B, STUDENT_BPS) == 3); + assert (getStudents (testGame, UNI_B, STUDENT_BQN) == 3); + assert (getStudents (testGame, UNI_B, STUDENT_MJ) == 1); + assert (getStudents (testGame, UNI_B, STUDENT_MT) == 1); + assert (getStudents (testGame, UNI_B, STUDENT_MTV) == 1); + assert (getStudents (testGame, UNI_B, STUDENT_MMONEY) == 1); + + assert (getStudents (testGame, UNI_C, STUDENT_THD) == 0); + assert (getStudents (testGame, UNI_C, STUDENT_BPS) == 3); + assert (getStudents (testGame, UNI_C, STUDENT_BQN) == 3); + assert (getStudents (testGame, UNI_C, STUDENT_MJ) == 1); + assert (getStudents (testGame, UNI_C, STUDENT_MT) == 1); + assert (getStudents (testGame, UNI_C, STUDENT_MTV) == 1); + assert (getStudents (testGame, UNI_C, STUDENT_MMONEY) == 1); + + while (getWhoseTurn (testGame) != UNI_B) { + throwDice (testGame, 12); + } + + assert (getWhoseTurn (testGame) != UNI_B); + + action createARC; + createARC.actionCode = OBTAIN_ARC; + createARC.path = {'LLRLRR'}; + makeAction (createARC); + + createARC.path = {'LLRLRRL'}; + makeAction (createARC); + + action createCampus; + createCampus.actionCode = OBTAIN_CAMPUS; + createCampus.path = {'LLRLRRL'} + makeAction (createCampus); + + assert (getCampuses (testGame, UNI_B) == 3); + assert (getARCs (testGame, UNI_B) == 2); + + assert (getStudents (testGame, UNI_A, STUDENT_THD) == 0); + assert (getStudents (testGame, UNI_A, STUDENT_BPS) == 3); + assert (getStudents (testGame, UNI_A, STUDENT_BQN) == 3); + assert (getStudents (testGame, UNI_A, STUDENT_MJ) == 2); + assert (getStudents (testGame, UNI_A, STUDENT_MT) == 1); + assert (getStudents (testGame, UNI_A, STUDENT_MTV) == 3); + assert (getStudents (testGame, UNI_A, STUDENT_MMONEY) == 1); + + assert (getStudents (testGame, UNI_B, STUDENT_THD) == 0); + assert (getStudents (testGame, UNI_B, STUDENT_BPS) == 0); + assert (getStudents (testGame, UNI_B, STUDENT_BQN) == 0); + assert (getStudents (testGame, UNI_B, STUDENT_MJ) == 0); + assert (getStudents (testGame, UNI_B, STUDENT_MT) == 0); + assert (getStudents (testGame, UNI_B, STUDENT_MTV) == 1); + assert (getStudents (testGame, UNI_B, STUDENT_MMONEY) == 1); + assert (getStudents (testGame, UNI_C, STUDENT_THD) == 0); + assert (getStudents (testGame, UNI_C, STUDENT_BPS) == 3); + assert (getStudents (testGame, UNI_C, STUDENT_BQN) == 3); + assert (getStudents (testGame, UNI_C, STUDENT_MJ) == 1); + assert (getStudents (testGame, UNI_C, STUDENT_MT) == 1); + assert (getStudents (testGame, UNI_C, STUDENT_MTV) == 1); + assert (getStudents (testGame, UNI_C, STUDENT_MMONEY) == 1); + throwDice (testGame, 6); + + assert (getStudents (testGame, UNI_A, STUDENT_THD) == 0); + assert (getStudents (testGame, UNI_A, STUDENT_BPS) == 3); + assert (getStudents (testGame, UNI_A, STUDENT_BQN) == 3); + assert (getStudents (testGame, UNI_A, STUDENT_MJ) == 2); + assert (getStudents (testGame, UNI_A, STUDENT_MT) == 1); + assert (getStudents (testGame, UNI_A, STUDENT_MTV) == 3); + assert (getStudents (testGame, UNI_A, STUDENT_MMONEY) == 1); + + assert (getStudents (testGame, UNI_B, STUDENT_THD) == 0); + assert (getStudents (testGame, UNI_B, STUDENT_BPS) == 0); + assert (getStudents (testGame, UNI_B, STUDENT_BQN) == 0); + assert (getStudents (testGame, UNI_B, STUDENT_MJ) == 1); + assert (getStudents (testGame, UNI_B, STUDENT_MT) == 0); + assert (getStudents (testGame, UNI_B, STUDENT_MTV) == 1); + assert (getStudents (testGame, UNI_B, STUDENT_MMONEY) == 1); + + assert (getStudents (testGame, UNI_C, STUDENT_THD) == 0); + assert (getStudents (testGame, UNI_C, STUDENT_BPS) == 3); + assert (getStudents (testGame, UNI_C, STUDENT_BQN) == 3); + assert (getStudents (testGame, UNI_C, STUDENT_MJ) == 1); + assert (getStudents (testGame, UNI_C, STUDENT_MT) == 1); + assert (getStudents (testGame, UNI_C, STUDENT_MTV) == 1); + assert (getStudents (testGame, UNI_C, STUDENT_MMONEY) == 1); disposeGame (testGame); } + +void fillResources (Game testGame) { + while (i <= 12) { + if (i != 7) { + while (j < 20) { + throwDice (i); + j ++; + } + } + i ++; + } +}