void testNewGame (void) { printf ("Now testing 'newGame':\n"); printf ("1) First turn number == -1\n"); prinft ("2) Regions initialised correctly (displine and dice values correct)\n"); // check makes a game without crashing int disciplines[NUM_REGIONS]; int dice [NUM_REGIONS]; int testCase = 0; while (testCase < TEST_NEW_GAME_CASES) { int regionID = 0; while (regionID < NUM_REGIONS) { int studentVal = randomValue(0, NUM_STUDENT_TYPES); int student = 0; if (studentVal == VAL_BQN) { student = BQN; } else if (studentVal == VAL_MMON) { student = MMON; } else if (studentVal == VAL_MJ) { student = MJ; } else if (studentVal == VAL_BPS) { student = BPS; } else if (studentVal == VAL_MTV) { student = MTV; } else { student = THD; } disciplines[regionID] = student; dice[regionID] = randomValue(MIN_DICE_VAL, MAX_DICE_VAL); regionID++; } Game g = newGame (disciplines, dice); assert (getTurnNumber(g) == -1); regionID = 0; while (regionID < NUM_REGIONS) { assert (getDiscipline(g, regionID) == disciplines[regionID]); assert (getDiceValue(g, regionID) == dice[regionID]); regionID++; } disposeGame (g); testCase++; } printf ("Passed\n"); }
int main(){ int n; scanf("%d",n); if(n%2==0) printf("Even"); else prinft("odd"); }
void pai(struct parente filho){ struct parente pai=filho->pai; pai->grau=filho->grau*2+1; struct parente mae=filho->mae; mae->grau=filho->grau*2+2; prinft("Nome do pai:"); scanf("%s",pai->nome); printf("Nome da mae:"); scanf("%s",mae->nome); }
/** * Assignment 6: * Author: Hayden Schmackpfeffer */ struct CookieRequest* get_cookie_1_svc(struct CookieRequest *request, struct svc_req *rqstp) { static struct CookieRequest response; int sister = request->sister; /* * Return Codes * -2: Cookie jar is empty * -1 if it is judy, and judy cannot request * +1 if the cookie is successfully returned */ if (cookies == 0) { response.err=-2; response.sister=TINA; printInfo(); printf("---MOTHER: Not enough cookies in the cookie jar.\n"); printf("Cookies Given to Tina: %d, Cookies Given to Judy: %d\n", cookies_tina, cookies_judy); return (&response); } if (sister == TINA) { cookies--; tinaCookies++; cookies_tina++; response.err=1; response.sister=TINA; printInfo(); printf("---MOTHER: Giving a cookie to TINA. Cookies left: %d, Tina's cookie streak: %d\n", cookies, tinaCookies); return (&response); } //else assume the sister is JUDY if (tinaCookies < 2) { response.err=-1; response.sister=JUDY; printInfo(); printf("---MOTHER: JUDY wants a cookie, but TINA has only gotten: %d \n", tinaCookies); return (&response); } else { cookies--; tinaCookies=0; cookies_judy++; response.err=1; response.sister=JUDY; printInfo(); printf("---MOTHER: Giving a cookie to JUDY. Cookies left: %d", cookies); return (&response); } response.err=0; response.sister=-1; printInfo(); prinft("---MOTHER: This case should never be reached (sister is not Judy or Tina"); return (&response); }
void startTests() { int sensorId1 = 1; int sensor1; int totalSuccessCount = 0; int totalAdminSuccessCount = 0; int totalInstallDrvSuccessCount = 0; int totalUninstallDrvSuccessCount = 0; // Unit tests on the Admin interface. printf("\nStarting tests...\n"); // installDrv printf("\nTests on 'installDrv'\n"); printf("\n- Test 1:\n\tFirst driver install\n\t") if (installDrv() == OK) { totalInstallDrvSuccessCount++; printf("Returned OK - Success\n"); } else { prinft("Returned ERROR - Failure\n"); } printf("\n- Test 2:\n\Second driver install\n\t") if (installDrv() == ERROR) { totalInstallDrvSuccessCount++; printf("Returned ERROR - Success\n"); } else { prinft("Returned OK - Failure\n"); } // Cleaning uninstallDrv(); // installDrv - Summary printf("\nSummary - 'installDrv' passed %d test(s) out of 2.\n"); totalAdminSuccessCount += totalInstallDrvSuccessCount; // uninstallDrv printf("\nTests on 'uninstallDrv'\n"); printf("\n- Test 1:\n\tTry to uninstall with no driver installed\n\t") if (uninstallDrv() == ERROR) { totalUninstallDrvSuccessCount++; printf("Returned ERROR - Success\n"); } else { prinft("Returned OK - Failure\n"); } // Preparing installDrv(); printf("\n- Test 2:\n\tTry to uninstall with driver installed and no devices\n\t") if (uninstallDrv() == OK) { totalUninstallDrvSuccessCount++; printf("Returned OK - Success\n"); } else { prinft("Returned ERROR - Failure\n"); } // Preparing installDrv(); addDev("/sensor1", ((char*)&sensorId1)); printf("\n- Test 3:\n\tTry to uninstall with driver installed and 1 device installed\n\t") if (uninstallDrv() == OK) { totalUninstallDrvSuccessCount++; printf("Returned OK - Success\n"); } else { prinft("Returned ERROR - Failure\n"); } // Preparing installDrv(); addDev("/sensor1", ((char*)&sensorId1)); sensor1 = open("/sensor1", 0, 0); printf("\n- Test 4:\n\tTry to uninstall with driver installed and 1 device installed and opened\n\t") if (uninstallDrv() == ERROR) { totalUninstallDrvSuccessCount++; printf("Returned ERROR - Success\n"); } else { prinft("Returned OK - Failure\n"); } // Cleaning close(sensor1); uninstallDrv(); // uninstallDrv - Summary printf("\nSummary - 'uninstallDrv' passed %d test(s) out of 4.\n"); totalAdminSuccessCount += totalUninstallDrvSuccessCount; }
int main() { int d,m,a; printf("Introduzca fecha en mes y anoen numeros"); scanf("%d %d %d",&d,&m,&a); if(a==%4){ switch(d){ case 1:if(m==1)printf("d es igual a 31 dias\n");break; case 2:if(m==2)prinft("d es igual a 28 dias\n");break; case 3:if(m==3)prinft("d es igual a 31 dias\n");break; case 4:if(m==4)prinft("d es igual a 30 dias\n");break; case 5:if(m==5)prinft("d es igual a 31 dias\n");break; case 6:if(m==6)prinft("d es igual a 30 dias\n");break; case 7:if(m==7)prinft("d es igual a 31 dias\n");break; case 8:if(m==8)prinft("d es igual a 31 dias\n");break; case 9:if(m==9)prinft("d es igual a 30 dias\n");break; case 10:if(m==10)prinft("d es igual a 31 dias\n");break; case 11:if(m==11)prinft("d es igual a 30 dias\n");break; case 12:if(m==12)prinft("d es igual a 31 dias\n");break; } } if(a!==&4){ switch(d){ case 1:if(m==1)printf("d es igual a 31 dias\n");break; case 2:if(m==2)prinft("d es igual a 29 dias\n");break; case 3:if(m==3)prinft("d es igual a 31 dias\n");break; case 4:if(m==4)prinft("d es igual a 30 dias\n");break; case 5:if(m==5)prinft("d es igual a 31 dias\n");break; case 6:if(m==6)prinft("d es igual a 30 dias\n");break; case 7:if(m==7)prinft("d es igual a 31 dias\n");break; case 8:if(m==8)prinft("d es igual a 31 dias\n");break; case 9:if(m==9)prinft("d es igual a 30 dias\n");break; case 10:if(m==10)prinft("d es igual a 31 dias\n");break; case 11:if(m==11)prinft("d es igual a 30 dias\n");break; case 12:if(m==12)prinft("d es igual a 31 dias\n");break; } return 0; }
int main(int argc, char *argv[]) { // FILE *fd; int len; //,x,y; char *dsc; // char bgr[3]; short svalue; int lvalue; unsigned char header[54],*ptr=&header[0]; if (argc != 3) { perror("not enough arguments."); exit(1); } /** Own declarations **/ // number of Threads given by console input int numberOfThreads = atoi(argv[1]); // Array of all Handles, allocate memory for given number of handles HANDLE threadHandles[numberOfThreads]; // = (HANDLE*)malloc(numberOfThreads * sizeof(HANDLE)); // Array of individualThread-Structs to pass data to each thread //struct individualThread* data = (struct individualThread*)malloc(numberOfThreads * sizeof(struct individualThread)); //int maxCalcPerThread = ceil((float)XSIZE*YSIZE/(float)numberOfThreads); //int counter, lineNumber, i, j; // calculation is divided by linecount if (numberOfThreads > YSIZE) { numberOfThreads = YSIZE; } /**********************/ /** Own initialization **/ // initialize individualThread-struct-array "data" by allocating memory // for (j=0; j < numberOfThreads; j++) { // data[j].lines = (int*)malloc(maxCalcPerThread * sizeof(int)); //data[j].threadPt = (FILE)malloc(sizeof(FILE)); // } // set individualThread´s data in order to make the threads work /*counter = 0; lineNumber = 0; for(i=0; i < numberOfThreads; i++){ for(j=i; j < 500; j+=numberOfThreads){ data[i].lines[counter] = j; counter++; lineNumber++; } data[i].numberOfLines = lineNumber; lineNumber = 0; counter = 0; }*/ // TODO check for line-numbers of each thread (delete later) /*for(i=0;i<numberOfThreads;i++){ for(j=0;j<data[i].numberOfLines;j++){ printf("%d , ", data[i].lines[j]); } printf("\n"); } printf("printing done\n");*/ /**********************/ /** Set Up Mutex **/ /*Mutex = CreateMutex(NULL, FALSE, NULL); if (Mutex == NULL) { printf("CreateMutex error: %d\n", GetLastError()); return 1; }*/ /**********************/ getDescription(NULL,&len); if(NULL==(dsc=(char*)malloc(sizeof(char)*len))) { perror("malloc"); exit(1); } getDescription(&dsc,&len); printf("Calculate %s %d\n",dsc,getId()); fd=fopen(argv[2],"wb+"); if(NULL==fd) { perror("open"); exit(1); } svalue=0x4d42; memcpy(ptr,&svalue,2);//signatur ptr+=2; lvalue=XSIZE*YSIZE*3+54; memcpy(ptr,&lvalue,4); //filesize ptr+=4; lvalue=0; memcpy(ptr,&lvalue,4);//reserved ptr+=4; lvalue=54; memcpy(ptr,&lvalue,4);//image offset ptr+=4; lvalue=40; memcpy(ptr,&lvalue,4);//size of header follows ptr+=4; lvalue=XSIZE; memcpy(ptr,&lvalue,4);//with of image ptr+=4; lvalue=YSIZE; memcpy(ptr,&lvalue,4); //height of image ptr+=4; svalue=1; memcpy(ptr,&svalue,2); //number of planes ptr+=2; svalue=24; memcpy(ptr,&svalue,2); //number of pixel ptr+=2; lvalue=0; //compression memcpy(ptr,&lvalue,4); //compression ptr+=4; lvalue=XSIZE*YSIZE*3; memcpy(ptr,&lvalue,4); //size of image ptr+=4; lvalue=0; memcpy(ptr,&lvalue,4); //xres ptr+=4; lvalue=0; memcpy(ptr,&lvalue,4); //yres ptr+=4; lvalue=0; memcpy(ptr,&lvalue,4); //number of colortables ptr+=4; lvalue=0; memcpy(ptr,&lvalue,4); //number of important colors ptr+=4; len=fwrite(header,1,sizeof(header),fd); //write header if(-1==len || len!=sizeof(header)) { perror("write"); exit(2); } sem = CreateSemaphore(NULL, 0, 1, NULL); if (NULL == sem) { printf("create semaphore error\n"); exit(1); } /* for(y=YSIZE-1;y>=0;y--) { for(x=0;x<XSIZE;x++) { getColorValuesAt(x * (2.0 / XSIZE) - 1.5, y * (2.0 / YSIZE) - 1.0,&bgr[2],&bgr[1],&bgr[0]); len=fwrite(bgr,1,3,fd); if(-1==len || len!=3) { perror("write"); exit(4); } } //no padding required because 1500%4 =0 } */ int chunkCount = YSIZE / threadcount; int i; for (i = 0; i < numberOfThreads; i++) { int from = i * chunkCount; int to = (i+1) * chunkCount; int* data = malloc(2 * sizeof(int)); printf("Setup init %d %d\n", from, to); if (i == threadcount - 1) { to = YSIZE; } data[0] = from; data[1] = to; printf("create a Thread \n"); threadHandles[i] = CreateThread(NULL, 0, run, data, 0, NULL); if (NULL == threadHandles[i]) { printf("thread could not be created\n"); exit(1); } } // wait for all threads to finish calculation in order to start writing to file for (i = 0; i < numberOfThreads; i++) { DWORD wait_status = WaitForSingleObject(threadHandles[i], INFINITE); if (WAIT_FAILED == wait_status) { printf("wait error\n"); exit(1); } BOOL close_status = CloseHandle(threadHandles[i]); if (!close_status) { prinft("close error\n"); exit(1); } } // CloseHandle(Mutex); // free file pointer fclose(fd); }