示例#1
0
END_TEST

START_TEST(test_print_vessel) {
    char stu[2048];
    char mod[2048];
    memset(stu, 0, 2048);
    memset(mod, 0, 2048);

    srand(time(0));
    struct cargo *c = create_cargo();

    char *names[] = { "Mariella", "Cargoship", "XRPS", "Symphony" };
    double lengths[] = { 154.5, 455.7, 345.15, 480.65, 235.06 };
    double depths[] = { 34.6, 76.4, 85.5, 14.8, 56.9 };

    char* name = names[rand()%4];
    double length = lengths[rand()%5];
    double depth = depths[rand()%5];

    struct vessel v = create_vessel(name, length, depth, *c);

    freopen("mockoutput", "w", stdout);
    print_vessel(&v); 
    read_stdout(stu, 2048);

    sprintf(mod, "%s\n%.1f\n%.1f\n%s\n%d\n%.1f\n", v.name, v.length, v.depth, v.crg.title, v.crg.quantity, v.crg.weight);

    char infostr[100] = "";
    if (mycompare(stu, mod, infostr)) {
        free(c);
        fail("[M3.04] Wrong print output! Your output:\n%s\nReference output:\n%s\nReason: %s\n",
               stu, mod, infostr);
    }
    free(c);
}
示例#2
0
END_TEST


START_TEST(test_draw_ball) {
char stu[2048];
char *mod = "...*...\n.*****.\n.*****.\n*******\n.*****.\n.*****.\n...*...\n";
int size = 3;
freopen("mockoutput", "w", stdout);
draw_ball(size);
read_stdout(stu, 2048);

char infostr[100] = "";
if (mycompare(stu, mod, infostr)) {
fail("[Task 1.6] Called draw_ball(%d). Your output:\n%s\nReference output:\n%s\nReason: %s\n",
size, stu, mod, infostr);
}
}
示例#3
0
int main () {
	  int pass = 0;
	  int fail = 0;
	  int r;
	  int p;
	  int index;
	  int handPos;

      struct gameState post, pre;

      printf ("Unit Test: cardtest4.c\n");
      printf ("   Target: Village Card\n");
      for(p=0; p<4; p++) {
    	  for(index=0; index<20; index++) {
    		  for(handPos=0; handPos<5; handPos++) {
    			  reset(&post, p, index, handPos);
    			  memcpy (&pre, &post, sizeof(struct gameState));
    			  set(&pre, p, handPos);
    			  playVillage(&post, handPos);
    			  r = mycompare(&pre, &post, p);
				  if (r == 0) { pass++; }
				  else {
					  fail++;
					  if(VERBOSE){
						  printf("\nFailed Test: p:%d index:%d handPos:%d\n", p, index, handPos);
						  printf("ORACLE\n");
						  myprint(&pre, p);
						  printf("RESULTS\n");
						  myprint(&post, p);
						  printf("\n");
					  }
				  }

    		  }
    	  }
      }
      if (fail)
          printf ("   Status: FAILED\n");
      else
    	  printf ("   Status: PASSED\n");

	  printf ("   Passed: %d\n", pass);
	  printf ("   Failed: %d\n", fail);

      return 0;
}
示例#4
0
文件: seq.cpp 项目: wengduo/item
int list_dizhi(NODE *phead, void *val, bool(*mycompare)(void *date, void *val, char ps), char ps)
{
	if (phead == NULL)
	{
		return -1;
	}
	NODE *p = phead->next;
	int count = 0;
	while (p != NULL)
	{
		count++;
		if (mycompare(p->date, val, ps))
		{
			return count;
		}
		p = p->next;
	}
	printf("无此数\n");
	return -1;
}
int countGreaterNumbers(struct transaction *Arr, int len, char *date) {
	if (Arr == NULL || len <= 0)
		return NULL;
	else
	{
		int j = 0, k = -1;
		for (j = 0; j < len; j++)
		{
			if (mycompare(Arr[j].date, date))
			{
				k = j;
			}
		}
		if (k != -1)
			return len - k - 1;
		else
			return 0;
	}
	
}
示例#6
0
END_TEST





// STUB goes here
START_TEST(test_draw_triangle) {
char stu[2048];
char *mod = "....#\n...##\n..###\n.####\n#####\n";
int size = 5;
freopen("mockoutput", "w", stdout);
draw_triangle(size);
read_stdout(stu, 2048);

char infostr[100] = "";
if (mycompare(stu, mod, infostr)) {
fail("[Task 1.5] Called draw_triangle(%d). Your output:\n%s\nReference output:\n%s\nReason: %s\n",
size, stu, mod, infostr);
}
}
示例#7
0
END_TEST


START_TEST(test_tick)
{
    Field *f;
    for (unsigned int i = 1; i < sizeof(fields) / sizeof(char *) - 1; i++) {
        f = fieldFromString(fields[i]);
        tick(f);
        
        char str[400];
        fieldToString(f, str, sizeof(str));
        
        char infostr[400];
        if (mycompare(str, fields[i + 1], infostr) != 0) {
            releaseField(f);
            fail("[M4.02.d] After tick()\n%s should evolve into\n%s. Your field:\n%s\nReason: %s\n",
                    fields[i], fields[i+1], str, infostr);
        }
	releaseField(f);
    }
}