void test_put_updates_value_when_key_is_already_present(){ int values[] = {100,200}; int key = 11; putValue(&hashmap,&key,&values[0]); putValue(&hashmap,&key,&values[1]); ASSERT(getValue(&hashmap,&key)); }
void resizeSymbolTable(SymbolTable * table){ int oldsize = size; int i; string value; int type; size *= 2; emptyItems = size; SymbolTable * newST = (SymbolTable*)malloc(sizeof(SymbolTable)* size); #ifdef DEBUG printf("Double the size of the table\n"); #endif for(i=0; i< oldsize; i++){ type = table[i].type; value = table[i].name; if(value != NULL){ putValue(value, type, newST); } } free(st); st = (SymbolTable*)malloc(sizeof(SymbolTable)* size); emptyItems = size; for(i=0; i< size; i++){ value = newST[i].name; type = newST[i].type; if(value != NULL){ putValue(value, type, st); } } free(newST); }
void AutomationPattern::flipY( int min, int max ) { timeMap tempMap = m_timeMap; timeMap::ConstIterator iterate = m_timeMap.lowerBound(0); float tempValue = 0; int numPoints = 0; for( int i = 0; ( iterate + i + 1 ) != m_timeMap.end() && ( iterate + i ) != m_timeMap.end() ; i++) { numPoints++; } for( int i = 0; i <= numPoints; i++ ) { if ( min < 0 ) { tempValue = valueAt( ( iterate + i ).key() ) * -1; putValue( MidiTime( (iterate + i).key() ) , tempValue, false); } else { tempValue = max - valueAt( ( iterate + i ).key() ); putValue( MidiTime( (iterate + i).key() ) , tempValue, false); } } generateTangents(); emit dataChanged(); }
void test_puts_two_elements_in_same_slot_of_hashMap(){ int values[] = {100,200}; int key[] = {11,21}; putValue(&hashmap,&key[0],&values[0]); putValue(&hashmap,&key[1],&values[1]); ASSERT(getValue(&hashmap,&key[0]) == &values[0]); ASSERT(getValue(&hashmap,&key[1]) == &values[1]); }
void test_tries_to_remove_element_from_hashMap_which_is_not_present(){ int value = 20; int key = 2; int KeyToRemove = 3; putValue(&hashmap,&key,&value); ASSERT(removeFromHashMap(&hashmap,&KeyToRemove) == FAIL); }
void test_removes_from_hashMap(){ int value = 20; int key = 2; putValue(&hashmap,&key,&value); ASSERT(removeFromHashMap(&hashmap,&key) == SUCCESS); ASSERT(getValue(&hashmap,&key) == NULL); }
void putKeysInRehashedMap(Hashmap* hash,Iterator keysIT){ HashElement* element; while(keysIT.hasNext(&keysIT)){ element = keysIT.next(&keysIT); putValue(hash,element->key,element->value); } }
void AutomationPattern::addObject( AutomatableModel * _obj, bool _search_dup ) { if( _search_dup ) { for( objectVector::iterator it = m_objects.begin(); it != m_objects.end(); ++it ) { if( *it == _obj ) { TextFloat::displayMessage( _obj->displayName(), tr( "Model is already connected " "to this pattern." ), embed::getIconPixmap( "automation" ), 2000 ); return; } } } // the automation track is unconnected and there is nothing in the track if( m_objects.isEmpty() && hasAutomation() == false ) { // then initialize first value putValue( MidiTime(0), _obj->inverseScaledValue( _obj->value<float>() ), false ); } m_objects += _obj; connect( _obj, SIGNAL( destroyed( jo_id_t ) ), this, SLOT( objectDestroyed( jo_id_t ) ), Qt::DirectConnection ); emit dataChanged(); }
bool AutomationPattern::addObject( AutomatableModel * _obj, bool _search_dup ) { if( _search_dup ) { for( objectVector::iterator it = m_objects.begin(); it != m_objects.end(); ++it ) { if( *it == _obj ) { return false; } } } // the automation track is unconnected and there is nothing in the track if( m_objects.isEmpty() && hasAutomation() == false ) { // then initialize first value putValue( MidiTime(0), _obj->inverseScaledValue( _obj->value<float>() ), false ); } m_objects += _obj; connect( _obj, SIGNAL( destroyed( jo_id_t ) ), this, SLOT( objectDestroyed( jo_id_t ) ), Qt::DirectConnection ); emit dataChanged(); return true; }
void generateRandomTile(void){ int i, x, sum, rand, tileNum, tileVal, tiles[16]; // Generate random tile number // index of temporary tile array x = 0; // number of empty tiles sum = 0; // get empty tile numbers for (i=1; i<17; i++){ if (getValue(i) == 0){ tiles[x] = i; x += 1; sum += 1; } } // generate tile number from empty tiles tileNum = tiles[(Random()%sum)]; // Generate tile value (80% 2, 20% 4) rand = Random()%100; if (rand < 20){ tileVal = 4; } else{ tileVal = 2; } // put new tile on board putValue(tileVal, tileNum); }
void test_getValue_when_element_which_is_not_present(){ int value = 100; int key = 11; int keyToSearch = 1; putValue(&hashmap,&key,&value); ASSERT(getValue(&hashmap,&keyToSearch) == NULL); }
void AutomationPattern::processMidiTime( const MidiTime & time ) { if( ! isRecording() ) { if( time >= 0 && hasAutomation() ) { const float val = valueAt( time ); for( objectVector::iterator it = m_objects.begin(); it != m_objects.end(); ++it ) { if( *it ) { ( *it )->setAutomatedValue( val ); } } } } else { if( time >= 0 && ! m_objects.isEmpty() ) { const float value = static_cast<float>( firstObject()->value<float>() ); if( value != m_lastRecordedValue ) { putValue( time, value, true ); m_lastRecordedValue = value; } else if( valueAt( time ) != value ) { removeValue( time, false ); } } } }
void AutomationPattern::addObject( AutomatableModel * _obj, bool _search_dup ) { if( _search_dup ) { for( objectVector::iterator it = m_objects.begin(); it != m_objects.end(); ++it ) { if( *it == _obj ) { // Already exists // TODO: Maybe let the user know in some non-annoying way return; } } } // the automation track is unconnected and there is nothing in the track if( m_objects.isEmpty() && hasAutomation() == false ) { // then initialize first value putValue( MidiTime(0), _obj->value<float>(), false ); } m_objects += _obj; connect( _obj, SIGNAL( destroyed( jo_id_t ) ), this, SLOT( objectDestroyed( jo_id_t ) ), Qt::DirectConnection ); emit dataChanged(); }
static errorCode sample_qnameData(const QName qname, void* app_data) { PRINT ("### QNAME "); writeQName (qname); PRINT ("\n"); char *avalue = QNameStrdup(&qname); putValue ((struct appData*) app_data, avalue); free (avalue); return ERR_OK; }
void test_rehash_when_list_grows_more_then_two_nodes(){ int values[] = {10,20,30}; int key[] = {1,11,21}; int i = 0; for(i = 0;i < 3;i++){ putValue(&hashmap,&key[i],&values[i]); } ASSERT(hashmap.bucket.capacity == 20); }
void test_keys_gives_iterator_for_hashmap(){ int value = 20; int key = 1; Iterator it; HashElement *temp; putValue(&hashmap,&key,&value); it = keys(&hashmap); temp = it.next(&it); ASSERT(temp->key == &key); }
static errorCode sample_decimalData(Decimal value, void* app_data) { char avalue[40]; #if 0 sprintf (avalue, "%g", (double)value); putValue ((struct appData*) app_data, avalue); #else printf("XO/EXI Type Decimal not supported '%s':%d\n", __FILE__,__LINE__); #endif return ERR_OK; }
void AutomationPattern::recordValue(MidiTime time, float value) { if( value != m_lastRecordedValue ) { putValue( time, value, true ); m_lastRecordedValue = value; } else if( valueAt( time ) != value ) { removeValue( time ); } }
void test_puts_multiple_elements_in_different_slots_of_hashMap(){ int values[] = {100,200,300,400,500}; int keys[] = {11,12,13,14,15}; int i; for(i = 0;i < 5;i++){ putValue(&hashmap,&keys[i],&values[i]); } ASSERT(getValue(&hashmap,&keys[0]) == &values[0]); ASSERT(getValue(&hashmap,&keys[1]) == &values[1]); ASSERT(getValue(&hashmap,&keys[2]) == &values[2]); ASSERT(getValue(&hashmap,&keys[3]) == &values[3]); ASSERT(getValue(&hashmap,&keys[4]) == &values[4]); }
void test_keys_gives_iterator_for_hashmap_when_multiple_elements_present(){ int values[] = {10,20,30,40}; int key[] = {1,2,3,4}; Iterator it; int i = 0; HashElement *temp; for(i = 0;i < 4;i++){ putValue(&hashmap,&key[i],&values[i]); } it = keys(&hashmap); i = 0; while(it.hasNext(&it)){ temp = it.next(&it); ASSERT(temp->key == &key[i]); i++; } }
void test_rehash_contains_all_previous_hashElements(){ int values[] = {10,20,30}; int key[] = {1,11,21}; int i = 0; Iterator it; HashElement *temp; for(i = 0;i < 3;i++){ putValue(&hashmap,&key[i],&values[i]); } it = keys(&hashmap); temp = it.next(&it); ASSERT(temp->key == &key[0]); temp = it.next(&it); ASSERT(temp->key == &key[2]); temp = it.next(&it); ASSERT(temp->key == &key[1]); }
void editP(HandlerType_t aHandlerType, uint8_t aPType, PtrUnion_t* aPgmPtrUnion, uint8_t aY, uint8_t aColor) { if (aHandlerType == HT_DISPLAY) { displayP(aHandlerType, aPType, aPgmPtrUnion, aY, aColor); return; } // the value holder S32MMSValCb_t s32MMSValCb; void* tgtAdr = pgmToRamP(aPType, aPgmPtrUnion, &s32MMSValCb); if(IS8BIT(aPType)) { if (ISSIGNED(aPType)) { s32MMSValCb.m_min = INT8_MIN; s32MMSValCb.m_max = INT8_MAX; } else { // s32MMSValCb.m_min = UINT8_MIN; // == 0, already done by memset s32MMSValCb.m_max = UINT8_MAX; } } else if (IS16BIT(aPType)) { if (ISSIGNED(aPType)) { s32MMSValCb.m_min = INT16_MIN; s32MMSValCb.m_max = INT16_MAX; } else { // s32MMSValCb.m_min = UINT16_MIN; // == 0, already done by memset s32MMSValCb.m_max = UINT16_MAX; } } if (editNumber(&s32MMSValCb, aY) != BT_ENTER) return; putValue(tgtAdr, aPType, &s32MMSValCb.m_val); } // editVar
void testInlineAutomation() { auto song = Engine::getSong(); InstrumentTrack* instrumentTrack = dynamic_cast<InstrumentTrack*>(Track::create(Track::InstrumentTrack, song)); Pattern* notePattern = dynamic_cast<Pattern*>(instrumentTrack->createTCO(0)); notePattern->changeLength(MidiTime(4, 0)); Note* note = notePattern->addNote(Note(MidiTime(4, 0)), false); note->createDetuning(); DetuningHelper* dh = note->detuning(); auto pattern = dh->automationPattern(); pattern->setProgressionType( AutomationPattern::LinearProgression ); pattern->putValue(MidiTime(0, 0), 0.0); pattern->putValue(MidiTime(4, 0), 1.0); QCOMPARE(pattern->valueAt(MidiTime(0, 0)), 0.0f); QCOMPARE(pattern->valueAt(MidiTime(1, 0)), 0.25f); QCOMPARE(pattern->valueAt(MidiTime(2, 0)), 0.5f); QCOMPARE(pattern->valueAt(MidiTime(4, 0)), 1.0f); }
void AutomationPattern::flipX( int length ) { timeMap tempMap; timeMap::ConstIterator iterate = m_timeMap.lowerBound(0); float tempValue = 0; int numPoints = 0; for( int i = 0; ( iterate + i + 1 ) != m_timeMap.end() && ( iterate + i ) != m_timeMap.end() ; i++) { numPoints++; } float realLength = ( iterate + numPoints ).key(); if ( length != -1 && length != realLength) { if ( realLength < length ) { tempValue = valueAt( ( iterate + numPoints ).key() ); putValue( MidiTime( length ) , tempValue, false); numPoints++; for( int i = 0; i <= numPoints; i++ ) { tempValue = valueAt( ( iterate + i ).key() ); MidiTime newTime = MidiTime( length - ( iterate + i ).key() ); tempMap[newTime] = tempValue; } } else { for( int i = 0; i <= numPoints; i++ ) { tempValue = valueAt( ( iterate + i ).key() ); MidiTime newTime; if ( ( iterate + i ).key() <= length ) { newTime = MidiTime( length - ( iterate + i ).key() ); } else { newTime = MidiTime( ( iterate + i ).key() ); } tempMap[newTime] = tempValue; } } } else { for( int i = 0; i <= numPoints; i++ ) { tempValue = valueAt( ( iterate + i ).key() ); cleanObjects(); MidiTime newTime = MidiTime( realLength - ( iterate + i ).key() ); tempMap[newTime] = tempValue; } } m_timeMap.clear(); m_timeMap = tempMap; generateTangents(); emit dataChanged(); }
void KJSEmbedPart::putVariant( const QString & valueName, const QVariant & value ) { KJS::Value val = convertToValue( js->globalExec(), value); putValue( valueName, val ); }
void test_puts_when_key_is_present_but_value_is_NULL(){ int key = 2; ASSERT(putValue(&hashmap,&key,NULL) == SUCCESS); }
void test_does_not_put_when_hashmap_is_NULL(){ int value = 20; int key = 2; ASSERT(putValue(NULL,&key,&value) == FAIL); }
void test_getValue_when_element_present(){ int value = 10; int key = 1; putValue(&hashmap,&key,&value); ASSERT(getValue(&hashmap,&key) == &value); }
int readHvalues(struct keymap *keyList, char *linep, FILE *fp, char *lsfile, int *LineNum, int exact, char *section) { static char fname[] = "readHvalues"; char *key; char *value; char *sp, *sp1; char error = FALSE; int i=0; sp = linep; key = getNextWord_(&linep); if ((sp1 = strchr(key, '=')) != NULL) *sp1 = '\0'; value = strchr(sp, '='); if (!value) { ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5402, "%s: %s(%d): missing '=' after keyword %s, section %s ignoring the line"), fname, lsfile, *LineNum, key, section); /* catgets 5402 */ } else { value++; while (*value == ' ') value++; if (value[0] == '\0') { ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5403, "%s: %s(%d): null value after keyword %s, section %s ignoring the line"), fname, lsfile, *LineNum, key, section); /* catgets 5403 */ } if (value[0] == '(') { value++; if ((sp1 = strrchr(value, ')')) != NULL) *sp1 = '\0'; } if (putValue(keyList, key, value) < 0) { ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5404, "%s: %s(%d): bad keyword %s in section %s, ignoring the line"), fname, lsfile, *LineNum, key, section); /* catgets 5404 */ } } if ((linep = getNextLineC_(fp, LineNum, TRUE)) != NULL) { if (isSectionEnd(linep, lsfile, LineNum, section)) { if (! exact) return 0; i = 0; while (keyList[i].key != NULL) { if (keyList[i].val == NULL) { ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5405, "%s: %s(%d): required keyword %s is missing in section %s, ignoring the section"), fname, lsfile, *LineNum, keyList[i].key, section); /* catgets 5405 */ error = TRUE; } i++; } if (error) { i = 0; while (keyList[i].key != NULL) { FREEUP(keyList[i].val); i++; } return -1; } return 0; } return readHvalues(keyList, linep, fp, lsfile, LineNum, exact, section); } ls_syslog(LOG_ERR, I18N_PREMATURE_EOF, fname, lsfile, *LineNum, section); return -1; }
void test_does_not_put_when_key_is_NULL(){ int value = 20; ASSERT(putValue(&hashmap,NULL,&value) == FAIL); }