void testNewGame (void) { printf ("Now testing 'newGame':\n"); printf ("1) First turn number == -1\n"); prinft ("2) Regions initialised correctly (displine and dice values correct)\n"); // check makes a game without crashing int disciplines[NUM_REGIONS]; int dice [NUM_REGIONS]; int testCase = 0; while (testCase < TEST_NEW_GAME_CASES) { int regionID = 0; while (regionID < NUM_REGIONS) { int studentVal = randomValue(0, NUM_STUDENT_TYPES); int student = 0; if (studentVal == VAL_BQN) { student = BQN; } else if (studentVal == VAL_MMON) { student = MMON; } else if (studentVal == VAL_MJ) { student = MJ; } else if (studentVal == VAL_BPS) { student = BPS; } else if (studentVal == VAL_MTV) { student = MTV; } else { student = THD; } disciplines[regionID] = student; dice[regionID] = randomValue(MIN_DICE_VAL, MAX_DICE_VAL); regionID++; } Game g = newGame (disciplines, dice); assert (getTurnNumber(g) == -1); regionID = 0; while (regionID < NUM_REGIONS) { assert (getDiscipline(g, regionID) == disciplines[regionID]); assert (getDiceValue(g, regionID) == dice[regionID]); regionID++; } disposeGame (g); testCase++; } printf ("Passed\n"); }
void addStudents (Game g, int regionID) { int i = 0; int x = 0; int y = 0; int z = 0; int curPlayer = UNI_A; int curVertex = g->gameBoard.campus[x][y][z]; int *regionSurround = getRegion (g, x, y, z); while (x < COORD) { while (y < COORD) { while (z < COORD) { curVertex = g->gameBoard.campus[x][y][z]; if (curVertex > 0) { regionSurround = getRegion (g, x, y, z); i = 0; while (i < 3) { if (regionSurround[i] == regionID) { if (curVertex >= 1 && curVertex <= 3) { curPlayer = curVertex; g->uni[curPlayer].numStudents[getDiscipline(g, regionID)]++; } else { curPlayer = curVertex - 3; g->uni[curPlayer].numStudents[getDiscipline(g, regionID)]+=2; } } i++; } } z++; } z = 0; y++; } y = 0; x++; } free (regionSurround); }
void testInitialisation (Game testGame){ action testAction; printf ("Testing initial conditions.\n"); printf ("Testing getDiscipline.\n"); assert (getDiscipline(testGame, 0) == STUDENT_BQN); assert (getDiscipline(testGame, 1) == STUDENT_MMONEY); assert (getDiscipline(testGame, 2) == STUDENT_MJ); assert (getDiscipline(testGame, 3) == STUDENT_MMONEY); assert (getDiscipline(testGame, 4) == STUDENT_MJ); assert (getDiscipline(testGame, 5) == STUDENT_BPS); assert (getDiscipline(testGame, 6) == STUDENT_MTV); assert (getDiscipline(testGame, 7) == STUDENT_MTV); assert (getDiscipline(testGame, 8) == STUDENT_BPS); assert (getDiscipline(testGame, 9) == STUDENT_MTV); assert (getDiscipline(testGame, 10) == STUDENT_BQN); assert (getDiscipline(testGame, 11) == STUDENT_MJ); assert (getDiscipline(testGame, 12) == STUDENT_BQN); assert (getDiscipline(testGame, 13) == STUDENT_THD); assert (getDiscipline(testGame, 14) == STUDENT_MJ); assert (getDiscipline(testGame, 15) == STUDENT_MMONEY); assert (getDiscipline(testGame, 16) == STUDENT_MTV); assert (getDiscipline(testGame, 17) == STUDENT_BQN); assert (getDiscipline(testGame, 18) == STUDENT_BPS); printf ("Testing getDiceValue\n"); assert (getDiceValue(testGame, 0) == 9); assert (getDiceValue(testGame, 1) == 10); assert (getDiceValue(testGame, 2) == 8); assert (getDiceValue(testGame, 3) == 12); assert (getDiceValue(testGame, 4) == 6); assert (getDiceValue(testGame, 5) == 5); assert (getDiceValue(testGame, 6) == 3); assert (getDiceValue(testGame, 7) == 11); assert (getDiceValue(testGame, 8) == 3); assert (getDiceValue(testGame, 9) == 11); assert (getDiceValue(testGame, 10) == 4); assert (getDiceValue(testGame, 11) == 6); assert (getDiceValue(testGame, 12) == 4); assert (getDiceValue(testGame, 13) == 7); assert (getDiceValue(testGame, 14) == 9); assert (getDiceValue(testGame, 15) == 2); assert (getDiceValue(testGame, 16) == 8); assert (getDiceValue(testGame, 17) == 10); assert (getDiceValue(testGame, 18) == 5); printf ("Testing Most ARC\n"); assert (getMostARCs(testGame) == NO_ONE); printf ("Testing most publications\n"); assert (getMostPublications (testGame) == NO_ONE); printf ("Testing turnNumber\n"); assert (getTurnNumber(testGame) == -1); printf ("Testing whoseTurn.\n"); assert (getWhoseTurn (testGame) == NO_ONE); printf("Testing getCampus (content of given vertex) \n"); assert (getCampus (testGame, "RLBLR") == VACANT_VERTEX); assert (getCampus (testGame, "RLBBR") == VACANT_VERTEX); assert (getCampus (testGame, "LRL") == VACANT_VERTEX); printf("Testing getARC (content of given edge) \n"); assert (getARC (testGame, "L") == VACANT_ARC); assert (getARC (testGame, "R") == VACANT_ARC); assert (getARC (testGame, "LR") == VACANT_ARC); assert (getARC (testGame, "RR") == VACANT_ARC); printf ("Testing isLegalAction\n"); assert (isLegalAction (testGame, testAction) == FALSE); printf ("Testing KPI points\n"); assert (getKPIpoints (testGame, UNI_A) == 0); assert (getKPIpoints (testGame, UNI_B) == 0); assert (getKPIpoints (testGame, UNI_C) == 0); printf ("Testing getARCs (number of ARC grants) \n"); assert (getARCs (testGame, UNI_A) == 0); assert (getARCs (testGame, UNI_B) == 0); assert (getARCs (testGame, UNI_C) == 0); printf ("Testing GO8 (number of G08 campus) \n"); assert (getGO8s (testGame, UNI_A) == 0); assert (getGO8s (testGame, UNI_B) == 0); assert (getGO8s (testGame, UNI_C) == 0); printf ("Testing getCampuses (number of normal campuses)\n"); assert (getCampuses (testGame, UNI_A) == 2); assert (getCampuses (testGame, UNI_B) == 2); assert (getCampuses (testGame, UNI_C) == 2); printf ("Testing IPs (number of IP patent) \n"); assert (getIPs(testGame, UNI_A) == 0); assert (getIPs(testGame, UNI_B) == 0); assert (getIPs(testGame, UNI_C) == 0); printf ("Testing publications\n"); assert (getPublications(testGame, UNI_A) == 0); assert (getPublications(testGame, UNI_B) == 0); assert (getPublications(testGame, UNI_C) == 0); printf ("Testing number of students of UNI_A\n"); 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_MTV) == 1); assert (getStudents (testGame, UNI_A, STUDENT_MMONEY) == 1); printf ("Testing number of students of UNI_B\n"); 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_MTV) == 1); assert (getStudents (testGame, UNI_B, STUDENT_MMONEY) == 1); printf ("Testing number of students of UNI_C\n"); 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_MTV) == 1); assert (getStudents (testGame, UNI_C, STUDENT_MMONEY) == 1); printf ("Testing getExchangeRate for UNI_A\n"); assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_BPS) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_BQN) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_MJ) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_MTV) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_MMONEY) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_MMONEY) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_BPS) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_BQN) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_MJ) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_MTV) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_MTV) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_BPS) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_BQN) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_MJ) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_MMONEY) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_BQN) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_BPS) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_MJ) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_MTV) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_MMONEY) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_MJ) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_BPS) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_BQN) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_MTV) == 3); assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_MMONEY) == 3); printf ("All tests passed\n\n"); }
//got these numbers off of the board void testgetDiscipline (void) { assert (getDiscipline(g, 0) == STUDENT_BQN); assert (getDiscipline(g, 1) == STUDENT_MMONEY); assert (getDiscipline(g, 2) == STUDENT_MJ); assert (getDiscipline(g, 3) == STUDENT_MMONEY); assert (getDiscipline(g, 4) == STUDENT_MJ); assert (getDiscipline(g, 5) == STUDENT_BPS); assert (getDiscipline(g, 6) == STUDENT_MTV); assert (getDiscipline(g, 7) == STUDENT_MTV); assert (getDiscipline(g, 8) == STUDENT_BPS); assert (getDiscipline(g, 9) == STUDENT_MTV); assert (getDiscipline(g, 10) == STUDENT_BQN); assert (getDiscipline(g, 11) == STUDENT_MJ); assert (getDiscipline(g, 12) == STUDENT_BQN); assert (getDiscipline(g, 13) == STUDENT_THD); assert (getDiscipline(g, 14) == STUDENT_MJ); assert (getDiscipline(g, 15) == STUDENT_MMONEY); assert (getDiscipline(g, 16) == STUDENT_MTV); assert (getDiscipline(g, 17) == STUDENT_BQN); assert (getDiscipline(g, 18) == STUDENT_BPS); }
int main(int argc, char *argv[]) { int discipline[6] = {STUDENT_THD, STUDENT_BPS, STUDENT_BQN, STUDENT_MJ, STUDENT_MTV, STUDENT_MMONEY} int dice[6] = {1, 2, 3, 4, 5, 6} newGame(*discipline[], dice[]); //Tests void makeAction action a; a.actionCode = BUILD_CAMPUS; a.destination = L; a.disciplineFrom = STUDENT_BPS; a.disciplineTo = STUDENT_MTV; assert(a.actionCode == BUILD_CAMPUS); assert(a.destination == L); assert(a.disciplineFrom == STUDENT_BPS); assert(a.discplineTo == STUDENT_MTV); //Tests void throwDice assert(diceScore >= 2 && diceScore <= 12); //Tests int getDiscipline assert (getDiscipline(Game g, 0) == STUDENT_BGN); assert (getDiscipline(Game g, 1) == STUDENT_MMONEY); assert (getDiscipline(Game g, 2) == STUDENT_MJ); assert (getDiscipline(Game g, 3) == STUDENT_MMONEY); assert (getDiscipline(Game g, 4) == STUDENT_MJ); assert (getDiscipline(Game g, 5) == STUDENT_BPS); assert (getDiscipline(Game g, 6) == STUDENT_MTV); assert (getDiscipline(Game g, 7) == STUDENT_MTV); assert (getDiscipline(Game g, 8) == STUDENT_BPS); assert (getDiscipline(Game g, 9) == STUDENT_MTV); assert (getDiscipline(Game g, 10) == STUDENT_BQN); assert (getDiscipline(Game g, 11) == STUDENT_MJ); assert (getDiscipline(Game g, 12) == STUDENT_BQN); assert (getDiscipline(Game g, 13) == STUDENT_THD); assert (getDiscipline(Game g, 14) == STUDENT_MJ); assert (getDiscipline(Game g, 15) == STUDENT_MMONEY); assert (getDiscipline(Game g, 16) == STUDENT_MTV); assert (getDiscipline(Game g, 17) == STUDENT_BQN); assert (getDiscipline(Game g, 18) == STUDENT_BPS); //Tests int getDiceValue assert (getDiceValue(Game g, 0) == 9); assert (getDiceVale(Game g, 1) == 10); assert (getDicevalue(Game g, 2) == 8); assert (getDiceValue(Game g, 3) == 12); assert (getDiceValue(Game g, 4) == 6); assert (getDiceValue(Game g, 5) == 5); assert (getDiceValue(Game g, 6) == 3); assert (getDiceValue(Game g, 7) == 11); assert (getDiceValue(Game g, 8) == 3); assert (getDiceValue(Game g, 9) == 11); assert (getDiceValue(Game g, 10) == 4); assert (getDiceValue(Game g, 11) == 6); assert (getDiceValue(Game g, 12) == 4); assert (getDiceValue(Game g, 13) == 7); assert (getDiceValue(Game g, 14) == 9); assert (getDiceValue(Game g, 15) == 2); assert (getDiceValue(Game g, 16) == 8); assert (getDiceValue(Game g, 17) == 10); assert (getDiceValue(Game g, 18) == 5); //Tests int getMostARCs (Game g) assert(getMostARCs(newGame) == NO_ONE); //Tests int getMostPublications (Game g) assert(getMostPublications(newGame) == No_ONE); //Tests int getTurnNumber (Game g) assert(getTurnNumber(newGame) == -1); //Tests int getWhoseTurn (Game g) assert(getWhoseTurn(newGame) == NO_ONE); //Tests int getCampus(Game g, path pathToVertex) assert (getCampus(Game g, path {\0}) == CAMPUS_A); assert (getCampus(Game g, path {‘R’, ‘R’, ‘L’, ‘R’, ‘L’,\0}) == CAMPUS_B); assert (getCampus(Game g, path {‘L’, ‘R’, ‘L’, ‘R’, ‘L’, ‘R’,\0}) == CAMPUS_C); //Tests int getARC(Game g, path pathToEdge) assert (getARC(Game g, path {\0}) == VACANT_ARC); assert (getARC(Game g, path {‘R’,\0}) == ARC A); assert (getARC(Game g, path {‘R’, ‘R’, ‘L’, ‘R’, ‘L’, ‘L’,\0}) == ARC B); assert (getARC(Game g, path {‘L’, ‘R’, ‘L’, ‘R’, ‘L’, ‘R’, ‘B’,\0}) == ARC C); //Tests int isLegalAction (Game g, action a) if (actionCode != PASS) { assert (actionCode >= 0 && actionCode <= 7); if (actionCode == BUILD_CAMPUS) { assert ((sizeof(destination)-1)/4 >= 0 && (sizeof(destination) - 1)/4 <= PATH_LIMIT); assert (getCampus(Game g, path destination) == VACANT_VERTEX); assert (getArc(Game g, (destination + 'B')) == ARC_A && getCampus(Game g, (destination + 'L')) == VACANT_VERTEX && getCampus(Game g, (destination + 'R')) == VACANT_VERTEX); assert (students[STUDENT_BPS] >= 1); assert (students[STUDENTS_BQN] >= 1); assert (students[STUDENTS_MJ] >= 1); assert (students[STUDENTS_MTV] >= 1); } if (actionCode == BUILD_GO8) { assert ((sizeof(destination)-1)/4 >= 0 && (sizeof(destination) - 1)/4 <= PATH_LIMIT); assert (getCampus(Game g, path destination) == CAMPUS_A); assert (students[STUDENTS_MJ] >= 2); assert (students[STUDENTS_MMONEY] >= 3); } if (actionCode == OBTAIN_ARC) { assert ((sizeof(destination)-1)/4 >= 0 && (sizeof(destination) - 1)/4 <= PATH_LIMIT); assert (getArc(Game g, (destination + 'B')) == ARC_A); } if (actionCode == START_SPINNOFF) { assert (students[STUDENT_MJ] >= 1); assert (students[STUDENT_MTV] >= 1); assert (students[STUDENT_MMONEY] >= 1); } if (actionCode == RETRAIN_STUDENTS) { assert (students[disciplineFrom] >= getExchangeRate(Game g, int player, int disciplineFrom, int disciplineTo)); assert (disciplineFrom != STUDENT_THD); assert (disciplineTo != STUDENT_THD); }
//Sample out testing simple things void testInitialState(Game g){ printf("Testing initialState!\n"); int disciplines[] = DEFAULT_DISCIPLINES; int dice[] = DEFAULT_DICE; //Check each region produces correct disciplines int regionID = 0; while (regionID < NUM_REGIONS) { assert(getDiscipline(g,regionID) == disciplines[regionID]); regionID ++; } //Check what dice value produces students in the specified region regionID = 0; while (regionID < NUM_REGIONS) { assert(getDiceValue(g,regionID) == dice[regionID]); regionID ++; } assert(getMostARCs(g) == NO_ONE); assert(getMostPublications(g) == NO_ONE); assert(getTurnNumber(g) == -1); assert(getWhoseTurn(g) == NO_ONE); //Check individual uni values int uni = UNI_A; while(uni <= UNI_C){ //Check Uni's exchange rates int testStudentFrom = STUDENT_BPS; int testStudentTo = STUDENT_BPS; while (testStudentFrom <= STUDENT_MMONEY) { while (testStudentTo <= STUDENT_MMONEY) { if (testStudentFrom != testStudentTo) { assert(getExchangeRate (g, uni, testStudentFrom, testStudentTo) == 3); } testStudentTo ++; } testStudentFrom ++; testStudentTo = STUDENT_BPS; } assert(getKPIpoints(g,uni) == 20); assert(getARCs(g,uni) == 0); assert(getGO8s(g,uni) == 0); assert(getCampuses(g,uni) == 2); assert(getPublications(g,uni) == 0); assert(getIPs(g,uni) == 0); //Check initial student values assert(getStudents(g,uni,STUDENT_THD)==0); assert(getStudents(g,uni,STUDENT_BPS)==3); assert(getStudents(g,uni,STUDENT_BQN)==3); assert(getStudents(g,uni,STUDENT_MJ)==1); assert(getStudents(g,uni,STUDENT_MTV)==1); assert(getStudents(g,uni,STUDENT_MMONEY)==1); uni++; } //Test isLegalAction at Terra Nullis action passAction; action CampusAction; action GO8Action; action ARCAction; action spinoffAction; action publicationAction; action patentAction; action retrainAction; passAction.actionCode = PASS; CampusAction.actionCode = BUILD_CAMPUS; GO8Action.actionCode = BUILD_GO8; ARCAction.actionCode = OBTAIN_ARC; spinoffAction.actionCode = START_SPINOFF; publicationAction.actionCode = OBTAIN_PUBLICATION; patentAction.actionCode = OBTAIN_IP_PATENT; retrainAction.actionCode = RETRAIN_STUDENTS; assert(isLegalAction(g, passAction) == FALSE); assert(isLegalAction(g, CampusAction) == FALSE); assert (isLegalAction(g, GO8Action) == FALSE); assert(isLegalAction(g, ARCAction) == FALSE); assert(isLegalAction(g, spinoffAction) == FALSE); assert(isLegalAction(g, publicationAction) == FALSE); assert(isLegalAction(g, patentAction) == FALSE); assert(isLegalAction(g, retrainAction) == FALSE); printf ("All initialState tests passed!\n"); }
// Returns the disciplines of surrounding hexes of a vertices trio getVertexHexes(Game g, int vertexId) { int results[3]; int resultI = 0; results[0] = -1; results[1] = -1; results[2] = -1; int rowsForColumns[NUM_COLUMNS] = ROWS_FOR_COLUMN; int startLeftColumns[NUM_COLUMNS] = START_LEFT_COLUMN; int startRightColumns[NUM_COLUMNS] = START_RIGHT_COLUMN; int region = 0; int column = 0; while (column < NUM_COLUMNS && resultI <= 2) { int row = 0; while (row < rowsForColumns[column]) { int left = startLeftColumns[column] + (row * 2); int right = startRightColumns[column] + (row * 2); if (vertexId - left <= 2 && vertexId - left >= 0) { results[resultI] = region; resultI++; } if (vertexId - right <= 2 && vertexId - right >= 0) { results[resultI] = region; resultI++; } region++; row++; } column++; } trio resultTrio; int allDisciplines[NUM_REGIONS]; int i = 0; while (i < NUM_REGIONS) { allDisciplines[i] = getDiscipline(g, i); i++; } // printf("Hexes for %d: ", vertexId); if (results[0] >= 0) { resultTrio.a = allDisciplines[results[0]]; // printf("%d, ", resultTrio.a); } else { resultTrio.a = -1; } if (results[1] >= 0) { resultTrio.b = allDisciplines[results[1]]; // printf("%d, ", resultTrio.b); } else { resultTrio.b = -1; } if (results[2] >= 0) { resultTrio.c = allDisciplines[results[2]]; // printf("%d, ", resultTrio.c); } else { resultTrio.c = -1; } // printf("\n"); return resultTrio; }