Beispiel #1
0
int teacher_main (double purchases, FILE *outfile)
{
	double discount_percent = 0.1, discount_money = 0.0, discount_total = 0.0, sales_tax = 0.0, total = 0.0;
	
	print_receipt (outfile, "Total Purchases = ", purchases);

	// look at discount
	discount_percent = determine_discount (purchases);
	discount_money = calculate_discount (purchases, discount_percent);
	discount_total = calculate_discount_total (purchases, discount_money);
	// Print discount to receipt
	if (discount_percent == 0.1)
	{
		print_receipt (outfile, "Teachers Discount (10%) = ", discount_money);
		print_receipt (outfile, "Discounted Total = ", discount_total);
	}
	else
	{
		print_receipt (outfile, "Teachers Discount (12%) = ", discount_money);
		print_receipt (outfile, "Discounted Total = ", discount_total);
	}

	// calculate sales tax and print to receipt
	sales_tax = calculate_sales_tax (discount_total);
	print_receipt (outfile, "Sales Tax (5%) = ", sales_tax);

	// calculate total and print to receipt
	total = calculate_total (discount_total, sales_tax);
	print_receipt (outfile, "Total = ", total);
	
	// teacher receipt created!
	return 0;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    float start = timeit();

    int ways = 0;
    int idx = 0;

    while (total[idx] <= limit && (idx != CAP)) {

        total[idx] += currency[idx];
        int sum = calculate_total();

        if (sum < limit)
            idx = 0;
        else {
            if (sum == limit)
                ways++;
            total[idx] = 0;
            idx++;
        } 
    }

    float stop = timeit();

    printf("Answer: %d\n", ways);
    printf("Time: %f\n", stop - start);

    return 0;
}
Beispiel #3
0
void Solution::print_solution(){
	std::cout << "Values = ";

	for (int i=0,l=values.size();i<l;++i){
		std::cout << values[i] << " ";
	}

	std::cout << std::endl << "Satisfied clauses = " << calculate_total() << std::endl;
}
Beispiel #4
0
int normal_main (double purchases, FILE *outfile)
{
	double sales_tax = 0.0, total = 0.0;

	print_receipt (outfile, "Total Purchases = ", purchases);

	// calculate sales tax and print to receipt
	sales_tax = calculate_sales_tax (purchases);
	print_receipt (outfile, "Sales Tax (5%) = ", sales_tax);

	// calculate total and print to receipt
	total = calculate_total (purchases, sales_tax);
	print_receipt (outfile, "Total = ", total);

	// Normal receipt created!
	return 0;
}
Beispiel #5
0
static int run_all_test_suites(/*@notnull@*/ test_runner * runner)
/*@globals
	fileSystem,
	internalState
@*/
/*@modifies
	fileSystem,
	internalState,

	runner,
	runner->buffer,
	runner->suite_number,
	runner->suites->suite,
	runner->stats
@*/
{

	const char * summary1;
	const char * summary2;

	printf("Running all the tests...\n\n");

	for(runner->suite_number = 0; runner->suite_number < runner->suites->count; runner->suite_number++){

		/*@-boundsread@*/
		test_suite * suite = runner->suites->suite[runner->suite_number];
		/*@=boundsread@*/

		run_test_suite(runner, suite);

		if(!suite->is_requirement){

			switch(suite->status){

				case STATUS_PASSED:
					runner->stats.suites.passed++;
					/*@switchbreak@*/ break;

				case STATUS_WARNING:
					runner->stats.suites.warnings++;
					/*@switchbreak@*/ break;

				default: /* STATUS_FAILED */
					runner->stats.suites.failed++;
			}

			runner->stats.tests.passed		+= suite->stats.passed;
			runner->stats.tests.warnings	+= suite->stats.warnings;
			runner->stats.tests.failed		+= suite->stats.failed;
		}
	}

	calculate_total(&runner->stats.requirements);
	calculate_total(&runner->stats.tests);
	calculate_total(&runner->stats.suites);

	/* delete temporary files */
	(void)remove(runner->out);
	(void)remove(runner->err);

	if(runner->report != NULL){

		printf("\n\nGenerating report...\n");

		generate_report(runner);

		printf("\tTest report created.\n");

		open_report(runner);
	}

	if(runner->stats.suites.failed > 0){
		summary1 = "Some of the tests failed.";
	}else if(runner->stats.suites.warnings > 0){
		summary1 = "Some *non-critical* test didn't pass.";
	}else{
		summary1 = "All tests passed successfully.";
	}

	if(runner->stats.suites.failed == 0 && runner->stats.suites.warnings == 0){
		summary2 = "";
	}else if(runner->stats.requirements.total == 0){
		summary2 = "\n\tPlease verify platform requirements.";
	}else if(runner->stats.requirements.failed > 0 || runner->stats.requirements.warnings > 0){
		summary2 = "\n\tIt could be related to some error on **platform requirements**.";
	}else{
		summary2 = "\n\tPlease report it at: http://code.google.com/p/exceptions4c/";
	}

	printf("\n%s%s\n\n", summary1, summary2);

	return(EXIT_SUCCESS);
}
Beispiel #6
0
static void run_test_suite(test_runner * runner, test_suite * suite)
/*@globals
	fileSystem,
	internalState
@*/
/*@modifies
	fileSystem,
	internalState,

	runner,
	runner->buffer,
	suite
@*/
{

	size_t tests;

	printf("%s %s...\n", (suite->is_requirement ? "Checking" : "Running test suite"), suite->title);

	tests = suite->tests->count;

	suite->stats.passed		= 0;
	suite->stats.warnings	= 0;
	suite->stats.failed		= 0;

	for(runner->test_number = 0; runner->test_number < tests; runner->test_number++){

		/*@-boundsread@*/
		unit_test * test = suite->tests->test[runner->test_number];
		/*@=boundsread@*/

		run_test(runner, test);

		{

			switch(test->status){

				case STATUS_PASSED:
					if(test->is_requirement){
						runner->stats.requirements.passed++;
					}
					if(!test->is_requirement || suite->is_requirement){
						suite->stats.passed++;
					}
					/*@switchbreak@*/ break;

				case STATUS_WARNING:
					if(test->is_requirement){
						runner->stats.requirements.warnings++;
					}
					if(!test->is_requirement || suite->is_requirement){
						suite->stats.warnings++;
					}
					/*@switchbreak@*/ break;

				default: /* STATUS_FAILED */
					if(test->is_requirement){
						runner->stats.requirements.failed++;
					}
					if(!test->is_requirement || suite->is_requirement){
						suite->stats.failed++;
					}
			}
		}
	}

	calculate_total(&suite->stats);

	suite->status = (suite->stats.failed > 0 ? STATUS_FAILED : (suite->stats.warnings > 0 ? STATUS_WARNING : STATUS_PASSED) );
}
Beispiel #7
0
/**
 * Function:  unittest4
 * Inputs:  printVal, seed, results
 * Outputs: none
 * Description: tests getWinners() function in dominion.c
 */
void unitTest4(int printVal, int seed, struct results *result){

	int i, r=0;
	int players[MAX_PLAYERS] = {0};

	struct playerGroup *playGroup = newPlayerGroup();

	// setup the kingdom cards available
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse,
					 sea_hag, tribute, smithy};

	// setup the struct for the control and active Games
	struct gameState *controlGame = newGame();
	struct gameState *activeGame = newGame();

	playGroup->numPlayers = random_number(2, MAX_PLAYERS);
	initializeGame(playGroup->numPlayers, k, seed, controlGame);

	playGroup->playerValues[0]->cardCounts[0] = 23;
	playGroup->playerValues[1]->cardCounts[0] = 46;
	playGroup->playerValues[2]->cardCounts[0] = 75;
	playGroup->playerValues[3]->cardCounts[0] = 66;

	for(i = 0; i < playGroup->numPlayers; i++)
	{
		updateCards(i, playGroup->playerValues[i], controlGame);
	}

	//copy the values from the activeGame into the controlGame
	memcpy(activeGame, controlGame, sizeof(struct gameState));

	// calculate the scores for the players
	for(i = 0; i < MAX_PLAYERS; i++)
	{
		playGroup->playerValues[i]->score = calculate_total(i, controlGame);
	}

	// run the getWinners function
	r = getWinners(players, activeGame);
	assert(r == 0);

	int winningScore = playGroup->playerValues[0]->score;
	int curWinner = 0;
	playGroup->playerValues[0]->winner = 1;

	for(i = 0; i < MAX_PLAYERS; i++)
	{

		if(playGroup->playerValues[i]->score >= winningScore)
		{
			winningScore = playGroup->playerValues[i]->score;
			playGroup->playerValues[curWinner]->winner = 0;
			playGroup->playerValues[i]->winner = 1;
			curWinner = i;
		}

	}

	for(i=0; i < MAX_PLAYERS; i++)
	{
		int j;
		int score = scoreFor(i, activeGame);

		if(!(playGroup->playerValues[i]->winner == players[i]) || !(score == playGroup->playerValues[i]->score))
		{
			printf("TEST: %d, FAIL: Player: %d of %d players\nScore: %d, Expected: %d, Winner Val Returned: %d,"
					" Expected: %d\n",
					result->testNum, i, playGroup->numPlayers, score,
					playGroup->playerValues[i]->score, players[i], playGroup->playerValues[i]->winner);
			result->testsFailed++;
		}
		else
		{
			assert(playGroup->playerValues[i]->winner == players[i]);

			if(PRINTPASS){
				printf("TEST: %d, PASS: Player: %d of %d players\nScore: %d, Expected: %d, Winner Val Returned: %d,"
						" Expected: %d\n",
						result->testNum, i, playGroup->numPlayers, score,
						playGroup->playerValues[i]->score, players[i], playGroup->playerValues[i]->winner);
			}
		}

		if(!(scoreFor(i, activeGame) == playGroup->playerValues[i]->score))
		{
			printf("HAND: ");
			for(j = 0; j < activeGame->handCount[i]; j++)
			{
				printf("%d,", activeGame->hand[i][j]);
			}
			printf("\n");
			printf("DECK: ");
			for(j = 0; j < activeGame->deckCount[i]; j++)
			{
				printf("%d,", activeGame->deck[i][j]);
			}
			printf("\n");
			printf("DISCARD: ");
			for(j = 0; j < activeGame->discardCount[i]; j++)
			{
				printf("%d,", activeGame->discard[i][j]);
			}
			printf("\n");
			printf("CURSE: %d, ESTATES: %d, DUCHY: %d, PROVINCE: %d, GREAT_HALL:%d, GARDENS: %d, totalCards: %d\n",
					playGroup->playerValues[i]->cardCounts[CURSE_CT], playGroup->playerValues[i]->cardCounts[ESTATE_CT],
					playGroup->playerValues[i]->cardCounts[DUCHY_CT], playGroup->playerValues[i]->cardCounts[PROVINCE_CT],
					playGroup->playerValues[i]->cardCounts[GREATHALL_CT], playGroup->playerValues[i]->cardCounts[GARDENS_CT],
					playGroup->playerValues[i]->totalCards);
		}
	}


	result->testsPassed++;

	// clean up memory
	for(i = 0; i < MAX_PLAYERS; i++){
		free(playGroup->playerValues[i]);
	}
	free(playGroup);
	free(controlGame);
	free(activeGame);
}