Exemple #1
0
void compute(fractal* f){
	int i, j;
	int sum = 0;
	for(i=0; i < fractal_get_height(f); i++){
		for(j=0; j < fractal_get_width(f); j++){
			fractal_compute_value(f,i,j);
			sum+=fractal_get_value(f,i,j);
		}
	}
	f->avg=(sum*1.0)/(f->height*f->width);
}
Exemple #2
0
void producer(){
	
	int currentLine = 1;
	int currentFile = 0;
	
	while(currentFile<FILEAMOUNT)
	{
		
		char* fractalResult=getFractal(files[currentFile], currentLine);
		currentLine++;
		printf("after get fractal: %s",fractalResult);
		if(eof==true){
			currentFile++;
			eof=false;
		}
		
		if(fractalResult[0]!="#"){
			printf("just before sem wait \n");
			sem_wait(&empty); 
			pthread_mutex_lock(&mutexFractal);
			
			int index;
			for(int i =0;i<10;i++){
				if(fractal_get_height(slots[i])<0){
					index=i;
				}
			}
			char * name= strtok(fractalResult," ");
			char * width = strtok(NULL," ");
			char * height = strtok(NULL," ");
			char * a = strtok(NULL," ");
			char * b = strtok(NULL," ");
			
			slots[index]= fractal_new(atoi(width), atoi(height), atof(a), atof(b), name);
		
			pthread_mutex_unlock(&mutexFractal);
			sem_post(&full);
		}
	}
	printf("After while");
	noMoreFiles=true;
	
}
void test_libfractal_get_set_value() {
	fractal_t *ptr = fractal_new(name, 10, 10, a, b);
	int w = fractal_get_width(ptr);
	int h = fractal_get_height(ptr);
	int x = 0;
	int y = 0;
	for ( y = 0; y < h ; y++) {
		for( x = 0; x < w ; x++)  {
			fractal_set_value(ptr, x, y, x+y*10);
		}
	}

	for ( y = 0; y < h ; y++) {
		for( x = 0; x < w ; x++)  {
			CU_ASSERT_EQUAL(fractal_get_value(ptr, x, y), x+y*10);
		}
	}

	fractal_free(ptr);
}
void test_libfractal_get_height() {
	fractal_t *ptr = fractal_new(name, width, 42, a, b);
	CU_ASSERT_EQUAL(fractal_get_height(ptr), 42);
	fractal_free(ptr);
}