GRASS Programmer's Manual
6.4.2(2012)
|
00001 00002 /***************************************************************************** 00003 * 00004 * MODULE: Grass PDE Numerical Library 00005 * AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006 00006 * soerengebbert <at> gmx <dot> de 00007 * 00008 * PURPOSE: Unit tests for geometry calculations 00009 * 00010 * COPYRIGHT: (C) 2000 by the GRASS Development Team 00011 * 00012 * This program is free software under the GNU General Public 00013 * License (>=v2). Read the file COPYING that comes with GRASS 00014 * for details. 00015 * 00016 *****************************************************************************/ 00017 00018 #include <stdio.h> 00019 #include <stdlib.h> 00020 #include <string.h> 00021 #include <grass/glocale.h> 00022 #include <grass/N_pde.h> 00023 #include <grass/G3d.h> 00024 #include "test_gpde_lib.h" 00025 00026 /* prototypes */ 00027 static int test_geom_data(void); 00028 00029 /* ************************************************************************* */ 00030 /* Performe the geom_data unit tests *************************************** */ 00031 /* ************************************************************************* */ 00032 int unit_test_geom_data(void) 00033 { 00034 int sum = 0; 00035 00036 G_message(_("\n++ Running geom_data unit tests ++")); 00037 00038 sum += test_geom_data(); 00039 00040 if (sum > 0) 00041 G_warning(_("\n-- geom_data unit tests failure --")); 00042 else 00043 G_message(_("\n-- geom_data unit tests finished successfully --")); 00044 00045 return sum; 00046 } 00047 00048 00049 /* ************************************************************************* */ 00050 /* ************************************************************************* */ 00051 /* ************************************************************************* */ 00052 int test_geom_data(void) 00053 { 00054 struct Cell_head region2d; 00055 G3D_Region region3d; 00056 N_geom_data *geom = NULL; 00057 int sum = 0, i; 00058 double area = 0; 00059 00060 G_get_set_window(®ion2d); 00061 00062 /*Set the defaults */ 00063 G3d_initDefaults(); 00064 00065 /*get the current region */ 00066 G3d_getWindow(®ion3d); 00067 00068 geom = N_alloc_geom_data(); 00069 if (!geom) { 00070 G_warning("error in N_alloc_geom_data"); 00071 return 1; 00072 } 00073 N_free_geom_data(geom); 00074 geom = NULL; 00075 00076 /* ************ 2d region *************** */ 00077 geom = N_init_geom_data_2d(®ion2d, geom); 00078 if (!geom) { 00079 G_warning("error in N_init_geom_data_2d"); 00080 return 2; 00081 } 00082 00083 geom = N_init_geom_data_2d(®ion2d, geom); 00084 if (!geom) { 00085 G_warning("error in N_init_geom_data_2d"); 00086 return 3; 00087 } 00088 00089 if (geom->dim != 2) 00090 sum++; 00091 if (geom->planimetric == 0 && geom->area == NULL) 00092 sum++; 00093 if (geom->planimetric == 1 && geom->area != NULL) 00094 sum++; 00095 00096 /*get areas */ 00097 area = 0.0; 00098 if (geom->planimetric == 0) { 00099 for (i = 0; i < geom->rows; i++) 00100 area += N_get_geom_data_area_of_cell(geom, i); 00101 00102 if (area == 0) { 00103 G_warning("Wrong area calculation in N_init_geom_data_2d"); 00104 sum++; 00105 } 00106 } 00107 00108 area = 0.0; 00109 if (geom->planimetric == 1) { 00110 for (i = 0; i < geom->rows; i++) 00111 area += N_get_geom_data_area_of_cell(geom, i); 00112 00113 if (area == 0) { 00114 G_warning 00115 ("Wrong area calculation in N_get_geom_data_area_of_cell"); 00116 sum++; 00117 } 00118 } 00119 00120 00121 N_free_geom_data(geom); 00122 geom = NULL; 00123 00124 /* ************ 3d region *************** */ 00125 geom = N_init_geom_data_3d(®ion3d, geom); 00126 if (!geom) { 00127 G_warning("error in N_init_geom_data_3d"); 00128 return 2; 00129 } 00130 00131 geom = N_init_geom_data_3d(®ion3d, geom); 00132 if (!geom) { 00133 G_warning("error in N_init_geom_data_3d"); 00134 return 3; 00135 } 00136 00137 if (geom->dim != 3) 00138 sum++; 00139 if (geom->planimetric == 0 && geom->area == NULL) 00140 sum++; 00141 00142 if (geom->planimetric == 1 && geom->area != NULL) 00143 sum++; 00144 00145 /*get areas */ 00146 area = 0.0; 00147 if (geom->planimetric == 0) { 00148 for (i = 0; i < geom->rows; i++) 00149 area += N_get_geom_data_area_of_cell(geom, i); 00150 00151 if (area == 0) { 00152 G_warning 00153 ("Wrong area calculation in N_get_geom_data_area_of_cell"); 00154 sum++; 00155 } 00156 } 00157 00158 area = 0.0; 00159 if (geom->planimetric == 1) { 00160 for (i = 0; i < geom->rows; i++) 00161 area += N_get_geom_data_area_of_cell(geom, i); 00162 00163 if (area == 0) { 00164 G_warning 00165 ("Wrong area calculation in N_get_geom_data_area_of_cell"); 00166 sum++; 00167 } 00168 } 00169 00170 return sum; 00171 00172 }