Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include "command.h"
- #define SIZE 5
- int check_init(command, int *, char [ ], char [ ][21], int);
- void err_message(int);
- int main( ) {
- char data[SIZE][61] = {
- "go;north;south;east;west;start;left;right;home",
- "look",
- "pick up;gold;platinum;crystal;magic sword",
- "drop;gold;platinum;crystal;magic sword",
- "attack;crystal;magic sword"
- };
- char keywords[SIZE][41] = { "go", "look", "pick up", "drop", "attack" };
- char modifiers[SIZE][SIZE][21] =
- { { "north", "south", "east", "west", "start" },
- { "", "", "", "", "" },
- { "gold", "platinum", "crystal", "magic sword", "" },
- { "gold", "platinum", "crystal", "magic sword", "" },
- { "crystal", "magic sword", "", "", "" }
- };
- char phrases[SIZE*3][81] = {
- " Hello Robot! Please GO \t\t over to the \n other side.",
- "Hello Robot can you \n\n\t do something? ",
- "Robot \t go over to the Right, then over to the left, then start",
- "Look over to the \n\n \t \t right",
- "Robot, can you see what I see?",
- "Did you see that? LOOK over \n there! No not there, LOOK here!\n",
- "Can you pick-up the platinum gold and crystal over there?",
- "Over there, can you Pick Up the \n\n \t GOLD \n?",
- "OK, I will get the crystal gold platinum and pick UP the Magic Sword",
- " drop the crystal ",
- "Robot, please drop the \n\n \t\t PLATINUM ",
- "Look can you see any gold platinum or crystal ?",
- " Attack with the crystal and the magic sword",
- "You must look around, move up then attack with the MAGIC sword",
- "ATTACK ATTACK ATTACK! First with a crystal, then with a Magic Sword!"
- };
- int rvalues[SIZE*3] = { 1, 0, 6, 1, 0, 1, 0, 2, 5, 4, 3, 0, 2, 3, 1 };
- int modc[SIZE] = { 5, 0, 4, 4, 2 };
- class command robots[SIZE];
- char t_data[61];
- int i, j, valid=1, rc, count=0, pos=0;
- for(i=0; i<SIZE && valid; i++) {
- if(i==0) {
- robots[i].init( ); // initializing with keyword "go", and modifiers
- // "north", "south", "east", "west", and "start"
- }
- else {
- strcpy(t_data, data[i]);
- robots[i].init(t_data);
- }
- rc = check_init(robots[i], &count, keywords[i], modifiers[i], modc[i]);
- if(rc) {
- valid = 0;
- }
- else {
- printf("Passed test %d...\n", count);
- printf("Press the enter key to continue...");
- getchar( );
- }
- }
- if(valid) {
- count++;
- for(i=0; i<SIZE && valid; i++) {
- for(j=0; j<3 && valid; j++) {
- rc = robots[i].valid_command(phrases[pos]);
- if(rc != rvalues[pos]) {
- printf("Program failed when testing the valid_command( )");
- printf(" function...\n");
- printf("Phrase: '%s'\n", phrases[pos]);
- printf("Your return value-----> %d\n", rc);
- printf("Actual return value---> %d\n", rvalues[pos]);
- valid = 0;
- }
- else {
- printf("Passed test %d...\n", count);
- printf("Press the enter key to continue...");
- getchar( );
- }
- count++;
- pos++;
- }
- }
- }
- if(valid) {
- printf("\nCongratualtions!!! You passed all tests.\n");
- printf("You may hand in your assignment.\n");
- }
- else {
- err_message(count);
- }
- return 0;
- }
- int check_init(command x, int *p, char key[ ], char mod[ ][21], int mc) {
- int rc, num, invalid;
- char keyword[41], modifier[21];
- x.get_keyword(keyword);
- invalid = strcmp(key, keyword);
- if(invalid) {
- rc = 1;
- }
- if(!invalid) {
- for(num=0; num<SIZE && !invalid; num++) {
- x.get_modifier(modifier, num);
- invalid = strcmp(modifier, mod[num]);
- if(invalid) {
- rc = 2 + num;
- }
- }
- }
- if(!invalid) {
- rc = x.modifier_count( );
- if(rc != mc) {
- rc = 7;
- invalid = 1;
- }
- }
- if(invalid) {
- printf("Program failed when testing the init(%s) function\n",
- *p == 0 ? " " : "char data[ ]");
- printf("Failed on test ");
- switch(rc) {
- case 1:
- printf("%d on keyword %d '%s'\n", *p+1, *p+1, key);
- printf("Your keyword-----> '%s'\n", keyword);
- printf("Actual keyword---> '%s'\n", key);
- break;
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- printf("%d on modifier %d '%s'\n", *p+1, num, mod[num-1]);
- printf("Your modifier-----> '%s'\n", modifier);
- printf("Actual modifier---> '%s'\n", mod[num-1]);
- break;
- case 7:
- printf("%d on modifier count...\n", *p+1);
- printf("Your modifier count-----> %d\n", x.modifier_count( ));
- printf("Actual modifier count---> %d\n", mc);
- break;
- }
- }
- (*p)++;
- return invalid; // returns (0) true or (1) false
- }
- void err_message(int total) {
- printf("\nYour program passed %d test(s)...\n", total);
- switch(total) {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- printf("Your program still needs considerable work!\n");
- break;
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- case 11:
- case 12:
- case 13:
- case 14:
- case 15:
- printf("Your program still needs some work!\n");
- break;
- case 16:
- case 17:
- case 18:
- case 19:
- printf("Your program is almost complete!\n");
- break;
- }
- printf("Keep at it!\n\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment