1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
/*****************************************************************************
*
* MODULE: Grass PDE Numerical Library
* AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006
* soerengebbert <at> gmx <dot> de
*
* PURPOSE: Unit tests of math tools
*
* COPYRIGHT: (C) 2000 by the GRASS Development Team
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
* for details.
*
*****************************************************************************/
#include <grass/gis.h>
#include <grass/N_pde.h>
#include "test_gpde_lib.h"
/* prototypes */
static int test_mean_calc(void);
/* *************************************************************** */
/* Perfrome the math tool tests ********************************** */
/* *************************************************************** */
int unit_test_tools(void)
{
int sum = 0;
G_message("\n++ Running math tool unit tests ++");
sum += test_mean_calc();
if (sum > 0)
G_warning("\n-- math tool unit tests failure --");
else
G_message("\n-- math tool unit tests finished successfully --");
return sum;
}
/* *************************************************************** */
/* Test the mean calculation functions *************************** */
/* *************************************************************** */
int test_mean_calc(void)
{
double a, b, mean_n, mean, vector, distance, D, weight;
double v[2];
double array[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int i;
int sum = 0;
char buff1[10];
for (i = 0; i < 10; i++)
array[i] += i;
a = 1.0 / 3.0;
b = 3.0;
v[0] = a;
v[1] = b;
/*arith mean */
mean = N_calc_arith_mean(a, b);
G_message("N_calc_arith_mean: calc a %g and b %g = %12.18lf", a, b, mean);
mean_n = N_calc_arith_mean_n(v, 2);
G_message("N_calc_arith_mean_n: calc a %g and b %g = %12.18lf", v[0], v[1],
mean_n);
if (mean != mean_n)
sum++;
/*geom mean */
mean = N_calc_geom_mean(a, b);
G_message("N_calc_geom_mean: calc a %g and b %g = %12.18lf", a, b, mean);
mean_n = N_calc_geom_mean_n(v, 2);
G_message("N_calc_geom_mean_n: calc a %g and b %g = %12.18lf", v[0], v[1],
mean_n);
if (mean != mean_n)
sum++;
/*harmonic mean */
mean = N_calc_harmonic_mean(a, b);
G_message("N_calc_harmonic_mean: calc a %g and b %g = %12.18lf", a, b,
mean);
mean_n = N_calc_harmonic_mean_n(v, 2);
G_message("N_calc_harmonic_mean_n: calc a %g and b %g = %12.18lf", v[0],
v[1], mean_n);
if (mean != mean_n)
sum++;
/*null test */
a = 2;
b = 0;
v[0] = a;
v[1] = b;
mean = N_calc_harmonic_mean(a, b);
G_message("N_calc_harmonic_mean: calc a %g and b %g = %12.18lf", a, b,
mean);
mean_n = N_calc_harmonic_mean_n(v, 2);
G_message("N_calc_harmonic_mean_n: calc a %g and b %g = %12.18lf", v[0],
v[1], mean_n);
if (mean != mean_n)
sum++;
/*quadratic mean */
a = 1.0 / 3.0;
b = 3.0;
v[0] = a;
v[1] = b;
mean = N_calc_quad_mean(a, b);
G_message("N_calc_quad_mean: calc a %g and b %g = %12.18lf", a, b, mean);
mean_n = N_calc_quad_mean_n(v, 2);
G_message("N_calc_quad_mean_n: calc a %g and b %g = %12.18lf", v[0], v[1],
mean_n);
if (mean != mean_n)
sum++;
/*Test the full upwind stabailization */
vector = -0.000001;
distance = 20;
D = 0.000001;
weight = N_full_upwinding(vector, distance, D);
G_message("N_full_upwinding: vector %g distance %g D %g weight %g\n",
vector, distance, D, weight);
if (weight != 0) {
G_warning("Error detected in N_full_upwinding");
sum++;
}
vector = 0.000001;
weight = N_full_upwinding(vector, distance, D);
G_message("N_full_upwinding: vector %g distance %g D %g weight %g\n",
vector, distance, D, weight);
if (weight != 1) {
G_warning("Error detected in N_full_upwinding");
sum++;
}
D = 0.0;
weight = N_full_upwinding(vector, distance, D);
G_message("N_full_upwinding: vector %g distance %g D %g weight %g\n",
vector, distance, D, weight);
if (weight != 0.5) {
G_warning("Error detected in N_full_upwinding");
sum++;
}
/*Test the exponential upwind stabailization */
vector = -0.000001;
distance = 20;
D = 0.000001;
weight = N_exp_upwinding(vector, distance, D);
G_message("N_exp_upwinding: vector %g distance %g D %g weight %g\n", vector,
distance, D, weight);
sprintf(buff1, "%1.2lf", weight);
sscanf(buff1, "%lf", &weight);
if (weight != 0.05) {
G_warning("Error detected in N_exp_upwinding");
sum++;
}
vector = 0.000001;
weight = N_exp_upwinding(vector, distance, D);
G_message("N_exp_upwinding: vector %g distance %g D %g weight %g\n", vector,
distance, D, weight);
sprintf(buff1, "%1.2lf", weight);
sscanf(buff1, "%lf", &weight);
if (weight != 0.95) {
G_warning("Error detected in N_exp_upwinding");
sum++;
}
D = 0.0;
weight = N_exp_upwinding(vector, distance, D);
G_message("N_exp_upwinding: vector %g distance %g D %g weight %g\n", vector,
distance, D, weight);
if (weight != 0.5) {
G_warning("Error detected in N_exp_upwinding");
sum++;
}
return sum;
}
|