Gipps::Gipps(const DriverInfo* d) : DriverModel(d) { v0 = randomValue(d->v0_min,d->v0_max); a = randomValue(d->a_min,d->a_max); b = randomValue(d->b_min,d->b_max); T = randomValue(d->T_min,d->T_max); // desired time gap s0 = randomValue(d->s0_min,d->s0_max); // safety distance }
Wall::Wall(int leftMargin, int top, sf::RenderWindow *window) { ++counter; id = counter; this->window = window; first.setFillColor(sf::Color::Blue); second.setFillColor(sf::Color::Blue); underBlock.setFillColor(sf::Color::Blue); overBlock.setFillColor(sf::Color::Blue); sf::Vector2u windowSize = window->getSize(); first.setSize(sf::Vector2f(leftMargin, thickness)); second.setSize(sf::Vector2f(windowSize.x - leftMargin - holeSize, thickness)); first.setPosition(0, top); second.setPosition(leftMargin + holeSize, top); underBlock.setSize(sf::Vector2f(40, 40)); overBlock.setSize(sf::Vector2f(40, 40)); int min = leftMargin - 49; int max = leftMargin + holeSize + 49; underBlock.setPosition(randomValue(min, max), top + 130); overBlock.setPosition(randomValue(min, max), top - 130); }
void *serialize( void ) { char *raw = new char[21]; int *rawint; int n = rand(); char str1[9]; char str2[9]; randomValue(str1); randomValue(str2); std::cout << str1 << std::endl; std::cout << n << std::endl; std::cout << str2 << std::endl; std::cout << "=========================" << std::endl; for(int i = 0; i < 8; ++i) raw[i] = str1[i]; rawint = reinterpret_cast<int*>(&raw[8]); *rawint = n; /*raw[8] = static_cast<char>(n); raw[9] = static_cast<char>(n >> 8); raw[10] = static_cast<char>(n >> 16); raw[11] = static_cast<char>(n >> 24);*/ for(int i = 0; i < 8; ++i) raw[i + 12] = str2[i]; return raw; }
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"); }
Soldier::Soldier() { _us = randomValue()- DOWNSIDE; _agility = randomValue() - DOWNSIDE; _observation = randomValue() - DOWNSIDE; _camouflage = randomValue() - DOWNSIDE; }
Rider::Rider() { static int amountOfNames = (init(), names.size()); _name = names[rand() % amountOfNames]; _reaction = randomValue(); _acceleration = randomValue(); _stress = randomValue(); _luck = randomValue(); }
void ScatterPlot::setSamples( int numPoints ) { QPolygonF samples; for ( int i = 0; i < numPoints; i++ ) { const double x = randomValue() * 24.0 + 1.0; const double y = ::log( 10.0 * ( x - 1.0 ) + 1.0 ) * ( randomValue() * 0.5 + 0.9 ); samples += QPointF( x, y ); } d_plot->setSamples( samples ); }
// MceSip::Random // ----------------------------------------------------------------------------- // TUint MceSip::Random( TUint aMinValue, TUint aMaxValue ) { TUint randomValue( aMinValue <= aMaxValue ? aMinValue : 0 ); if ( aMinValue <= aMaxValue ) { TTime time; time.HomeTime(); TInt64 seed( time.Int64() ); for ( TUint i = 0; i < ( aMaxValue - aMinValue ); i++ ) { TInt random = Math::Rand( seed ); TReal random2 = ( TReal )random / KMceRandDividerOne; TUint random3 = ( TUint )( aMaxValue * random2 ) / KMceRandDividerTwo; if ( aMinValue <= random3 && aMaxValue >= random3 ) { randomValue = random3; break; } } } return randomValue; }
int main() { int x = 165; int i; for(i=0; i < 5; i++) { x = randomValue(x); printf("%d\n",x); } }
void MatrixGenerator::generateMatrixD(bool isPercent) { cout << "Generating matrixD... " << flush; int UpDown = 0; for (int i=0 ; i<m ; i++) { for (int j=i-w+UpDown ; j<=i+w+UpDown ; j++) { if (j < 0 || j >= n) continue; if (i == j) { matrix[i][j] = randomValue(minDiagValue, maxDiagValue); } else { matrix[i][j] = randomValue(minValue, maxValue); } notNullElementsCount++; } } cout << "done" << endl; cout << "MatrixD test: passed" << endl; }
void MatrixGenerator::generateMatrixC(bool isPercent) { cout << "Generating matrixC... " << flush; int numbersNotNull = k; if (isPercent) numbersNotNull = (int)((double)n*((double)numbersNotNull/100.0)); for (int j=0 ; j<n ; j++) { matrix[j][j] = randomValue(minDiagValue, maxDiagValue); notNullElementsCount++; int numbersLeft = numbersNotNull - 1; while (numbersLeft) { int index = randomIndex(minIndex, maxIndex); if (matrix[index][j] == 0) { matrix[index][j] = randomValue(minValue, maxValue); notNullElementsCount++; numbersLeft--; } } } cout << "done" << endl; cout << "MatrixC test: " << ((testMatrixC(numbersNotNull) == true)?"passed":"failed") << endl; }
FVDM::FVDM(const DriverInfo* d) : DriverModel(d) { v0 = randomValue(d->v0_min,d->v0_max); s0 = randomValue(d->s0_min,d->s0_max); // safety distance beta = randomValue(d->beta_min,d->beta_max); tau = randomValue(d->tau_min,d->tau_max); tWidth = randomValue(d->tWidth_min,d->tWidth_max); lambda = randomValue(d->lambda_min,d->lambda_max); }
void timeSurvey(std::vector < double > &tab, Rider riders[]) { double times[N]; double timesLap[16]; double difference[16]; int k=0; for (int i = 0; i < N; i++) { textcolor(BRIGHT, WHITE); printf("\n%s%9d %s\n",":::::::::::::::::::", i+1, "Lap:"); for (int j = 0; j< N; j++) { bool ifFinish=true; int wayStart=0; double wayLenght=0; clock_t begin, end; time( &begin ); textcolor(BRIGHT, j+1); printf("%s\n", riders[j].name().c_str()); while(ifFinish) { usleep(TIME_INTERVAL); wayStart++; wayLenght += ((riders[j].stress())/100+riders[j].acceleration()*(i+1)/10+randomValue()/100)*wayStart*wayStart/2; printf("%20s\n", "*"); if(wayLenght<4000) ifFinish=true; else ifFinish=false; } time( &end); difference[k] = 10 + difftime( end, begin ) + riders[j].reaction()/1000/(i+1); printf("%s %f\n\n", "Time: ", difference[k]); k++; } } for (int i = 0; i < N; i++) { times[i]+=difference[i]+difference[i+4]+difference[i+8]+difference[i+12]; tab.push_back( times[i] ); } textcolor(BRIGHT, WHITE); printf("%s\n%19s\n", "::::::::::::::::::::::::::::::::::", "FINISH!"); }
void MatrixGenerator::initializeMatrixAndVector() { cout << "Initializing matrix and vector... " << flush; matrix = new double*[m]; for (int i=0 ; i<m ; i++) matrix[i] = new double[n]; clearMatrix(); multiVector = new double[n]; for (int i=0 ; i<n ; i++) multiVector[i] = randomValue(1, 2); resultVector = new double[n]; clearResultVector(); cout << "done" << endl; }
void testGetTurnNumber (void) { printf ("Now testing getTurnNumber... "); // Create game: int disciplines[] = DEFAULT_DISCIPLINES; int dice[] = DEFAULT_DICE; Game g = newGame (disciplines, dice); // Check turns: int turnNum = -1; while (turnNum < TEST_GET_TURN_NUMBER_TURNS) { assert (getTurnNumber(g) == turnNum); throwDice(g, randomValue(2,12)) turnNum++; } disposeGame (g); printf ("Passed\n"); }
cf2_buf_readByte( CF2_Buffer buf ) { if ( buf->ptr < buf->end ) { #if CF2_IO_FAIL if ( randomError2() ) { CF2_SET_ERROR( buf->error, Invalid_Stream_Operation ); return 0; } return *(buf->ptr)++ + randomValue(); #else return *(buf->ptr)++; #endif } else { CF2_SET_ERROR( buf->error, Invalid_Stream_Operation ); return 0; } }
TestCase * Grader02::testWorkload1(int len, int order){ std::vector<int> input; std::vector<int> sorted; createVector(input, sorted, order, len, true); Stopwatch watch; watch.start(); IPriorityQueue * queue = (IPriorityQueue *)createObject("IPriorityQueue1"); if (queue == NULL){ return nullObject("IPriorityQueue1"); } watch.pause(); GoldPriorityQueue gold_queue(sorted); for (size_t i = 0; i < input.size(); ++i){ int key = input[i]; std::string value = randomValue(); gold_queue.push_back(key, value); watch.unpause(); IKeyValue * key_value = (IKeyValue *)createObject("IKeyValue1"); if (key_value == NULL){ return nullObject("IKeyValue1"); } key_value->setKey(key); key_value->setValue(value); queue->enqueue(key_value); int size = queue->size(); if (size != gold_queue.size()){ return failed("after enqueue, size is incorrect"); } int user_key = queue->lowestKey(); IVectorString * user_values = queue->lowestValues(); gold_queue.iterate(); int gold_key = gold_queue.lowestKey(); std::vector<std::string> values = gold_queue.getValues(gold_key); watch.pause(); if (gold_key != user_key){ return failed("after enqueue, lowest key is incorrect"); } if (valuesEqual(user_values, values) == false){ return failed("after enqueue, values incorrect"); } bool check_sort = true; if (len != 10 && i % 100 != 0){ check_sort = false; } if (check_sort){ watch.unpause(); IVectorKeyValue * user_sorted = queue->returnSorted(); watch.pause(); if (sortedEqual(user_sorted, gold_queue.returnSorted()) == false){ return failed("after enqueue, sorted is not equal"); } } } gold_queue.iterate(); int count = 0; while (gold_queue.hasNext()){ watch.unpause(); int user_key = queue->lowestKey(); IVectorString * user_values = queue->lowestValues(); watch.pause(); int gold_key = gold_queue.lowestKey(); std::vector<std::string> values = gold_queue.getValues(gold_key); if (gold_key != user_key){ return failed("during dequeue, lowest key is incorrect"); } if (valuesEqual(user_values, values) == false){ return failed("during dequeue, values incorrect"); } watch.unpause(); int size = queue->size(); watch.pause(); if (size != gold_queue.size()){ return failed("during dequeue, size is incorrect"); } bool check_sort = true; if (len != 10 && count % 100 != 0){ check_sort = false; } if (check_sort){ IVectorKeyValue * user_sorted = queue->returnSorted(); std::vector<std::pair<int, std::string> > gold_sorted = gold_queue.returnSorted(); if (sortedEqual(user_sorted, gold_sorted) == false){ return failed("during dequeue, sorted is not equal"); } } watch.unpause(); queue->dequeue(); watch.pause(); gold_queue.dequeue(); ++count; } return passed(watch.getTime()); }
void loadBoostPlasma2D(Domain *D,LoadList *LL,int s,int iteration) { int i,j,k,istart,iend,jstart,jend,l,intNum,cnt; int posX,posY,iter,t; double tmp,dx,dy; double wp,pDt,v1,v2,v3,gamma,beta[2]; double ne,randTest=0,positionX,positionY; ptclList *New,*p; Particle ***particle; particle=D->particle; dx=D->dx; dy=D->dy; beta[0]=D->beta; beta[1]=1.0; istart=D->istart; iend=D->iend; jstart=D->jstart; jend=D->jend; srand(iteration); //position define iter=0; k=0; for(i=iend-1; i<=iend; i++) { for(j=jstart; j<jend; j++) { for(l=0; l<LL->xnodes-1; l++) for(t=0; t<LL->ynodes-1; t++) { posX=i+D->minXSub-istart; posY=j+D->minYSub-jstart; if((posX>=LL->xpoint[l] && posX<LL->xpoint[l+1]) && (posY>=LL->ypoint[t] && posY<LL->ypoint[t+1])) { ne=((LL->xn[l+1]-LL->xn[l])/(LL->xpoint[l+1]-LL->xpoint[l]) *(posX-LL->xpoint[l])+LL->xn[l]); ne*=((LL->yn[t+1]-LL->yn[t])/(LL->ypoint[t+1]-LL->ypoint[t]) *(posY-LL->ypoint[t])+LL->yn[t]); ne*=LL->numberInCell*beta[iter]; //it is the double number of superparticles. intNum=(int)ne; randTest=ne-intNum; cnt=0; while(cnt<intNum) { positionX=randomValue(beta[iter]); positionY=randomValue(1.0); New = (ptclList *)malloc(sizeof(ptclList)); New->next = particle[i][j][k].head[s]->pt; particle[i][j][k].head[s]->pt = New; New->x = positionX; New->oldX=i+positionX; New->y = positionY; New->oldY=j+positionY; New->z = 0; New->oldZ=k+0; New->E1=New->E2=New->E3=0.0; New->B1=New->B2=New->B3=0.0; v1=maxwellianVelocity(LL->temperature)/velocityC; v2=maxwellianVelocity(LL->temperature)/velocityC; v3=maxwellianVelocity(LL->temperature)/velocityC; New->p1=-D->gamma*D->beta+v1; New->p2=v2; New->p3=v3; LL->index+=1; New->index=LL->index; cnt++; } //end of while(cnt) if(randTest>randomValue(1.0)) { positionX=randomValue(beta[iter]); positionY=randomValue(1.0); New = (ptclList *)malloc(sizeof(ptclList)); New->next = particle[i][j][k].head[s]->pt; particle[i][j][k].head[s]->pt = New; New->x = positionX; New->oldX=i+positionX; New->y = positionY; New->oldY=j+positionY; New->z = 0; New->oldZ=k+0; New->E1=New->E2=New->E3=0.0; New->B1=New->B2=New->B3=0.0; v1=maxwellianVelocity(LL->temperature)/velocityC; v2=maxwellianVelocity(LL->temperature)/velocityC; v3=maxwellianVelocity(LL->temperature)/velocityC; New->p1=-D->gamma*D->beta+v1; New->p2=v2; New->p3=v3; LL->index+=1; New->index=LL->index; } //end of randTest } //end of if(x,y nodes) } //end of for(xnodes,ynodes) } //End of for(j) iter=iter+1; } //End of for(i) }
void loadMovingPolygonPlasma3D(Domain *D,LoadList *LL,int s,int iteration) { int i,j,k,istart,iend,jstart,jend,kstart,kend,intNum,cnt,l,m,n,myrank; int modeX,modeYZ; double posX,posY,posZ,v1,v2,v3,centerX,centerY,centerZ; double ne,randTest,positionX,positionY,positionZ,gaussCoefX,polyCoefX2,gaussCoefYZ,polyCoefYZ2; Particle ***particle; particle=D->particle; MPI_Comm_rank(MPI_COMM_WORLD, &myrank); ptclList *New,*p; istart=D->istart; iend=D->iend; jstart=D->jstart; jend=D->jend; kstart=D->kstart; kend=D->kend; centerX=LL->centerX; centerY=LL->centerY; centerZ=LL->centerZ; gaussCoefX=LL->gaussCoefX; polyCoefX2=LL->polyCoefX2; gaussCoefYZ=LL->gaussCoefYZ; polyCoefYZ2=LL->polyCoefYZ2; modeX=LL->modeX; modeYZ=LL->modeYZ; srand(iteration*(myrank+1)); //position define i=iend-1; for(j=jstart; j<jend; j++) for(k=kstart; k<kend; k++) { for(l=0; l<LL->xnodes-1; l++) for(m=0; m<LL->ynodes-1; m++) for(n=0; n<LL->znodes-1; n++) { posX=i+D->minXSub-istart; posY=j+D->minYSub-jstart; posZ=k+D->minZSub-kstart; if(posX>=LL->xpoint[l] && posX<LL->xpoint[l+1] && posY>=LL->ypoint[m] && posY<LL->ypoint[m+1] && posZ>=LL->zpoint[n] && posZ<LL->zpoint[n+1]) { ne=((LL->xn[l+1]-LL->xn[l])/(LL->xpoint[l+1]-LL->xpoint[l])*(posX-LL->xpoint[l])+LL->xn[l]); ne*=((LL->yn[m+1]-LL->yn[m])/(LL->ypoint[m+1]-LL->ypoint[m])*(posY-LL->ypoint[m])+LL->yn[m]); ne*=((LL->zn[n+1]-LL->zn[n])/(LL->zpoint[n+1]-LL->zpoint[n])*(posZ-LL->zpoint[n])+LL->zn[n]); applyFunctionX(modeX,centerX,posX,gaussCoefX,polyCoefX2); applyFunctionYZ(modeYZ,centerY,posY,centerZ,posZ,gaussCoefYZ,polyCoefYZ2); ne*=LL->numberInCell; //it is the double number of superparticles. intNum=(int)ne; randTest=ne-intNum; cnt=0; while(cnt<intNum) { positionX=randomValue(1.0); positionY=randomValue(1.0); positionZ=randomValue(1.0); New = (ptclList *)malloc(sizeof(ptclList)); New->next = particle[i][j][k].head[s]->pt; particle[i][j][k].head[s]->pt = New; New->x = positionX; New->oldX=i+positionX; New->y = positionY; New->oldY=j+positionY; New->z = positionZ; New->oldZ=k +positionZ; New->E1=New->E2=New->E3=0.0; New->B1=New->B2=New->B3=0.0; v1=maxwellianVelocity(LL->temperature)/velocityC; v2=maxwellianVelocity(LL->temperature)/velocityC; v3=maxwellianVelocity(LL->temperature)/velocityC; New->p1=-D->gamma*D->beta+v1; New->p2=v2; New->p3=v3; LL->index+=1; New->index=LL->index; New->core=myrank; cnt++; } //end of while(cnt) if(randTest>randomValue(1.0)) { positionX=randomValue(1.0); positionY=randomValue(1.0); positionZ=randomValue(1.0); New = (ptclList *)malloc(sizeof(ptclList)); New->next = particle[i][j][k].head[s]->pt; particle[i][j][k].head[s]->pt = New; New->x = positionX; New->oldX=i+positionX; New->y = positionY; New->oldY=j+positionY; New->z = positionZ; New->oldZ=k +positionZ; New->E1=New->E2=New->E3=0.0; New->B1=New->B2=New->B3=0.0; v1=maxwellianVelocity(LL->temperature)/velocityC; v2=maxwellianVelocity(LL->temperature)/velocityC; v3=maxwellianVelocity(LL->temperature)/velocityC; New->p1=-D->gamma*D->beta+v1; New->p2=v2; New->p3=v3; LL->index+=1; New->index=LL->index; New->core=myrank; } //end of if(randTest) } //End of if(pos...) } //end of for(l,m,n) } //End of for(i,j,k) }
terrain* terrain_genDiamondSquare(int size, float range, float factor, const char* texturePath) { terrain* ret = (terrain*)malloc(sizeof(terrain)); ret->model = NULL; ret->heightMap = (float**)malloc(sizeof(float) * size * size); ret->size = size; *((float*)ret->heightMap + 0 * size + 0) = 0; *((float*)ret->heightMap + 0 * size + (size-1)) = 0; *((float*)ret->heightMap + (size-1) * size + 0) = 0; *((float*)ret->heightMap + (size-1) * size + (size-1)) = 0; setRandSeed(); int i, j, k; // NOTE: this is not correct, square values are not using the value of adjacent diamonds correctly for (i = size - 1; i >= 2; i /= 2, range *= pow(2,-factor)) { for (j = 0; j < size - 1; j += i) { for (k = 0; k < size - 1; k += i) { float a = access_2df_array(ret->heightMap, size, j, k); float b = access_2df_array(ret->heightMap, size, j, k+i); float c = access_2df_array(ret->heightMap, size, j+i, k); float d = access_2df_array(ret->heightMap, size, j+i, k+i); float e = access_2df_array(ret->heightMap, size, j + i/2, k + i/2) = (a + b + c + d)/4.0f + randomValue(range); access_2df_array(ret->heightMap, size, j, k+i/2) = (access_2df_array(ret->heightMap, size, j, k) + access_2df_array(ret->heightMap, size, j, k+i) + e)/3.0f + randomValue(range); access_2df_array(ret->heightMap, size, j+i/2, k) = (access_2df_array(ret->heightMap, size, j, k) + access_2df_array(ret->heightMap, size, j+i, k) + e)/3.0f + randomValue(range); access_2df_array(ret->heightMap, size, j+i, k+i/2) = (access_2df_array(ret->heightMap, size, j+i, k) + access_2df_array(ret->heightMap, size, j+i, k+i) + e)/3.0f + randomValue(range); access_2df_array(ret->heightMap, size, j+i/2, k+i) = (access_2df_array(ret->heightMap, size, j, k+i) + access_2df_array(ret->heightMap, size, j+i, k+i) + e)/3.0f + randomValue(range); } } } ret->model = (mesh*)malloc(sizeof(mesh)); mesh_init(ret->model); ret->model->indexCount = 6 * (ret->size - 1) * (ret->size - 1); ret->model->vertexCount = ret->size * ret->size; GLfloat *vertices = (GLfloat*)malloc(sizeof(GLfloat) * ret->model->vertexCount * 8); GLuint *indices = (GLuint*)malloc(sizeof(GLuint) * ret->model->indexCount); for (i = 0, k = 0; i < ret->size; i++) for (j = 0; j < ret->size; j++, k+=8) { vertices[k] = (-ret->size/2 + i); vertices[k+1] = access_2df_array(ret->heightMap, ret->size, i, j); vertices[k+2] = (ret->size/2 - j); vertices[k+3] = (float)((int)j % 2); vertices[k+4] = (float)((int)i % 2); vertices[k+5] = 0; vertices[k+6] = 1; vertices[k+7] = 0; // TODO: fix normals } for (i = 0, k = 0; i < ret->size - 1; i++) { for (j = 0; j < ret->size - 1; j++, k+=6) { indices[k] = i + ret->size*j; indices[k+1] = i + ret->size + 1 + ret->size*j; indices[k+2] = i + 1 + ret->size*j; } } for (i = 0, k = 3; i < ret->size - 1; i++) { for (j = 0; j < ret->size - 1; j++, k+=6) { indices[k] = i + ret->size*j; indices[k+1] = ret->size + i + ret->size*j; indices[k+2] = i + ret->size + 1 + ret->size*j; } } mesh_loadToVAO(ret->model, vertices, indices); mesh_textureFromFile(ret->model, texturePath); free(indices); free(vertices); return ret; }
TestCase * Grader02::testWorkload4(int len, int order, int merge_count, int merge_len){ std::vector<int> input; std::vector<int> sorted; createVector(input, sorted, order, len, false); Stopwatch watch; watch.start(); IPriorityQueue * queue = (IPriorityQueue *)createObject("IPriorityQueue4"); if (queue == NULL){ return nullObject("IPriorityQueue4"); } watch.pause(); GoldPriorityQueue gold_queue(sorted); for (size_t i = 0; i < merge_len; ++i){ int key = input[i]; std::string value = randomValue(); gold_queue.push_back(key, value); watch.unpause(); IKeyValue * key_value = (IKeyValue *)createObject("IKeyValue4"); if (key_value == NULL){ return nullObject("IKeyValue4"); } key_value->setKey(key); key_value->setValue(value); queue->enqueue(key_value); int size = queue->size(); if (size != gold_queue.size()){ return failed("after enqueue, size is incorrect"); } int user_key = queue->lowestKey(); IVectorString * user_values = queue->lowestValues(); gold_queue.iterate(); int gold_key = gold_queue.lowestKey(); std::vector<std::string> values = gold_queue.getValues(gold_key); watch.pause(); if (gold_key != user_key){ return failed("after enqueue, lowest key is incorrect"); } if (valuesEqual(user_values, values) == false){ return failed("after enqueue, values incorrect"); } } for (int i = 1; i < merge_count; ++i){ watch.unpause(); IPriorityQueue * queue2 = (IPriorityQueue *)createObject("IPriorityQueue4"); if (queue == NULL){ return nullObject("IPriorityQueue4"); } watch.pause(); for (int j = (i * merge_len); j < ((i + 1) * merge_len); ++j){ int key = input[j]; std::string value = randomValue(); gold_queue.push_back(key, value); watch.unpause(); IKeyValue * key_value = (IKeyValue *)createObject("IKeyValue4"); if (key_value == NULL){ return nullObject("IKeyValue4"); } key_value->setKey(key); key_value->setValue(value); queue2->enqueue(key_value); watch.pause(); } watch.unpause(); queue->merge(queue2); watch.pause(); gold_queue.iterate(); watch.unpause(); int user_key = queue->lowestKey(); IVectorString * user_values = queue->lowestValues(); watch.pause(); int gold_key = gold_queue.lowestKey(); std::vector<std::string> values = gold_queue.getValues(gold_key); if (gold_key != user_key){ return failed("during dequeue, lowest key is incorrect"); } if (valuesEqual(user_values, values) == false){ return failed("during dequeue, values incorrect"); } } return passed(watch.getTime()); }
void disturbMidpoint(ofVec3f & midPoint, ofVec3f const & bottomLeft, ofVec3f const & topLeft, ofVec3f const & topRight, ofVec3f const & bottomRight) { //if (std::rand() % 2 == 0) { // return; //} midPoint[2] += (topLeft.distance(bottomRight) + topRight.distance(bottomLeft)) * randomValue(); if (midPoint[2] < minHeight) { minHeight = midPoint[2]; } if (midPoint[2] > maxHeight) { maxHeight = midPoint[2]; } }
int main() { unsigned char ctl, engineLeft, engineRight; // do ASURO initialization Init(); // initialize control value ctl = 100; // loop forever while (1) { // generate new speed levels for left and right engine engineLeft = (unsigned char)randomValue(ctl); engineRight = (unsigned char)randomValue(engineLeft); // go straight forward when ctl is between 0 and 31 if (ctl <32) { MotorDir(FWD,FWD); MotorSpeed(engineLeft,engineLeft); } // go a curve in forward direction in case that ctl is between 32 and 63 else if (ctl <64) { MotorDir(FWD,FWD); MotorSpeed(engineLeft,engineRight); } // cycle right when ctl between 64 and 127 else if (ctl <128) { MotorDir(FWD, RWD); MotorSpeed(engineLeft,engineRight); } // cycle left when ctl is between 128 and 191 else if (ctl <192) { MotorDir(RWD, FWD); MotorSpeed(engineLeft,engineRight); } // go straight back when ctl is between 192 and 223 else if (ctl <224) { MotorDir(RWD,RWD); MotorSpeed(engineRight,engineRight); } // go straight back in case that ctl is between 224 and 255 else { MotorDir(RWD,RWD); MotorSpeed(engineRight,engineRight); } // drive for the number of milliseconds specified by five-fold ctl Msleep(5*ctl); // generate a new control word ctl = (unsigned char)randomValue(engineRight); } return -1; }