Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dienharm finalproject bugfree #86

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f74d59e
Added dienharm project and dominion files
Oct 5, 2019
94f9e6f
Modified the project README file under dienharm/ as required by Assig…
Oct 5, 2019
e1e4481
Refactored cardEffect() with new baron card function.
Oct 13, 2019
5181cf8
Refactoring for minion, ambassador, tribute, and mine card functions.
Oct 13, 2019
709c11f
Added bugs to baron, minion, ambassador, tribute, and mine functions
Oct 13, 2019
a7875bd
Copied original dominion files into FinalProject-Bugs directory
Nov 29, 2019
ef9079c
Moved original dominion code to FinalProject-Bugs/dominion
Nov 30, 2019
b1ccddd
Added individual unit tests for bugs 1-4 and updated makefile
Nov 30, 2019
305cd58
Added BugFree directory and fixed bugs 1-4 in dominion.c
Nov 30, 2019
9b90475
Fixed errors in assert statements for unit tests for bugs 2 and 3
Nov 30, 2019
0b979b9
Corrected error in bug 1 unit test assertions and gainCard() target f…
Nov 30, 2019
6641a65
Copied unit test assertion corrections from dienharm-finalproject-bugs
Nov 30, 2019
a201441
Fixed incorrect test status print messages in unit tests for bugs 2-4.
Nov 30, 2019
cda1169
Added unit test for bugs 7,9,10 and added fixed code to dominion.c
rcelsom Dec 4, 2019
3d28cee
added commands to makefile
rcelsom Dec 4, 2019
dfcd7c7
added commands to makefile
rcelsom Dec 4, 2019
a2b70b8
added commands to makefile
rcelsom Dec 4, 2019
2cc2211
added commands to makefile
rcelsom Dec 4, 2019
ab515f2
added commands to makefile
rcelsom Dec 4, 2019
afac90f
added commands to makefile
rcelsom Dec 4, 2019
0a29212
added commands to makefile
rcelsom Dec 4, 2019
062532f
added commands to makefile
rcelsom Dec 4, 2019
c9d186d
updated makefile
rcelsom Dec 4, 2019
fef770c
updated makefile
rcelsom Dec 4, 2019
24525ea
updated makefile
rcelsom Dec 4, 2019
f7c753a
updated makefile
rcelsom Dec 4, 2019
7120a25
updated makefile
rcelsom Dec 4, 2019
6b3af9c
updated makefile
rcelsom Dec 4, 2019
dc1a9f5
updated makefile
rcelsom Dec 4, 2019
0127333
Merge pull request #2 from elsomr/final-project
MattDienhart Dec 4, 2019
e8fff48
Added unit tests for bugs 5, 6, and 8, removed redundant Makefile.mak…
Dec 4, 2019
a243795
Fixed error in unit test 9
Dec 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions projects/FinalProject-BugFree/dominion/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
CFLAGS= -Wall -fpic -coverage -lm -std=c99

rngs.o: rngs.h rngs.c
gcc -c rngs.c -g $(CFLAGS)

dominion.o: dominion.h dominion.c rngs.o
gcc -c dominion.c -g $(CFLAGS)

playdom: dominion.o playdom.c
gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS)
#To run playdom you need to enter: ./playdom <any integer number> like ./playdom 10*/

testDrawCard: testDrawCard.c dominion.o rngs.o
gcc -o testDrawCard -g testDrawCard.c dominion.o rngs.o $(CFLAGS)

interface.o: interface.h interface.c
gcc -c interface.c -g $(CFLAGS)

runtests: testDrawCard
./testDrawCard &> unittestresult.out
gcov dominion.c >> unittestresult.out
cat dominion.c.gcov >> unittestresult.out


player: player.c interface.o
gcc -o player player.c -g dominion.o rngs.o interface.o $(CFLAGS)

bug1: bug1_unit.c dominion.o
gcc -o bug1 bug1_unit.c dominion.o rngs.o -g $(CFLAGS)

bug2: bug2_unit.c dominion.o
gcc -o bug2 bug2_unit.c dominion.o rngs.o -g $(CFLAGS)

bug3: bug3_unit.c dominion.o
gcc -o bug3 bug3_unit.c dominion.o rngs.o -g $(CFLAGS)

bug4: bug4_unit.c dominion.o
gcc -o bug4 bug4_unit.c dominion.o rngs.o -g $(CFLAGS)

bug5: bug5_unit.c dominion.o
gcc -o bug5 bug5_unit.c dominion.o rngs.o -g $(CFLAGS)

bug6: bug6_unit.c dominion.o
gcc -o bug6 bug6_unit.c dominion.o rngs.o -g $(CFLAGS)

bug7: unitTest7.c dominion.o rngs.o
gcc -o bug7 -g unitTest7.c dominion.o rngs.o $(CFLAGS)

bug8: bug8_unit.c dominion.o
gcc -o bug8 bug8_unit.c dominion.o rngs.o -g $(CFLAGS)

bug9: unitTest9.c dominion.o rngs.o
gcc -o bug9 -g unitTest9.c dominion.o rngs.o $(CFLAGS)

bug10: unitTest10.c dominion.o rngs.o
gcc -o bug10 -g unitTest10.c dominion.o rngs.o $(CFLAGS)


unittestresults: bug1 bug2 bug3 bug4 bug5 bug6 bug7 bug8 bug9 bug10
bug1 &> unittestresults.out
bug2 >> unittestresults.out
bug3 >> unittestresults.out
bug4 >> unittestresults.out
bug5 >> unittestresults.out
bug6 >> unittestresults.out
bug7 >> unittestresults.out
bug8 >> unittestresults.out
bug9 >> unittestresults.out
bug10 >> unittestresults.out
gcov dominion.c -b -f >> unittestresults.out
cat dominion.c.gcov >> unittestresults.out

all: playdom player bug1 bug2 bug3 bug4 bug5 bug6 bug7 bug8 bug9 bug10

clean:
rm -f *.o playdom.exe playdom player player.exe *.gcov *.gcda *.gcno *.so *.out testDrawCard testDrawCard.exe bug1.exe bug1 bug2.exe bug2 bug3.exe bug3 bug4.exe bug4 bug5.exe bug5 bug6.exe bug6 bug7.exe bug7 bug8.exe bug8 bug9.exe bug9 bug10.exe bug10 unittestresults.out
2 changes: 2 additions & 0 deletions projects/FinalProject-BugFree/dominion/READM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run make all #To compile the dominion code
run ./playdom 30 # to run playdom code
70 changes: 70 additions & 0 deletions projects/FinalProject-BugFree/dominion/bug1_unit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// bug1_unit.c
// This program performs unit testing on the cardEffect() function for the
// Mine card per Bug #1.
//
// Author: Matt Dienhart
// Date: 11-29-2019

#include "dominion.h"
#include "dominion_helpers.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// This function behaves like "assert()", but does not cause the program
// to exit if the condition is false. Instead, it prints a message to
// indicate the result of the comparison.
void custom_assert(int condition) {
if (condition) {
printf("PASSED\n");
} else {
printf("FAILED\n");
}

return;
}

int main() {
// set up card array
int k[10] = { adventurer, council_room, feast, gardens, baron,
remodel, smithy, village, mine, great_hall };

// declare the game state
struct gameState G;

printf("Begin testing the mine card within cardEffect():\n");

// set up the game state for testing
int seed = 5; // arbitrary seed for RNG
G.whoseTurn = 0; //player 1 is the current player
int player = G.whoseTurn;
int bonus = 0;

// set up test-specific conditions

// player attempts to trash a copper card and gain a silver card
printf(" -- Testing Bug #1 --\n");
initializeGame(2, k, seed, &G);
G.handCount[player] = 2;
G.hand[player][0] = mine;
G.hand[player][1] = copper;
G.supplyCount[silver] = 1;
G.discardCount[player] = 0;
G.playedCardCount = 0;

cardEffect(mine, copper, silver, 0, &G, 0, &bonus);

// show test result
printf("Checking if Player 1's hand size has decreased by 1: ");
custom_assert(G.handCount[player] == 1);
printf("Checking if Player 1's discard pile has increased by 1: ");
custom_assert(G.discardCount[player] == 1);
printf("Checking if Player 1's discard pile now contains the Mine card: ");
custom_assert(G.discard[player][0] == mine);
printf("Checking if the played cards pile is still empty: ");
custom_assert(G.playedCardCount == 0);

printf("Testing completed.\n");

return 0;
}
69 changes: 69 additions & 0 deletions projects/FinalProject-BugFree/dominion/bug2_unit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// bug2_unit.c
// This program performs unit testing on the cardEffect() function for the
// Mine card per Bug #2.
//
// Author: Matt Dienhart
// Date: 11-29-2019

#include "dominion.h"
#include "dominion_helpers.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// This function behaves like "assert()", but does not cause the program
// to exit if the condition is false. Instead, it prints a message to
// indicate the result of the comparison.
void custom_assert(int condition) {
if (condition) {
printf("PASSED\n");
} else {
printf("FAILED\n");
}

return;
}

int main() {
// set up card array
int k[10] = { adventurer, council_room, feast, gardens, baron,
remodel, smithy, village, mine, great_hall };

// declare the game state
struct gameState G;

printf("Begin testing the mine card within cardEffect():\n");

// set up the game state for testing
int seed = 5; // arbitrary seed for RNG
G.whoseTurn = 0; //player 1 is the current player
int player = G.whoseTurn;
int bonus = 0;

// set up test-specific conditions

// player attempts to trash a copper card and gain a gold card
printf(" -- Testing Bug #2 --\n");
initializeGame(2, k, seed, &G);
G.handCount[player] = 2;
G.hand[player][0] = mine;
G.hand[player][1] = copper;
G.supplyCount[gold] = 1;
G.discardCount[player] = 0;

cardEffect(mine, copper, gold, 0, &G, 0, &bonus);

// show test result
printf("Checking if Player 1's hand size has stayed the same: ");
custom_assert(G.handCount[player] == 2);
printf("Checking if Player 1 still has the Copper card: ");
custom_assert(G.handCount[player] > 0 && G.hand[player][G.handCount[player]-1] == copper);
printf("Checking if there is no change to the supply of Gold cards: ");
custom_assert(G.supplyCount[gold] == 1);
printf("Checking if Player 1's discard pile is still empty: ");
custom_assert(G.discardCount[player] == 0);

printf("Testing completed.\n");

return 0;
}
69 changes: 69 additions & 0 deletions projects/FinalProject-BugFree/dominion/bug3_unit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// bug3_unit.c
// This program performs unit testing on the cardEffect() function for the
// Remodel card per Bug #3.
//
// Author: Matt Dienhart
// Date: 11-29-2019

#include "dominion.h"
#include "dominion_helpers.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// This function behaves like "assert()", but does not cause the program
// to exit if the condition is false. Instead, it prints a message to
// indicate the result of the comparison.
void custom_assert(int condition) {
if (condition) {
printf("PASSED\n");
} else {
printf("FAILED\n");
}

return;
}

int main() {
// set up card array
int k[10] = { adventurer, council_room, feast, gardens, baron,
remodel, smithy, village, mine, great_hall };

// declare the game state
struct gameState G;

printf("Begin testing the remodel card within cardEffect():\n");

// set up the game state for testing
int seed = 5; // arbitrary seed for RNG
G.whoseTurn = 0; //player 1 is the current player
int player = G.whoseTurn;
int bonus = 0;

// set up test-specific conditions

// player attempts to trash an estate card and gain a province card
printf(" -- Testing Bug #3 --\n");
initializeGame(2, k, seed, &G);
G.handCount[player] = 2;
G.hand[player][0] = remodel;
G.hand[player][1] = estate;
G.supplyCount[province] = 2;
G.discardCount[player] = 0;

cardEffect(remodel, estate, province, 0, &G, 0, &bonus);

// show test result
printf("Checking if Player 1's hand size has stayed the same: ");
custom_assert(G.handCount[player] == 2);
printf("Checking if Player 1 still has the Estate card: ");
custom_assert(G.handCount[player] > 0 && G.hand[player][G.handCount[player]-1] == estate);
printf("Checking if there is no change to the supply of Province cards: ");
custom_assert(G.supplyCount[province] == 2);
printf("Checking if Player 1's discard pile is still empty: ");
custom_assert(G.discardCount[player] == 0);

printf("Testing completed.\n");

return 0;
}
69 changes: 69 additions & 0 deletions projects/FinalProject-BugFree/dominion/bug4_unit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// bug4_unit.c
// This program performs unit testing on the isGameOver() function
// when Sea Hag and Treasure Map supplies are empty per Bug #3.
//
// Author: Matt Dienhart
// Date: 11-29-2019

#include "dominion.h"
#include "dominion_helpers.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// This function behaves like "assert()", but does not cause the program
// to exit if the condition is false. Instead, it prints a message to
// indicate the result of the comparison.
void custom_assert(int condition) {
if (condition) {
printf("PASSED\n");
} else {
printf("FAILED\n");
}

return;
}

int main() {
// set up card array
int k[10] = { adventurer, sea_hag, treasure_map, gardens, baron,
remodel, smithy, village, mine, great_hall };

// declare the game state
struct gameState G;

printf("Begin testing the isGameOver() function:\n");

// set up the game state for testing
int seed = 5; // arbitrary seed for RNG


// set up test-specific conditions

// player attempts to trash an estate card and gain a province card
printf(" -- Testing Bug #4 --\n");
initializeGame(2, k, seed, &G);

// set supply piles for all cards to 3
int i;
for (i=curse; i<=treasure_map; i++) {
G.supplyCount[i] = 3;
}

// set supply count for Sea Hag, Treasure Map, and Adventurer to 0
G.supplyCount[sea_hag] = 0;
G.supplyCount[treasure_map] = 0;
G.supplyCount[adventurer] = 0;

// call the function to be tested
int result;
result = isGameOver(&G);

// show test result
printf("Checking if the game has ended due to supply depletion: ");
custom_assert(result == 1);

printf("Testing completed.\n");

return 0;
}
Loading