[GRASS-SVN] r57599 - in grass/trunk/lib/vector/rtree: . test_suite
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Sep 5 07:16:49 PDT 2013
Author: huhabla
Date: 2013-09-05 07:16:48 -0700 (Thu, 05 Sep 2013)
New Revision: 57599
Added:
grass/trunk/lib/vector/rtree/test_suite/
grass/trunk/lib/vector/rtree/test_suite/Makefile
grass/trunk/lib/vector/rtree/test_suite/test.gmath.lib.html
grass/trunk/lib/vector/rtree/test_suite/test.rtree.lib.html
grass/trunk/lib/vector/rtree/test_suite/test_basics.c
grass/trunk/lib/vector/rtree/test_suite/test_main.c
grass/trunk/lib/vector/rtree/test_suite/test_rtree_lib.h
Log:
New rtree testsuite
Added: grass/trunk/lib/vector/rtree/test_suite/Makefile
===================================================================
--- grass/trunk/lib/vector/rtree/test_suite/Makefile (rev 0)
+++ grass/trunk/lib/vector/rtree/test_suite/Makefile 2013-09-05 14:16:48 UTC (rev 57599)
@@ -0,0 +1,13 @@
+MODULE_TOPDIR = ../../../..
+
+PGM=test.rtree.lib
+
+LIBES = $(VECTORLIB) $(GISLIB) $(RTREELIB)
+DEPENDENCIES = $(VECTORDEP) $(GISDEP) $(RTREEDEP)
+
+EXTRA_CFLAGS = $(VECT_CFLAGS)
+EXTRA_INC = $(VECT_INC)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
Added: grass/trunk/lib/vector/rtree/test_suite/test.gmath.lib.html
===================================================================
--- grass/trunk/lib/vector/rtree/test_suite/test.gmath.lib.html (rev 0)
+++ grass/trunk/lib/vector/rtree/test_suite/test.gmath.lib.html 2013-09-05 14:16:48 UTC (rev 57599)
@@ -0,0 +1,3 @@
+
+
+Take a look at the module command line help for more information.
Added: grass/trunk/lib/vector/rtree/test_suite/test.rtree.lib.html
===================================================================
Added: grass/trunk/lib/vector/rtree/test_suite/test_basics.c
===================================================================
--- grass/trunk/lib/vector/rtree/test_suite/test_basics.c (rev 0)
+++ grass/trunk/lib/vector/rtree/test_suite/test_basics.c 2013-09-05 14:16:48 UTC (rev 57599)
@@ -0,0 +1,205 @@
+/*****************************************************************************
+ *
+ * MODULE: Grass PDE Numerical Library
+ * AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006
+ * soerengebbert <at> gmx <dot> de
+ *
+ * PURPOSE: Unit tests for les solving
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/glocale.h>
+#include <grass/gis.h>
+#include <grass/rtree.h>
+#include <grass/vector.h>
+#include "test_rtree_lib.h"
+
+/* prototypes */
+static int test_basics_1d(void);
+static int test_basics_2d(void);
+static int test_basics_3d(void);
+static int test_basics_4d(void);
+
+/* ************************************************************************* */
+/* Performe the solver unit tests ****************************************** */
+/* ************************************************************************* */
+
+int unit_test_basics(void)
+{
+ int sum = 0;
+
+ G_message(_("\n++ Running basic unit tests ++"));
+
+ sum += test_basics_1d();
+ sum += test_basics_2d();
+ sum += test_basics_3d();
+ sum += test_basics_4d();
+
+ if (sum > 0)
+ G_warning(_("\n-- Basic rtree unit tests failure --"));
+ else
+ G_message(_("\n-- Basic rtree unit tests finished successfully --"));
+
+ return sum;
+}
+
+/* *************************************************************** */
+/* *************************************************************** */
+/* *************************************************************** */
+
+int test_basics_1d(void)
+{
+ int sum = 0, num, i;
+
+ struct RTree* tree = RTreeCreateTree(-1, 0, 1);
+
+ struct ilist *list = G_new_ilist();
+
+ for(i = 0; i < 10; i++) {
+
+ struct RTree_Rect* rect1 = RTreeAllocRect(tree);
+ RTreeSetRect1D(rect1, tree,(i - 2), (i + 2));
+ RTreeInsertRect(rect1, i + 1, tree);
+
+ struct RTree_Rect* rect2 = RTreeAllocRect(tree);
+ RTreeSetRect1D(rect2, tree, 2.0, 7.0);
+
+ num = RTreeSearch2(tree, rect2, list);
+ printf("Found %i neighbors\n", num);
+
+ if(num != i + 1)
+ sum++;
+
+ RTreeFreeRect(rect1);
+ RTreeFreeRect(rect2);
+ }
+ RTreeDestroyTree(tree);
+ G_free_ilist(list);
+
+ return sum;
+}
+
+
+/* *************************************************************** */
+/* *************************************************************** */
+/* *************************************************************** */
+
+int test_basics_2d(void)
+{
+ int sum = 0, num, i;
+
+ struct RTree* tree = RTreeCreateTree(-1, 0, 2);
+
+ struct ilist *list = G_new_ilist();
+
+ for(i = 0; i < 10; i++) {
+
+ struct RTree_Rect* rect1 = RTreeAllocRect(tree);
+ RTreeSetRect2D(rect1, tree,(i - 2), (i + 2), (i - 2), (i + 2));
+ RTreeInsertRect(rect1, i + 1, tree);
+
+ struct RTree_Rect* rect2 = RTreeAllocRect(tree);
+ RTreeSetRect2D(rect2, tree, 2.0, 7.0, 2.0, 7.0);
+
+ num = RTreeSearch2(tree, rect2, list);
+ printf("Found %i neighbors\n", num);
+
+ if(num != i + 1)
+ sum++;
+
+ RTreeFreeRect(rect1);
+ RTreeFreeRect(rect2);
+ }
+ RTreeDestroyTree(tree);
+ G_free_ilist(list);
+
+ return sum;
+}
+
+
+/* *************************************************************** */
+/* *************************************************************** */
+/* *************************************************************** */
+
+int test_basics_3d(void)
+{
+ int sum = 0, num, i;
+
+ struct RTree* tree = RTreeCreateTree(-1, 0, 3);
+
+ struct ilist *list = G_new_ilist();
+
+ for(i = 0; i < 10; i++) {
+
+ struct RTree_Rect* rect1 = RTreeAllocRect(tree);
+ RTreeSetRect3D(rect1, tree,(i - 2), (i + 2), (i - 2), (i + 2),
+ (i - 2), (i + 2));
+ RTreeInsertRect(rect1, i + 1, tree);
+
+ struct RTree_Rect* rect2 = RTreeAllocRect(tree);
+ RTreeSetRect3D(rect2, tree, 2.0, 7.0, 2.0,
+ 7.0, 2.0, 7.0);
+
+ num = RTreeSearch2(tree, rect2, list);
+ printf("Found %i neighbors\n", num);
+
+ if(num != i + 1)
+ sum++;
+
+ RTreeFreeRect(rect1);
+ RTreeFreeRect(rect2);
+ }
+ RTreeDestroyTree(tree);
+ G_free_ilist(list);
+
+ return sum;
+}
+
+
+/* *************************************************************** */
+/* *************************************************************** */
+/* *************************************************************** */
+
+int test_basics_4d(void)
+{
+ int sum = 0, num, i;
+
+ struct RTree* tree = RTreeCreateTree(-1, 0, 4);
+
+ struct ilist *list = G_new_ilist();
+
+ for(i = 0; i < 10; i++) {
+
+ struct RTree_Rect* rect1 = RTreeAllocRect(tree);
+ RTreeSetRect4D(rect1, tree,(i - 2), (i + 2), (i - 2), (i + 2),
+ (i - 2), (i + 2), (i - 2), (i + 2));
+ RTreeInsertRect(rect1, i + 1, tree);
+
+ struct RTree_Rect* rect2 = RTreeAllocRect(tree);
+ RTreeSetRect4D(rect2, tree, 2.0, 7.0, 2.0,
+ 7.0, 2.0, 7.0, 2.0, 7.0);
+
+ num = RTreeSearch2(tree, rect2, list);
+ printf("Found %i neighbors\n", num);
+
+ if(num != i + 1)
+ sum++;
+
+ RTreeFreeRect(rect1);
+ RTreeFreeRect(rect2);
+ }
+ RTreeDestroyTree(tree);
+ G_free_ilist(list);
+
+ return sum;
+}
+
Added: grass/trunk/lib/vector/rtree/test_suite/test_main.c
===================================================================
--- grass/trunk/lib/vector/rtree/test_suite/test_main.c (rev 0)
+++ grass/trunk/lib/vector/rtree/test_suite/test_main.c 2013-09-05 14:16:48 UTC (rev 57599)
@@ -0,0 +1,93 @@
+/****************************************************************************
+ *
+ * MODULE: test.gpde.lib
+ *
+ * AUTHOR(S): Original author
+ * Soeren Gebbert soerengebbert <at> gmx <dot> de
+ * 05 Sep 2007 Berlin
+ *
+ * PURPOSE: Unit and integration tests for the gmath library
+ *
+ * COPYRIGHT: (C) 2007 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 <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "test_rtree_lib.h"
+
+/*- Parameters and global variables -----------------------------------------*/
+typedef struct {
+ struct Option *unit, *integration, *solverbenchmark, *blasbenchmark, *rows;
+ struct Flag *full, *testunit, *testint;
+} paramType;
+
+paramType param; /*Parameters */
+
+/*- prototypes --------------------------------------------------------------*/
+static void set_params(void); /*Fill the paramType structure */
+
+/* ************************************************************************* */
+/* Set up the arguments we are expecting ********************************** */
+
+/* ************************************************************************* */
+void set_params(void) {
+ param.unit = G_define_option();
+ param.unit->key = "unit";
+ param.unit->type = TYPE_STRING;
+ param.unit->required = YES;
+ param.unit->options = "basics";
+ param.unit->description = _("Choose the unit tests to run");
+
+ param.testunit = G_define_flag();
+ param.testunit->key = 'u';
+ param.testunit->description = _("Run all unit tests");
+
+}
+
+/* ************************************************************************* */
+/* ************************************************************************* */
+
+/* ************************************************************************* */
+int main(int argc, char *argv[]) {
+ struct GModule *module;
+ int returnstat = 0, i;
+
+
+ /* Initialize GRASS */
+ G_gisinit(argv[0]);
+
+ module = G_define_module();
+ module->description
+ = _("Performs benchmarks, unit and integration tests for the gmath library");
+
+ /* Get parameters from user */
+ set_params();
+
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+
+ /*unit tests */
+ i = 0;
+ if (param.unit->answers) {
+ while (param.unit->answers[i]) {
+ if (strcmp(param.unit->answers[i], "basics") == 0)
+ returnstat += unit_test_basics();
+ i++;
+ }
+ }
+
+
+
+ if (returnstat != 0)
+ G_warning("Errors detected while testing the gmath lib");
+ else
+ G_message("\n-- gmath lib tests finished successfully --");
+
+ return (returnstat);
+}
Added: grass/trunk/lib/vector/rtree/test_suite/test_rtree_lib.h
===================================================================
--- grass/trunk/lib/vector/rtree/test_suite/test_rtree_lib.h (rev 0)
+++ grass/trunk/lib/vector/rtree/test_suite/test_rtree_lib.h 2013-09-05 14:16:48 UTC (rev 57599)
@@ -0,0 +1,24 @@
+
+/*****************************************************************************
+*
+* MODULE: Grass gmath Library
+* AUTHOR(S): Soeren Gebbert, Berlin (GER) Oct 2007
+* soerengebbert <at> gmx <dot> de
+*
+* PURPOSE: Unit and Integration tests
+*
+* 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.
+*
+*****************************************************************************/
+
+#ifndef _TEST_GMATH_LIB_H_
+#define _TEST_GMATH_LIB_H_
+
+/* Basic functionality tests */
+extern int unit_test_basics(void);
+
+#endif
More information about the grass-commit
mailing list