void VariableSuite_TestSetValueDouble( VariableSuiteData* data ) {
    Index                   ii;
    double tmp;
    Variable*      var = Variable_Register_GetByName( data->vr, "temperature" );

    /* Fill the temperature Variable with another known pattern of kinda random (bit filling) numbers */
    for( ii = 0; ii < data->aSize[0]; ii++ ) {

        Variable_SetValueDouble( var, ii, 1.0f - ( 1.0f / (data->aSize[0]+2) * (ii+1) ) );
    }

    /* Check that Variable_SetValueDouble on the temperature Variable set the right numbers */
    for( ii = 0; ii < data->aSize[0]; ii++ ) {
        tmp = 1.0f - 1.0f / (data->aSize[0]+2) * (ii+1);

        pcu_check_true( fabs(data->temperature[ii] - tmp ) < 1e-12);
    }
}
void VariableSuite_TestGetValueDouble( VariableSuiteData* data ) {
    Index                   ii;
    double tmp;
    Variable*      var = Variable_Register_GetByName( data->vr, "temperature" );

    /* Test the Get and Set of a scalar double....................................................................... */
    /* Fill the temperature array with a known pattern of kinda random (bit filling) numbers. */
    for( ii = 0; ii < data->aSize[0]; ii++ ) {
        data->temperature[ii] = 1.0f / (data->aSize[0]+2) * (ii+1);
    }

    /* Check that Variable_GetValueDouble on the temperature Variable returns the right numbers */
    for( ii = 0; ii < data->aSize[0]; ii++ ) {
        tmp = 1.0f / (data->aSize[0]+2) * (ii+1);

        pcu_check_true( fabs(Variable_GetValueDouble( var, ii ) - tmp ) < 1e-12);
    }
}
void Variable_Register_SetAllVariablesFromDictionary( void* _variable_Register, Index index, Dictionary* dictionary ) {
	Variable_Register* variable_Register = (Variable_Register*) _variable_Register;
	Variable*          variable;
	Dictionary_Index   dictionary_I;
	Dictionary_Entry*  entry;

	for ( dictionary_I = 0 ; dictionary_I < dictionary->count ; dictionary_I++ ) {
		entry = dictionary->entryPtr[ dictionary_I ];

		/* Find variable on particle associated with this name */
		variable = Variable_Register_GetByName( variable_Register, entry->key );
		
		/* If there is no variable, continue through loop */
		if (variable == NULL) 
			continue;

		/* Assign Value */
		Variable_SetValueFromDictionary( variable, index, dictionary );
	}
}
void VariableSuite_TestSetValueAtDouble( VariableSuiteData* data ) {
    Index                   ii;
    double tmp;
    int d;
    Variable*      var = Variable_Register_GetByName( data->vr, "velocity" );

    /* Fill the variable Variable with another known pattern of kinda random (bit filling) numbers */
    for( ii = 0; ii < data->aSize[1]; ii++ ) {

        for( d = 0; d < 3; d++ ) {
            Variable_SetValueAtDouble( var, ii, d, 1.0 - ( 1.0 / ((data->aSize[1]*3)+2) * (ii*3+d+1) ) );
        }
    }

    /* Check that Variable_SetValueDouble on the velocity Variable set the right numbers */
    for( ii = 0; ii < data->aSize[1]; ii++ ) {

        for( d = 0; d < 3; d++ ) {
            tmp = 1.0 - ( 1.0 / ((data->aSize[1]*3)+2) * (ii*3+d+1) );

            pcu_check_true( data->velocity[ii][d]-tmp < 1e-12 );
        }
    }
}
void LiveComponentRegisterSuite_TestGet( LiveComponentRegisterSuiteData* data ) {
   typedef float Triple[3];

   float* array;
   Triple* structArray;

   StgVariable* var;
   StgVariable* vec;
   StgVariable* vecVar[3];
   StgVariable* tempVar = NULL;
   Index length = 10;

   Variable_Register* reg;

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

   reg = Variable_Register_New();

   var = StgVariable_NewScalar(
      "Scalar",
		NULL,
      StgVariable_DataType_Float,
      &length,
      NULL,
      (void**)&array,
      reg );

   vec = StgVariable_NewVector(
      "Three",
		NULL,
      StgVariable_DataType_Float,
      3,
      &length,
      NULL,
      (void**)&structArray,
      reg,
      "a",
      "b",
      "c" );

   vecVar[0] = Variable_Register_GetByName( reg, "a" );
   vecVar[1] = Variable_Register_GetByName( reg, "b" );
   vecVar[2] = Variable_Register_GetByName( reg, "c" );

   Variable_Register_BuildAll( reg );

   LiveComponentRegister_Add( data->lcRegister, (Stg_Component*) var );
   pcu_check_true( LiveComponentRegister_IfRegThenAdd( (Stg_Component*) vec ) );
   LiveComponentRegister_Add( data->lcRegister, (Stg_Component*) vecVar[0] );
   LiveComponentRegister_Add( data->lcRegister, (Stg_Component*) vecVar[1] );
   LiveComponentRegister_Add( data->lcRegister, (Stg_Component*) vecVar[2] );

   tempVar = (StgVariable*) LiveComponentRegister_Get( data->lcRegister, (Name)"Scalar" );
   pcu_check_true( tempVar == var );

   tempVar = (StgVariable* ) LiveComponentRegister_Get( LiveComponentRegister_GetLiveComponentRegister(), (Name)"Three" );
   pcu_check_true( tempVar == vec );

   tempVar = (StgVariable* ) LiveComponentRegister_Get( data->lcRegister, (Name)"a" );
   pcu_check_true( tempVar == vecVar[0] );

   tempVar = (StgVariable* ) LiveComponentRegister_Get( data->lcRegister, (Name)"b" );
   pcu_check_true( tempVar == vecVar[1] );

   tempVar = (StgVariable* ) LiveComponentRegister_Get( data->lcRegister, (Name)"c" );
   pcu_check_true( tempVar == vecVar[2] );
}
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] );
            }
        }
    }
}
void VariableSuite_TestVariable_Float( VariableSuiteData* data ) {
    typedef float Triple[3];

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

    float testValues[] = { 123456789.0, 0.987654321 };
    Index testValueCount = 2;
    Index test_I;
    float testValue;

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

    int i, j;

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

    var = Variable_NewScalar( "Float-Scalar", NULL, Variable_DataType_Float, &length, NULL, (void**)&array, data->vr );
    vec = Variable_NewVector( "Float-Three", NULL, Variable_DataType_Float, 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_SetValueFloat( var, i, testValue );

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

        /* "~~~Scalar~~~\n" */
        for ( i = 0; i < length; ++i ) {
            pcu_check_true( Variable_GetValueFloat( var, i ) == (float)(float)testValue );
            pcu_check_true( Variable_GetValueFloatAsChar( var, i ) == (float)(char)testValue );
            pcu_check_true( Variable_GetValueFloatAsShort( var, i ) == (float)(short)testValue );
            pcu_check_true( Variable_GetValueFloatAsInt( var, i ) == (float)(int)testValue );
            pcu_check_true( Variable_GetValueFloatAsDouble( var, i ) == (double)(float)testValue );
        }

        /*~~~Vector~~~*/
        for ( i = 0; i < length; ++i ) {
            pcu_check_true( Variable_GetValueAtFloat( vec, i, 0 ) == (float)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsChar( vec, i, 0 ) == (char)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsShort( vec, i, 0 ) == (short)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsInt( vec, i, 0 ) == (int)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsDouble( vec, i, 0 ) == (double)(float)testValue );
            pcu_check_true( Variable_GetPtrAtFloat( vec, i, 0 ) == &structArray[i][0] );

            pcu_check_true( Variable_GetValueAtFloat( vec, i, 1 ) == (float)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsChar( vec, i, 1 ) == (char)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsShort( vec, i, 1 ) == (short)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsInt( vec, i, 1 ) == (int)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsDouble( vec, i, 1 ) == (double)(float)testValue );
            pcu_check_true( Variable_GetPtrAtFloat( vec, i, 1 ) == &structArray[i][1] );

            pcu_check_true( Variable_GetValueAtFloat( vec, i, 2 ) == (float)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsChar( vec, i, 2 ) == (char)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsShort( vec, i, 2 ) == (short)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsInt( vec, i, 2 ) == (int)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsDouble( vec, i, 2 ) == (double)(float)testValue );
            pcu_check_true( Variable_GetPtrAtFloat( vec, i, 2 ) == &structArray[i][2] );
        }

        /*~~~Vector: Sub-Variable~~~*/
        for ( i = 0; i < length; ++i ) {
            for ( j = 0; j < 3; ++j ) {
                pcu_check_true( Variable_GetStructPtr( vecVar[j], i ) == &structArray[i][j] );
            }
        }
    }
}