void DictionarySuite_TestSet( DictionarySuiteData* data ) {
   Dictionary_Entry_Value* currValue;
   Dictionary_Entry_Value* listValue;
   double                  newVal1 = 34.3, newVal2 = 38.9;
   Index                   ii=0;

   DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD );

   listValue = Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_list" );
   /* getting dictionary out of a list */
   currValue = Dictionary_Entry_Value_GetFirstElement( listValue  );
   /* do something to this value */
   Dictionary_Entry_Value_SetFromDouble( currValue, newVal1 );
   currValue = currValue->next;
   /* do something to this value */
   Dictionary_Entry_Value_SetFromDouble( currValue, newVal2 );
   
   pcu_check_true( 5 == Dictionary_Entry_Value_GetCount( listValue ) );
   currValue = Dictionary_Entry_Value_GetFirstElement( listValue );
   pcu_check_le( fabs(newVal1 - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 );
   currValue = currValue->next;
   pcu_check_le( fabs(newVal2 - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 );
   currValue = currValue->next;
   for ( ii=2; ii<data->testDD->testListCount; ii++ ) {
      pcu_check_le( fabs(data->testDD->testList[ii]
         - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 );
      currValue = currValue->next;
   }
}
void DictionarySuite_TestAddElement( DictionarySuiteData* data ) {
   Dictionary_Entry_Value* yValue;
   Dictionary_Entry_Value* testStruct;
   Dictionary_Entry_Value* currValue;
   double                  newVal = -45.0;

   DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD );

   /* turning the starty value into a list using add element */
   testStruct = Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_struct"  );
   yValue = Dictionary_Entry_Value_GetMember( Dictionary_Entry_Value_GetMember(testStruct, (Dictionary_Entry_Key)"geom" ), "starty");
   Dictionary_Entry_Value_AddElement( yValue, Dictionary_Entry_Value_FromDouble(newVal) );

   pcu_check_true( Dictionary_Entry_Value_Type_List == yValue->type );
   pcu_check_true( 2 == Dictionary_Entry_Value_GetCount( yValue ) );

   currValue = Dictionary_Entry_Value_GetFirstElement( yValue );
   pcu_check_le( fabs( data->testDD->testStruct->geom.starty - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 );
   currValue = currValue->next;
   pcu_check_le( fabs( newVal - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 );
}
void WeightsSuite_TestElementIntegral(
   PICelleratorContext* context,
   Name                 funcName,
   Index                count,   // was SampleSize - defaults to 5000
   double               meanTolerance,
   double               stdDevTolerance,
   double               expectedMean,
   double               expectedStdDev ) 
{
   Swarm*             integrationSwarm = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"integrationSwarm" );
   Swarm*             materialSwarm    = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPoints" );
   FeMesh*            mesh             = (FeMesh*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"linearMesh" );
   WeightsCalculator* weights          = (WeightsCalculator*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"weights"  );
   FeVariable*        feVariable;
   Element_LocalIndex lElement_I       = 0;
   double             analyticValue    = 0.0;
   double             integral         = 0.0;
   double             error;
   double             errorSquaredSum  = 0.0;
   double             errorSum         = 0.0;
   double             mean;
   double             standardDeviation;
   Index              loop_I;
   void*              data;
   double             differenceMean, differenceStdDev;   

   /* Create FeVariable */
   feVariable = FeVariable_New_Full(
      "feVariable", 
      (DomainContext*)context,
      mesh,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL, 
      1,
      context->dim,
      False,
      False,
      False,
      MPI_COMM_WORLD,
      context->fieldVariable_Register );

   Journal_Firewall( (funcName!=NULL), Journal_Register( Error_Type, (Name)"ConstantWeightsSuite"  ),
      "Error, function name input to %s is NULL", __func__ );

   if ( strcasecmp( funcName, "ShapeFunction" ) == 0 ) {
      feVariable->_interpolateWithinElement = shapeFunction;
      analyticValue = 4.0;
   }
   else if ( strcasecmp( funcName, "ConstantFunction" ) == 0 ) {
      feVariable->_interpolateWithinElement = constantFunction;
      analyticValue = -12.0;
   }
   else if ( strcasecmp( funcName, "LinearFunction" ) == 0 ) {
      feVariable->_interpolateWithinElement = linearFunction;
      analyticValue = 8.0;
   }
   else if ( strcasecmp( funcName, "QuadraticFunction" ) == 0 ) {
      feVariable->_interpolateWithinElement = quadraticFunction;
      analyticValue = 16.0/3.0;
   }
   else if ( strcasecmp( funcName, "PolynomialFunction" ) == 0 ) {
      feVariable->_interpolateWithinElement = polynomialFunction;
      analyticValue = 148.0/3.0;
   }
   else if ( strcasecmp( funcName, "ExponentialFunction" ) == 0 ) {
      feVariable->_interpolateWithinElement = exponentialFunction;
      analyticValue = 0.0 /*TODO*/;
      abort();
   }
   else if ( strcasecmp( funcName, "ExponentialInterface" ) == 0 ) {
      feVariable->_interpolateWithinElement = exponentialInterface;
      analyticValue = 0.05 * (exp(2) - exp(-2)) + 2.0;
   }
   else if ( strcasecmp( funcName, "CircleInterface" ) == 0 ) {
      feVariable->_interpolateWithinElement = circleInterface;
      analyticValue = M_PI;
   }
   else 
      Journal_Firewall( False,
         Journal_Register( Error_Type, (Name)"ConstantWeightsSuite"  ),
         "Cannot understand function name '%s'\n", funcName );

   for ( loop_I = 0 ; loop_I < count ; loop_I++ ) {
      Swarm_Random_Seed( (long)loop_I );
      /* Layout Particles */
      _Swarm_InitialiseParticles( materialSwarm, data );

      _IntegrationPointsSwarm_UpdateHook( NULL, integrationSwarm );
      
      WeightsCalculator_CalculateCell( weights, integrationSwarm, lElement_I );

      /* Evaluate Integral */
      integral = FeVariable_IntegrateElement( feVariable, integrationSwarm, lElement_I );

      /* Calculate Error */
      error = fabs( integral - analyticValue )/fabs( analyticValue );
      errorSum += error;
      errorSquaredSum += error*error;
   }

   /* Calculate Mean and Standard Deviation */
   mean = errorSum / (double)count;
   standardDeviation = sqrt( errorSquaredSum / (double)count - mean * mean );

   //printf( "Func: %s - Mean = %g; SD = %g\n", funcName, mean, standardDeviation );

   /* compare the mean and standard deviation */
   differenceMean = fabs(mean - expectedMean);
   differenceStdDev = fabs(standardDeviation - expectedStdDev);
   pcu_check_le( differenceMean, meanTolerance );
   pcu_check_le( differenceStdDev, stdDevTolerance );
}