gimme-alpha 0.1

matdb-suite.c File Reference

#include <math.h>
#include <stdio.h>
#include <CUnit/CUnit.h>
#include "argdefaults.h"
#include "matdb.h"
#include "tests/matdb-suite.h"
Include dependency graph for matdb-suite.c:

Go to the source code of this file.

Functions

void create_matdb (void)
void destroy_matdb (void)
void set_get_material_1_1 (void)
void set_get_material_1_2 (void)
void set_get_material_2_1 (void)
void set_get_material_2_2 (void)
void set_get_alloy_1_2_1_b (void)
void set_get_alloy_1_2_2_l (void)
void get_alloy_early_1_n2_1_b (void)
void get_alloy_early_1_n2_2_l (void)
void matdb_suite_add_tests (CU_pSuite suite)

Variables

struct matdbmdb

Function Documentation

void create_matdb ( void  )

Definition at line 36 of file matdb-suite.c.

References matdb::bowings, matdb_new(), and matdb::materials.

Referenced by matdb_suite_add_tests().

                        {
  mdb = matdb_new();
  CU_ASSERT(mdb != NULL);
  CU_ASSERT(mdb->materials != NULL);
  CU_ASSERT(mdb->bowings != NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void destroy_matdb ( void  )

Definition at line 43 of file matdb-suite.c.

References matdb_destroy().

Referenced by matdb_suite_add_tests().

Here is the call graph for this function:

Here is the caller graph for this function:

void get_alloy_early_1_n2_1_b ( void  )

Definition at line 154 of file matdb-suite.c.

References get_alloy_param(), get_material_param(), and set_bowing_param().

Referenced by matdb_suite_add_tests().

                                    {
  //fprintf(stderr, "get_alloy_early_1_n2_1_b: ");
  double b = 7;
  /*25% mat1 and 75% mat2*/
  double x=0.25;
  int err;
  /*Should fail at setting the bowing; 4 ways of failing*/
  set_bowing_param(mdb, "material_1", "material_2", "param_2", b, &err);
  //fprintf(stderr, "err=%d ", err);
  CU_ASSERT(err == 4);
  set_bowing_param(mdb, "material_2", "material_1", "param_2", b, &err);
  //fprintf(stderr, "err=%d ", err);
  CU_ASSERT(err == 2);
  set_bowing_param(mdb, "material_1", "material_172", "param_2", b, &err);
  //fprintf(stderr, "err=%d ", err);
  CU_ASSERT(err == 3);
  set_bowing_param(mdb, "material_172", "material_1", "param_2", b, &err);
  //fprintf(stderr, "err=%d ", err);
  CU_ASSERT(err == 1);

  /*Should get material1, but not material2.*/
  get_material_param(mdb, "material_1", "param_2", &err);
  //fprintf(stderr, "err=%d ", err);
  CU_ASSERT(err == 0);
  get_material_param(mdb, "material_2", "param_2", &err);
  //fprintf(stderr, "err=%d ", err);
  CU_ASSERT(err == 2);
  /*Should fail to get "material_172", since it has no entry whatsoever*/
  get_material_param(mdb, "material_172", "param_2", &err);
  //fprintf(stderr, "err=%d ", err);
  CU_ASSERT(err == 1);

  /*Should fail to get the bowing; 4 ways of failing.*/
  get_alloy_param(mdb, "material_1", "material_2", x, "param_2", &err);
  //fprintf(stderr, "err=%d ", err);
  CU_ASSERT(err == 5);
  get_alloy_param(mdb, "material_2", "material_1", x, "param_2", &err);
  //fprintf(stderr, "err=%d ", err);
  CU_ASSERT(err == 3);
  get_alloy_param(mdb, "material_1", "material_172", x, "param_2", &err);
  //fprintf(stderr, "err=%d ", err);
  CU_ASSERT(err == 4);
  get_alloy_param(mdb, "material_172", "material_1", x, "param_2", &err);
  //fprintf(stderr, "err=%d ", err);
  CU_ASSERT(err == 2);
  //fprintf(stderr, "\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void get_alloy_early_1_n2_2_l ( void  )

Definition at line 204 of file matdb-suite.c.

References get_alloy_param(), and get_material_param().

Referenced by matdb_suite_add_tests().

                                    {
  ////fprintf(stderr, "get_alloy_early_1_n2_2_l\n");
  double b = 7;
  /*25% mat1 and 75% mat2*/
  double x=0.25;
  int err;
  /*Should get material1, but not material2.*/
  get_material_param(mdb, "material_1", "param_2", &err);
  CU_ASSERT(err == 0);
  get_material_param(mdb, "material_2", "param_2", &err);
  CU_ASSERT(err == 2);
  /*Should fail to get "material_172", since it has no entry whatsoever*/
  get_material_param(mdb, "material_172", "param_2", &err);
  CU_ASSERT(err == 1);

  /*Should fail to get the bowing; 4 ways of failing.*/
  get_alloy_param(mdb, "material_1", "material_2", x, "param_2", &err);
  CU_ASSERT(err == 5);
  get_alloy_param(mdb, "material_2", "material_1", x, "param_2", &err);
  CU_ASSERT(err == 3);
  get_alloy_param(mdb, "material_1", "material_172", x, "param_2", &err);
  CU_ASSERT(err == 4);
  get_alloy_param(mdb, "material_172", "material_1", x, "param_2", &err);
  CU_ASSERT(err == 2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void matdb_suite_add_tests ( CU_pSuite  suite)

Definition at line 231 of file matdb-suite.c.

References create_matdb(), destroy_matdb(), get_alloy_early_1_n2_1_b(), get_alloy_early_1_n2_2_l(), set_get_alloy_1_2_1_b(), set_get_alloy_1_2_2_l(), set_get_material_1_1(), set_get_material_1_2(), set_get_material_2_1(), and set_get_material_2_2().

Referenced by main().

                                            {
  CU_add_test(suite, "create", create_matdb);
  CU_add_test(suite, "set_get_material_1_1", set_get_material_1_1);
  CU_add_test(suite, "set_get_material_1_2", set_get_material_1_2);
  CU_add_test(suite, "set_get_material_2_1", set_get_material_2_1);
  CU_add_test(suite, "get_alloy_early_1_n2_1_b", get_alloy_early_1_n2_1_b);
  CU_add_test(suite, "get_alloy_early_1_n2_2_l", get_alloy_early_1_n2_2_l);
  CU_add_test(suite, "set_get_material_2_2", set_get_material_2_2);
  CU_add_test(suite, "set_get_alloy_1_2_1_b", set_get_alloy_1_2_1_b);
  CU_add_test(suite, "set_get_alloy_1_2_2_l", set_get_alloy_1_2_2_l);
  CU_add_test(suite, "destroy", destroy_matdb);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_get_alloy_1_2_1_b ( void  )

Definition at line 98 of file matdb-suite.c.

References alloy_bowed(), CLOSE_ENOUGH, get_alloy_param(), get_material_param(), and set_bowing_param().

Referenced by matdb_suite_add_tests().

                                 {
  //fprintf(stderr, "set_get_alloy_1_2_1_b: ");
  double b = 7;
  /*25% mat1 and 75% mat2*/
  double x=0.25;
  int err;
  set_bowing_param(mdb, "material_1", "material_2", "param_1", b, &err);
  //fprintf(stderr, "b=%g x=%g err=%d ", b, x, err);
  CU_ASSERT(err == 0);
  double d1 = get_material_param(mdb, "material_1", "param_1", &err);
  CU_ASSERT(err == 0);
  double d2 = get_material_param(mdb, "material_2", "param_1", &err);
  CU_ASSERT(err == 0);
  double v12 = get_alloy_param(mdb, "material_1", "material_2", x, "param_1", &err);
  CU_ASSERT(err == 0);
  double v21 = get_alloy_param(mdb, "material_2", "material_1", (1.0-x), "param_1", &err);
  CU_ASSERT(err == 0);
  CU_ASSERT(fabs(v12 - v21) <= fabs(CLOSE_ENOUGH*(v12)));
  double v_12 = alloy_bowed(d1, d2, b, x);
  double v_21 = alloy_bowed(d2, d1, b, (1-x));
  CU_ASSERT(fabs(v_12 - v_21) <= fabs(CLOSE_ENOUGH*(v_12)));
  CU_ASSERT(fabs(v_12 - v21) <= fabs(CLOSE_ENOUGH*(v_12)));
  CU_ASSERT(fabs(v12 - v_21) <= fabs(CLOSE_ENOUGH*(v_12)));
  CU_ASSERT(fabs(v21 - v_12) <= fabs(CLOSE_ENOUGH*(v_12)));
  CU_ASSERT(fabs(v_21 - v12) <= fabs(CLOSE_ENOUGH*(v_12)));
  //fprintf(stderr, "v12=%g v21=%g v_12=%g v_21=%g\n", v12, v21, v_12, v_21);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_get_alloy_1_2_2_l ( void  )

Definition at line 129 of file matdb-suite.c.

References alloy_linear(), CLOSE_ENOUGH, get_alloy_param(), and get_material_param().

Referenced by matdb_suite_add_tests().

                                 {
  //fprintf(stderr, "set_get_alloy_1_2_2_b\n");
  /*25% mat1 and 75% mat2*/
  double x=0.25;
  int err;
  double d1 = get_material_param(mdb, "material_1", "param_2", &err);
  CU_ASSERT(err == 0);
  double d2 = get_material_param(mdb, "material_2", "param_2", &err);
  CU_ASSERT(err == 0);
  double v12 = get_alloy_param(mdb, "material_1", "material_2", x, "param_2", &err);
  CU_ASSERT(err == 0);
  double v21 = get_alloy_param(mdb, "material_2", "material_1", (1.0-x), "param_2", &err);
  CU_ASSERT(err == 0);
  CU_ASSERT(fabs(v12 - v21) <= fabs(CLOSE_ENOUGH*(v12)));
  double v_12 = alloy_linear(d1, d2, x);
  double v_21 = alloy_linear(d2, d1, (1-x));
  CU_ASSERT(fabs(v_12 - v_21) <= fabs(CLOSE_ENOUGH*(v_12)));
  CU_ASSERT(fabs(v_12 - v21) <= fabs(CLOSE_ENOUGH*(v_12)));
  CU_ASSERT(fabs(v12 - v_21) <= fabs(CLOSE_ENOUGH*(v_12)));
  CU_ASSERT(fabs(v21 - v_12) <= fabs(CLOSE_ENOUGH*(v_12)));
  CU_ASSERT(fabs(v_21 - v12) <= fabs(CLOSE_ENOUGH*(v_12)));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_get_material_1_1 ( void  )

Definition at line 48 of file matdb-suite.c.

References get_material_param(), and set_material_param().

Referenced by matdb_suite_add_tests().

                                {
  //fprintf(stderr, "set_get_material_1_1:");
  double d = 0.5;
  int err;
  set_material_param(mdb, "material_1", "param_1", d, &err);
  CU_ASSERT(err == 0);
  double e = get_material_param(mdb, "material_1", "param_1", &err);
  //fprintf(stderr, "d=%g e=%g err=%d\n", d, e, err);
  CU_ASSERT(d == e);
  CU_ASSERT(err == 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_get_material_1_2 ( void  )

Definition at line 61 of file matdb-suite.c.

References get_material_param(), and set_material_param().

Referenced by matdb_suite_add_tests().

                                {
  //fprintf(stderr, "set_get_material_1_2\n");
  double d = 73;
  int err;
  set_material_param(mdb, "material_1", "param_2", d, &err);
  CU_ASSERT(err == 0);
  double e = get_material_param(mdb, "material_1", "param_2", &err);
  CU_ASSERT(d == e);
  CU_ASSERT(err == 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_get_material_2_1 ( void  )

Definition at line 73 of file matdb-suite.c.

References get_material_param(), and set_material_param().

Referenced by matdb_suite_add_tests().

                                {
  //fprintf(stderr, "set_get_material_2_2\n");
  double d = 1.3;
  int err;
  set_material_param(mdb, "material_2", "param_1", d, &err);
  CU_ASSERT(err == 0);
  double e = get_material_param(mdb, "material_2", "param_1", &err);
  CU_ASSERT(d == e);
  CU_ASSERT(err == 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_get_material_2_2 ( void  )

Definition at line 84 of file matdb-suite.c.

References get_material_param(), and set_material_param().

Referenced by matdb_suite_add_tests().

                                {
  //fprintf(stderr, "set_get_material_2_2\n");
  double d = 0.17;
  int err;
  set_material_param(mdb, "material_2", "param_2", d, &err);
  CU_ASSERT(err == 0);
  double e = get_material_param(mdb, "material_2", "param_2", &err);
  CU_ASSERT(d == e);
  CU_ASSERT(err == 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

struct matdb* mdb

Definition at line 34 of file matdb-suite.c.

Referenced by matdb_new().

 All Classes Files Functions Variables Enumerations Enumerator Defines