Exemple #1
0
void _SwarmVariable_ValueAtShort( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
	SwarmVariable*	self     = (SwarmVariable*)swarmVariable;
	Variable*       variable = self->variable;
	Dof_Index       dofCount = self->dofCount;
	Dof_Index       dof_I;

	for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
		value[ dof_I ] = (double) Variable_GetValueAtShort( variable, lParticle_I, dof_I );
	}
}
void VariableSuite_TestVariable_Short( VariableSuiteData* data ) {
    typedef short Triple[3];

    short* array;
    Triple* structArray;
    Index length = 10;

    /* List of values to test the variable with.
     * Values to test are hex 5's and a's because they are a series of 0101 and 1010 respectively so they test
     * each bit in memory to read/set.
     */
    long int testValues[] = { 0x5555, 0xaaaa };
    Index testValueCount = 2;
    Index test_I;
    long int testValue;

    Variable* var;
    Variable* vec;
    Variable* vecVar[3];

    int i, j;

    array = Memory_Alloc_Array( short, length, "test" );
    structArray = Memory_Alloc_Array( Triple, length, "test" );

    var = Variable_NewScalar( "Short-Scalar", NULL, Variable_DataType_Short, &length, NULL, (void**)&array, data->vr );
    vec = Variable_NewVector( "Short-Three", NULL, Variable_DataType_Short, 3, &length, NULL, (void**)&structArray, data->vr, "a", "b", "c" );

    vecVar[0] = Variable_Register_GetByName( data->vr, "a" );
    vecVar[1] = Variable_Register_GetByName( data->vr, "b" );
    vecVar[2] = Variable_Register_GetByName( data->vr, "c" );

    Variable_Register_BuildAll( data->vr );


    for ( test_I = 0; test_I < testValueCount; ++test_I ) {

        testValue = testValues[test_I];


        for ( i = 0; i < length; ++i ) {
            Variable_SetValueShort( var, i, testValue );

            Variable_SetValueAtShort( vec, i, 0, testValue );
            Variable_SetValueAtShort( vec, i, 1, testValue );
            Variable_SetValueAtShort( vec, i, 2, testValue );
        }

        for ( i = 0; i < length; ++i ) {
            pcu_check_true( Variable_GetValueShort( var, i ) == (short)(short)testValue );
            pcu_check_true( Variable_GetValueShortAsChar( var, i ) == (char)(short)testValue );
            pcu_check_true( Variable_GetValueShortAsInt( var, i ) == (int)(short)testValue );
            pcu_check_true( Variable_GetValueShortAsFloat( var, i ) == (float)(short)testValue );
            pcu_check_true( Variable_GetValueShortAsDouble( var, i ) == (double)(short)testValue );
        }

        for ( i = 0; i < length; ++i ) {
            pcu_check_true( Variable_GetValueAtShort( vec, i, 0 ) == (short)(short)testValue );
            pcu_check_true( Variable_GetValueAtShortAsChar( vec, i, 0 ) == (char)(short)testValue );
            pcu_check_true( Variable_GetValueAtShortAsInt( vec, i, 0 ) == (int)(short)testValue );
            pcu_check_true( Variable_GetValueAtShortAsFloat( vec, i, 0 ) == (float)(short)testValue );
            pcu_check_true( Variable_GetValueAtShortAsDouble( vec, i, 0 ) == (double)(short)testValue );
            pcu_check_true( Variable_GetPtrAtShort( vec, i, 0 ) == &structArray[i][0] );

            pcu_check_true( Variable_GetValueAtShort( vec, i, 1 ) == (short)(short)testValue );
            pcu_check_true( Variable_GetValueAtShortAsChar( vec, i, 1 ) == (char)(short)testValue );
            pcu_check_true( Variable_GetValueAtShortAsInt( vec, i, 1 ) == (int)(short)testValue );
            pcu_check_true( Variable_GetValueAtShortAsFloat( vec, i, 1 ) == (float)(short)testValue );
            pcu_check_true( Variable_GetValueAtShortAsDouble( vec, i, 1 ) == (double)(short)testValue );
            pcu_check_true( Variable_GetPtrAtShort( vec, i, 1 ) == &structArray[i][1] );

            pcu_check_true( Variable_GetValueAtShort( vec, i, 2 ) == (short)(short)testValue );
            pcu_check_true( Variable_GetValueAtShortAsChar( vec, i, 2 ) == (char)(short)testValue );
            pcu_check_true( Variable_GetValueAtShortAsInt( vec, i, 2 ) == (int)(short)testValue );
            pcu_check_true( Variable_GetValueAtShortAsFloat( vec, i, 2 ) == (float)(short)testValue );
            pcu_check_true( Variable_GetValueAtShortAsDouble( vec, i, 2 ) == (double)(short)testValue );
            pcu_check_true( Variable_GetPtrAtShort( vec, i, 2 ) == &structArray[i][2] );
        }

        for ( i = 0; i < length; ++i ) {
            for ( j = 0; j < 3; ++j ) {
                pcu_check_true( Variable_GetStructPtr( vecVar[j], i ) == &structArray[i][j] );
            }
        }
    }
}