testGame.c - OpenLearning
// blackbox testing

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "Game.h"

#define DEFAULT_DISCIPLINES {STUDENT_BQN, STUDENT_MMONEY, STUDENT_MJ,  \
    STUDENT_MMONEY, STUDENT_MJ, STUDENT_BPS, STUDENT_MTV, 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 NUMBER_OF_TILES 19

void runAllTests (void);

void testNewGame (void); //Nick
void testDisposeGame (void); //Darren
void testMakeAction (void); //Amelia
void testThrowDice (void); //Jesse
void testGetDiscipline (void); //Sabrina
void testGetDiceValue (void); //Nick
void testGetMostARCs (void); //Darren
void testGetMostPublications (void); //Amelia
void testGetTurnNumber (void); //Jesse
void testGetWhoseTurn (void); //Sabrina
void testGetCampus (void); //Nick
void testGetARC (void); //Darren
void testIsLegalAction (void); //Amelia
void testGetKPIpoints (void); //Jesse
void testGetARCs (void); //Sabrina
void testGetGO8s (void); //Nick
void testGetCampuses (void); //Darren
void testGetIPs (void); //Amelia
void testGetPublications (void); //Jesse
void testGetStudents (void); //Sabrina
void testGetExchangeRate (void); //Nick

int main (int argc, char *argv[]) {
    runAllTests ();
    return EXIT_SUCCESS;
}

void runAllTests (void) {
    // Uncomment your when your tests are completed

    testNewGame (); //Nick
    testMakeAction (); //Amelia  
    testThrowDice (); //Jesse
    testGetDiscipline (); //Sabrina
    testGetDiceValue (); //Nick
    testGetMostARCs (); //Darren
    testGetMostPublications (); //Amelia
    testGetTurnNumber (); //Jesse
    testGetWhoseTurn (); //Sabrina
    testGetCampus (); //Nick
    testGetARC (); //Darren
    testIsLegalAction (); //Amelia
    testGetKPIpoints (); //Jesse
    testGetARCs (); //Sabrina
    testGetGO8s (); //Nick
    testGetCampuses (); //Darren
    testGetIPs (); //Amelia
    testGetPublications (); //Jesse
    testGetStudents (); //Sabrina
    testGetExchangeRate (); //Nick

    printf ("All test passed. You are Awesome!!!\n");
}


void testNewGame (void) {
    int disciplines[NUMBER_OF_TILES] = DEFAULT_DISCIPLINES;
    int dice[NUMBER_OF_TILES] = DEFAULT_DICE;
    
    Game testGame = newGame (disciplines, dice);

    assert (testGame != NULL);

    //test that each player has 2 campuses at the start of the game
    assert (getCampuses(testGame, UNI_A) == 2);
    assert (getCampuses(testGame, UNI_B) == 2);
    assert (getCampuses(testGame, UNI_C) == 2);

    //test that each player has 0 Publications at the start of the game
    assert (getPublications(testGame, UNI_A) == 0);
    assert (getPublications(testGame, UNI_B) == 0);
    assert (getPublications(testGame, UNI_C) == 0);

    //test that each player has 0 ARCs at the start of the game
    assert (getARCs(testGame, UNI_A) == 0);
    assert (getARCs(testGame, UNI_B) == 0);
    assert (getARCs(testGame, UNI_C) == 0);

    //test that each player has 0 IPs at the start of the game
    assert (getIPs(testGame, UNI_A) == 0);
    assert (getIPs(testGame, UNI_B) == 0);
    assert (getIPs(testGame, UNI_C) == 0);

    //test that each player has 3 BPS students at the start of the game
    assert (getStudents(testGame, UNI_A, STUDENT_BPS) == 3);
    assert (getStudents(testGame, UNI_B, STUDENT_BPS) == 3);
    assert (getStudents(testGame, UNI_C, STUDENT_BPS) == 3);

    //test that each player has 3 B? students at the start of the game
    assert (getStudents(testGame, UNI_A, STUDENT_BQN) == 3);
    assert (getStudents(testGame, UNI_B, STUDENT_BQN) == 3);
    assert (getStudents(testGame, UNI_C, STUDENT_BQN) == 3);

    //test that each player has 1 MTV student at the start of the game
    assert (getStudents(testGame, UNI_A, STUDENT_MTV) == 1);
    assert (getStudents(testGame, UNI_B, STUDENT_MTV) == 1);
    assert (getStudents(testGame, UNI_C, STUDENT_MTV) == 1);

    //test that each player has 1 MJ students at the start of the game
    assert (getStudents(testGame, UNI_A, STUDENT_MJ) == 1);
    assert (getStudents(testGame, UNI_B, STUDENT_MJ) == 1);
    assert (getStudents(testGame, UNI_C, STUDENT_MJ) == 1);

    //test that each player has 1 M$ students at the start of the game
    assert (getStudents(testGame, UNI_A, STUDENT_MMONEY) == 1);
    assert (getStudents(testGame, UNI_B, STUDENT_MMONEY) == 1);
    assert (getStudents(testGame, UNI_C, STUDENT_MMONEY) == 1);

    //test that each player has 0 ThD students at the start of the game
    assert (getStudents(testGame, UNI_A, STUDENT_THD) == 0);
    assert (getStudents(testGame, UNI_B, STUDENT_THD) == 0);
    assert (getStudents(testGame, UNI_C, STUDENT_THD) == 0);

    assert (getCampus (testGame, "LB") == UNI_A);
	assert (getCampus (testGame, "RRLRL") == UNI_B);
	assert (getCampus (testGame, "LRLRL") == UNI_C);

}

void testMakeAction (void) {

}

void testThrowDice (void) {

    int disciplines[NUMBER_OF_TILES] = DEFAULT_DISCIPLINES;
    int dice[NUMBER_OF_TILES] = DEFAULT_DICE;
    
    Game testingGame = newGame (disciplines, dice);
    
        // the game starts in turn -1
	assert(getTurnNumber(testingGame) == -1);
	
    //Function throwDice doesnt return anything?
    //We just test if other funtions return the right values when we update the diceScore
	int count = 0;
	while (count < NUMBER_OF_TILES) {
		throwDice (testingGame, dice[count]);
		
		//turn number should have increased
		assert(getTurnNumber (testingGame) == count);		

		count++;
	}
        
    disposeGame (testingGame);
}

void testGetDiscipline (void) {
    int testDisciplines[] = DEFAULT_DISCIPLINES;
    int testDice[] = DEFAULT_DICE;
    Game testingGame = newGame (testDisciplines, testDice);

    assert (getDiscipline (testingGame, 0) == STUDENT_BQN);
    assert (getDiscipline (testingGame, 1) == STUDENT_MMONEY);
    assert (getDiscipline (testingGame, 2) == STUDENT_MJ);
    assert (getDiscipline (testingGame, 3) == STUDENT_MMONEY);
    assert (getDiscipline (testingGame, 4) == STUDENT_MJ);
    assert (getDiscipline (testingGame, 5) == STUDENT_BPS);
    assert (getDiscipline (testingGame, 6) == STUDENT_MTV);
    assert (getDiscipline (testingGame, 7) == STUDENT_MTV);
    assert (getDiscipline (testingGame, 8) == STUDENT_BPS);
    assert (getDiscipline (testingGame, 9) == STUDENT_MTV);
    assert (getDiscipline (testingGame, 10) == STUDENT_BQN);
    assert (getDiscipline (testingGame, 11) == STUDENT_MJ);
    assert (getDiscipline (testingGame, 12) == STUDENT_BQN);
    assert (getDiscipline (testingGame, 13) == STUDENT_THD);
    assert (getDiscipline (testingGame, 14) == STUDENT_MJ);
    assert (getDiscipline (testingGame, 15) == STUDENT_MMONEY);
    assert (getDiscipline (testingGame, 16) == STUDENT_MTV);
    assert (getDiscipline (testingGame, 17) == STUDENT_BQN);
    assert (getDiscipline (testingGame, 18) == STUDENT_BPS);

    disposeGame (testingGame);

    int testDisciplines1[] = {STUDENT_MMONEY, STUDENT_BPS, STUDENT_MJ,
        STUDENT_MJ, STUDENT_MJ, STUDENT_MTV, STUDENT_MTV, STUDENT_THD,
        STUDENT_MTV, STUDENT_MJ, STUDENT_BQN, STUDENT_BQN, STUDENT_BQN,
        STUDENT_MTV, STUDENT_MTV, STUDENT_BPS, STUDENT_BPS, STUDENT_BQN,
        STUDENT_THD};
    Game testingGame1 = newGame (testDisciplines1, testDice);

    assert (getDiscipline (testingGame1, 0) == STUDENT_MMONEY);
    assert (getDiscipline (testingGame1, 1) == STUDENT_BPS);
    assert (getDiscipline (testingGame1, 2) == STUDENT_MJ);
    assert (getDiscipline (testingGame1, 3) == STUDENT_MJ);
    assert (getDiscipline (testingGame1, 4) == STUDENT_MJ);
    assert (getDiscipline (testingGame1, 5) == STUDENT_MTV);
    assert (getDiscipline (testingGame1, 6) == STUDENT_MTV);
    assert (getDiscipline (testingGame1, 7) == STUDENT_THD);
    assert (getDiscipline (testingGame1, 8) == STUDENT_MTV);
    assert (getDiscipline (testingGame1, 9) == STUDENT_MJ);
    assert (getDiscipline (testingGame1, 10) == STUDENT_BQN);
    assert (getDiscipline (testingGame1, 11) == STUDENT_BQN);
    assert (getDiscipline (testingGame1, 12) == STUDENT_BQN);
    assert (getDiscipline (testingGame1, 13) == STUDENT_MTV);
    assert (getDiscipline (testingGame1, 14) == STUDENT_MTV);
    assert (getDiscipline (testingGame1, 15) == STUDENT_BPS);
    assert (getDiscipline (testingGame1, 16) == STUDENT_BPS);
    assert (getDiscipline (testingGame1, 17) == STUDENT_BQN);
    assert (getDiscipline (testingGame1, 18) == STUDENT_THD);

    disposeGame (testingGame1);
}

void testGetDiceValue (void) {
	
	int testDisciplines[] = DEFAULT_DISCIPLINES;
    int testDice[] = DEFAULT_DICE;
	
    Game testgame = newGame (testDisciplines, testDice);

    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);

    disposeGame (testgame);

}

void testGetMostARCs (void) { //darren
    int disciplines[NUMBER_OF_TILES] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
        1,1,1};
    int dice[NUMBER_OF_TILES] = {8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8};
    //int leader = 0;
    Game testingGame = newGame (disciplines, dice);
    assert (getMostARCs(testingGame) == NO_ONE);
    int counter = 0 ;
    while (counter < 100){
        throwDice(testingGame, 8);
        counter ++;
    } //now we have 100 of each
    disposeGame(testingGame);
    // return leader;
}

void testGetMostPublications (void) {
    
    //Setting up test Game
    int disciplines[NUMBER_OF_TILES] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
        1,1,1}; 
    int dice[NUMBER_OF_TILES] = {7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
    Game testingGame = newGame (disciplines, dice);

    // Making sure noone is in control at the start
    assert (getMostPublications (testingGame) == NO_ONE);

    // you need to give uniA and uniB enough resources to get a
    // publication, or else they won't be able to.

    // Give UNIA a publication (Technically an illegal move)
    if (getWhoseTurn (testingGame) == UNI_A) {
        // need to create an action type
        // action getPublication = {OBTAIN_PUBLICATION};
        // then correctly use make action - has the below prototype
        // void makeAction (Game g, action a)
        // i.e. makeAction (testingGame, getPublication);
        action a;
        a.actionCode = OBTAIN_PUBLICATION;
        makeAction (testingGame, a);
        // Test that UNIA is in control
        assert (getMostPublications (testingGame) == UNI_A);
    }
    


    // Give UNIB 2 publications
    if (getWhoseTurn (testingGame) == UNI_B) {
        // make similar changes as above
        action a;
        a.actionCode = OBTAIN_PUBLICATION;
        makeAction (testingGame, a);
        makeAction (testingGame, a);
        // Make sure UNIB is now in control
        assert (getMostPublications (testingGame) == UNI_B);
    }
    

    disposeGame (testingGame);
    
}

void testGetTurnNumber (void) {
    int disciplines[NUMBER_OF_TILES] = DEFAULT_DISCIPLINES;
    int dice[NUMBER_OF_TILES] = DEFAULT_DICE;
    
    Game testingGame = newGame (disciplines, dice);

	assert(getTurnNumber(testingGame) == -1);
	
	int count = 0;
	while (count < NUMBER_OF_TILES) {
		throwDice (testingGame, dice[count]);
		
		//turn number should have increased
		assert(getTurnNumber (testingGame) == count);		
			
		count++;
	}
	
    disposeGame (testingGame);
}

void testGetWhoseTurn (void) {
    int testDisciplines[NUMBER_OF_TILES] = DEFAULT_DISCIPLINES;
    int testDice[NUMBER_OF_TILES] = DEFAULT_DICE;

    Game testingGame = newGame (testDisciplines, testDice);

    assert (getWhoseTurn (testingGame) == NO_ONE);

    int count = 0;
    int dice = 0;
    while (count < 100) {
        dice = rand () % 11 + 2;
        throwDice (testingGame, dice);
        int turnNumber = getTurnNumber (testingGame);

        if (turnNumber == 0) {
            assert (getWhoseTurn (testingGame) == UNI_A);
        } else if (turnNumber == 1) {
            assert (getWhoseTurn (testingGame) == UNI_B);
        } else if (turnNumber == 2) {
            assert (getWhoseTurn (testingGame) == UNI_C);
        }
        count++;
    }

    disposeGame (testingGame);
}

void testGetCampus (void) {

}

void testGetARC (void) {
    // input coOrdinates of the vertex
    int disciplines[NUMBER_OF_TILES] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
        1,1,1};
    int dice[NUMBER_OF_TILES] = {8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8};
    Game testingGame = newGame (disciplines, dice);  

    int count = 0;
    while (count < 180+1) { //using 180 +1 because it will go back to A
        throwDice (testingGame, 8);
        count++;
    };
    assert(getWhoseTurn(testingGame) == UNI_A);
    action a;
    a.actionCode = OBTAIN_ARC;
    strcpy(a.destination, "L");
    makeAction(testingGame, a);
    strcpy(a.destination, "LR");
    makeAction(testingGame, a);
    strcpy(a.destination, "LRL");
    makeAction(testingGame, a);
    strcpy(a.destination, "LRRR");
    assert(getARC(testingGame, "L") == ARC_A);
    assert(getARC(testingGame, "LR") == ARC_A);
    assert(getARC(testingGame, "LRL") == ARC_A);
    assert(getARC(testingGame, "LRRR") == ARC_A);

    throwDice(testingGame, 8);
    strcpy(a.destination, "RRLRL");
    makeAction(testingGame, a);
    strcpy(a.destination, "RRLRLL");
    makeAction(testingGame, a);
    strcpy(a.destination, "RRLRLLL");

    assert(getARC(testingGame, "RRLRL") == ARC_B);
    assert(getARC(testingGame, "RRLRLL") == ARC_B);
    assert(getARC(testingGame, "RRLRLLL") == ARC_B);

    disposeGame (testingGame);
}

void testIsLegalAction (void) {
    //someone elses test we failed
    action a;
    int disciplines[] = {2,5,3,5,3,1,4,4,1,4,2,3,2,0,3,5,4,2,1};
    int dice[] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};
    Game g = newGame(disciplines, dice);
    throwDice(g, 11);
    a.actionCode = PASS;
    strncpy(a.destination, "", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = 0, a.disciplineTo = 0;
    makeAction(g, a);
    throwDice(g, 8);
    a.actionCode = PASS;
    strncpy(a.destination, "•dêôßp·hÂn·xÃn·ôßp·ôßp·¿·o·", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = -1217458176, a.disciplineTo = 0;
    makeAction(g, a);
    throwDice(g, 5);
    a.actionCode = PASS;
    strncpy(a.destination, "4o·", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = -1219197004, a.disciplineTo = -1217482040;
    makeAction(g, a);
    throwDice(g, 9);
    a.actionCode = OBTAIN_ARC;
    strncpy(a.destination, "R", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = -1217482040, a.disciplineTo = -1217456695;
    isLegalAction(g, a);
    assert (isLegalAction(g, a) == FALSE);

    disposeGame (g);


    //assert(actionCode != OBTAIN_PUBLICATION);
    //assert(actionCode != OBTAIN_IP_PATENT);

   // assert(disciplineFrom  => STUDENT_THD);
    //assert(disciplineFrom  <= STUDENT_MMONEY);

    //assert(disciplineTo  => STUDENT_THD);
    //assert(disciplineTo  <= STUDENT_MMONEY);


    //assert path is always on board 
    //assert vertex is empty
    //assert they have the resources
    //assert they have an arc next to proposed campus
    //assert spot to make a GO8 has a campus on it
    //No actions in terra nullis



    //disposeGame (testingGame);
}

void testGetKPIpoints (void) {

    int disciplines[NUMBER_OF_TILES] = DEFAULT_DISCIPLINES;
    int dice[NUMBER_OF_TILES] = DEFAULT_DICE;
    
    Game testingGame = newGame (disciplines, dice);
	
	//All players should start with 0 KPI points
	
    assert (getKPIpoints (testingGame, UNI_A) == 20);	
    assert (getKPIpoints (testingGame, UNI_B) == 20);	
    assert (getKPIpoints (testingGame, UNI_C) == 20);
	
    disposeGame (testingGame);
}

void testGetARCs (void) {
    // this is the prototype from Game.h
    // int getARCs (Game g, int player);

    // sets up the board
    int disciplines[NUMBER_OF_TILES] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
        1,1,1};
    int dice[NUMBER_OF_TILES] = {7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
    
    Game testingGame = newGame (disciplines, dice);
    
    // asserts everyone has no arcs to start with
    assert (getARCs (testingGame, UNI_A) == 0);
    assert (getARCs (testingGame, UNI_B) == 0);
    assert (getARCs (testingGame, UNI_C) == 0);
    
    // resource farming
    int count = 0;
    while (count < 200) {
        throwDice (testingGame, 7);

        assert (getARCs (testingGame, UNI_A) == 0);
        assert (getARCs (testingGame, UNI_B) == 0);
        assert (getARCs (testingGame, UNI_C) == 0);
        
        count++;
    }

    // building the arcs and testing - LRLRLR... crash case player 1
    int numARCsUNIA = 0;
    action swap = {RETRAIN_STUDENTS, "", STUDENT_BPS, STUDENT_BQN};
    path p = "L";
    char append = 'R';
    action buildARC = {OBTAIN_ARC, {*p}};

    if (isLegalAction (testingGame, swap)) {
        makeAction (testingGame, swap);
    }

    while (isLegalAction (testingGame, buildARC)) { 

        if (isLegalAction (testingGame, swap)) {
            makeAction (testingGame, swap);
        }

        if (getWhoseTurn (testingGame) == UNI_A) {
            makeAction (testingGame, buildARC);
            snprintf (p, sizeof (p), "%s%c", p, append);
            
            if (append == 'R') {
                append = 'L';
            } else {
                append = 'R';
            }
            numARCsUNIA++;
        }

        throwDice (testingGame, 7);

        assert (getARCs (testingGame, UNI_A) == numARCsUNIA);
    }

    // building the arcs and testing - LRLRLR... crash case player 2
    int numARCsUNIB = 0;
    snprintf (p, sizeof (p), "%s", "LRLRLR");
    append = 'R';

    if (isLegalAction (testingGame, swap)) {
        makeAction (testingGame, swap);
    }

    while (isLegalAction (testingGame, buildARC)) { 

        if (isLegalAction (testingGame, swap)) {
            makeAction (testingGame, swap);
        }

        if (getWhoseTurn (testingGame) == UNI_B) {
            makeAction (testingGame, buildARC);
            snprintf (p, sizeof (p), "%s%c", p, append);
            
            if (append == 'R') {
                append = 'L';
            } else {
                append = 'R';
            }
            numARCsUNIB++;
        }

        throwDice (testingGame, 7);

        assert (getARCs (testingGame, UNI_A) == numARCsUNIA);
        assert (getARCs (testingGame, UNI_B) == numARCsUNIB);
    }

    disposeGame (testingGame);
}

void testGetGO8s (void) {

}

void testGetCampuses (void) {
    int disciplines[NUMBER_OF_TILES] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
        1,1,1};
    int dice[NUMBER_OF_TILES] = {8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8};
    
    
    Game testingGame = newGame (disciplines, dice);
    // game start, 2 campuses each
    assert(getCampuses(testingGame, UNI_A) == 2);
    assert(getCampuses(testingGame, UNI_A) == 2);
    assert(getCampuses(testingGame, UNI_A) == 2);
    // return player.numOfCampuses;
    disposeGame (testingGame);
}

void testGetIPs (void) {
    
    int disciplines[NUMBER_OF_TILES] = {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
        3,3,3};
    int dice[NUMBER_OF_TILES] = {6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6};

    Game testingGame = newGame (disciplines, dice);

    // Asserting that there are no IPS at the start of the game
    assert(getIPs (testingGame, UNI_A) == 0); 
    assert(getIPs (testingGame, UNI_B) == 0);
    assert(getIPs (testingGame, UNI_C) == 0);


    // resource farming
    int count = 0;
    while (count < 300) {
        throwDice (testingGame, 6);
 
        assert (getIPs (testingGame, UNI_A) == 0);
        assert (getIPs (testingGame, UNI_B) == 0);
        assert (getIPs (testingGame, UNI_C) == 0);
         
        count++;
    }


    // Case where Uni_A tries to get an IP
    //int UNI_A = 0;
    action swap1 = {RETRAIN_STUDENTS, "", STUDENT_MJ, STUDENT_MTV};
    action swap2 = {RETRAIN_STUDENTS, "", STUDENT_MJ, STUDENT_MMONEY};

    int uni = getWhoseTurn(testingGame);

    int i = 0;
    while (i < 50) {
         // Making some MTV's
            makeAction (testingGame, swap1);
        
        i++;
    }
    
    i = 0;
    while (i < 50) {
          // Making some MMoney's
            makeAction (testingGame, swap2);
        
        i++;
    }

    i = 0;
    while (i < 10) {
        action a;
        a.actionCode =  OBTAIN_IP_PATENT;
        makeAction (testingGame, a);  // hopefully making an ip
        i++;
    }
    
    //Assert player one has one arc
    assert(getIPs(testingGame, uni) == 10); 

    disposeGame (testingGame);
    
}

void testGetPublications (void) {
    int disciplines[NUMBER_OF_TILES] = DEFAULT_DISCIPLINES;
    int dice[NUMBER_OF_TILES] = DEFAULT_DICE;
    
    Game testingGame = newGame (disciplines, dice);
	
	//All players should start with 0 publications
	
    assert (getPublications (testingGame, UNI_A) == 0);	
    assert (getPublications (testingGame, UNI_B) == 0);	
    assert (getPublications (testingGame, UNI_C) == 0);
	

    disposeGame (testingGame);
}

void testGetStudents (void) {
    int testDisciplines[NUMBER_OF_TILES] = DEFAULT_DISCIPLINES;
    int testDice[NUMBER_OF_TILES] = DEFAULT_DICE;
    Game testingGame = newGame (testDisciplines, testDice);

    int BPSforA = 3;
    int BQNforA = 3;
    int MTVforA = 1;
    int MJforA = 1;
    int MMONEYforA = 1;
    int THDforA = 0;

    int BPSforB = 3;
    int BQNforB = 3;
    int MTVforB = 1;
    int MJforB = 1;
    int MMONEYforB = 1;
    int THDforB = 0;

    int BPSforC = 3;
    int BQNforC = 3;
    int MTVforC = 1;
    int MJforC = 1;
    int MMONEYforC = 1;
    int THDforC = 0;

    assert (getStudents (testingGame, UNI_A, STUDENT_BPS) == BPSforA);
    assert (getStudents (testingGame, UNI_A, STUDENT_BQN) == BQNforA);
    assert (getStudents (testingGame, UNI_A, STUDENT_MTV) == MTVforA);
    assert (getStudents (testingGame, UNI_A, STUDENT_MJ) == MJforA);
    assert (getStudents (testingGame, UNI_A, STUDENT_THD) == THDforA);
    assert (getStudents (testingGame, UNI_A, STUDENT_MMONEY)
                                                        == MMONEYforA);
    

    assert (getStudents (testingGame, UNI_B, STUDENT_BPS) == BPSforB);
    assert (getStudents (testingGame, UNI_B, STUDENT_BQN) == BQNforB);
    assert (getStudents (testingGame, UNI_B, STUDENT_MTV) == MTVforB);
    assert (getStudents (testingGame, UNI_B, STUDENT_MJ) == MJforB);
    assert (getStudents (testingGame, UNI_B, STUDENT_THD) == THDforB);
    assert (getStudents (testingGame, UNI_B, STUDENT_MMONEY)
                                                        == MMONEYforB);
    

    assert (getStudents (testingGame, UNI_C, STUDENT_BPS) == BPSforC);
    assert (getStudents (testingGame, UNI_C, STUDENT_BQN) == BQNforC);
    assert (getStudents (testingGame, UNI_C, STUDENT_MTV) == MTVforC);
    assert (getStudents (testingGame, UNI_C, STUDENT_MJ) == MJforC);
    assert (getStudents (testingGame, UNI_C, STUDENT_THD) == THDforC);
    assert (getStudents (testingGame, UNI_C, STUDENT_MMONEY)
                                                        == MMONEYforC);
    

    int turn = getTurnNumber (testingGame);
    int dice = 0;
    while (turn < 100) {
        dice = rand () % 11 + 2;
        throwDice (testingGame, dice);

        if (dice == 5) {
            BPSforB++;
        } else if (dice == 6) {
            MJforA++;
        } else if (dice == 7) {
            THDforA += MMONEYforA + MTVforA;
            MMONEYforA = 0;
            MTVforA = 0;

            THDforB += MMONEYforB + MTVforB;
            MMONEYforB = 0;
            MTVforB = 0;

            THDforC += MMONEYforC + MTVforC;
            MMONEYforC = 0;
            MTVforC = 0;
        } else if (dice == 8) {
            MTVforC++;
            MJforC++;
        } else if (dice == 9) {
            BQNforB++;
        } else if (dice == 11) {
            MTVforA++;        
        }

        assert (getStudents (testingGame, UNI_A, STUDENT_BPS)
                                                        == BPSforA);
        assert (getStudents (testingGame, UNI_A, STUDENT_BQN)
                                                        == BQNforA);
        assert (getStudents (testingGame, UNI_A, STUDENT_MTV)
                                                        == MTVforA);
        assert (getStudents (testingGame, UNI_A, STUDENT_MJ)
                                                        == MJforA);
        assert (getStudents (testingGame, UNI_A, STUDENT_MMONEY)
                                                        == MMONEYforA);
        assert (getStudents (testingGame, UNI_A, STUDENT_THD)
                                                        == THDforA);

        assert (getStudents (testingGame, UNI_B, STUDENT_BPS)
                                                        == BPSforB);
        assert (getStudents (testingGame, UNI_B, STUDENT_BQN)
                                                        == BQNforB);
        assert (getStudents (testingGame, UNI_B, STUDENT_MTV)
                                                        == MTVforB);
        assert (getStudents (testingGame, UNI_B, STUDENT_MJ)
                                                        == MJforB);
        assert (getStudents (testingGame, UNI_B, STUDENT_MMONEY)
                                                        == MMONEYforB);
        assert (getStudents (testingGame, UNI_B, STUDENT_THD)
                                                        == THDforB);

        assert (getStudents (testingGame, UNI_C, STUDENT_BPS)
                                                        == BPSforC);
        assert (getStudents (testingGame, UNI_C, STUDENT_BQN)
                                                        == BQNforC);
        assert (getStudents (testingGame, UNI_C, STUDENT_MTV)
                                                        == MTVforC);
        assert (getStudents (testingGame, UNI_C, STUDENT_MJ)
                                                        == MJforC);
        assert (getStudents (testingGame, UNI_C, STUDENT_MMONEY)
                                                        == MMONEYforC);
        assert (getStudents (testingGame, UNI_C, STUDENT_THD)
                                                        == THDforC);
        
        turn = getTurnNumber (testingGame);
    }

    disposeGame (testingGame);
}

void testGetExchangeRate (void) {
    //someone elses test
    int disciplines[] = {2,5,3,5,3,1,4,4,1,4,2,3,2,0,3,5,4,2,1};
    int dice[] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};
    Game g = newGame(disciplines, dice);

    assert (getExchangeRate(g, UNI_A, 1, 2) == 3);
}

Download file: testGame.c (26.9 KB)

Comments

Chat