Revision: 56760
http://sourceforge.net/p/brlcad/code/56760
Author: starseeker
Date: 2013-08-12 20:48:13 +0000 (Mon, 12 Aug 2013)
Log Message:
-----------
Add test for bn_poly_sub from sf patch #224 by Nyah Check. Interestingly,
seems to be a difference between our routine and Octave - will need to double
check that.
Modified Paths:
--------------
brlcad/trunk/src/libbn/tests/CMakeLists.txt
Added Paths:
-----------
brlcad/trunk/src/libbn/tests/bn_poly_sub.c
Modified: brlcad/trunk/src/libbn/tests/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libbn/tests/CMakeLists.txt 2013-08-12 20:48:11 UTC (rev
56759)
+++ brlcad/trunk/src/libbn/tests/CMakeLists.txt 2013-08-12 20:48:13 UTC (rev
56760)
@@ -4,7 +4,9 @@
BRLCAD_ADDEXEC(tester_bn_poly_multiply bn_poly_multiply.c "libbu;libbn"
NO_INSTALL)
BRLCAD_ADDEXEC(tester_bn_poly_scale bn_poly_scale.c "libbu;libbn" NO_INSTALL)
+BRLCAD_ADDEXEC(tester_bn_poly_sub bn_poly_sub.c "libbu;libbn" NO_INSTALL)
+
# For tester_bn_tri_tri_isect_coplanar, the input format is as follows:
#
# tester_bn_tri_tri_isect_coplanar V0 V1 V2 U0 U1 U2 <area_flag> <expected
result>
@@ -70,7 +72,9 @@
add_test(bn_poly_multiply tester_bn_poly_multiply)
add_test(bn_poly_scale tester_bn_poly_scale)
+add_test(bn_poly_cub_rts tester_bn_poly_sub)
+
# Local Variables:
# tab-width: 8
# mode: cmake
Added: brlcad/trunk/src/libbn/tests/bn_poly_sub.c
===================================================================
--- brlcad/trunk/src/libbn/tests/bn_poly_sub.c (rev 0)
+++ brlcad/trunk/src/libbn/tests/bn_poly_sub.c 2013-08-12 20:48:13 UTC (rev
56760)
@@ -0,0 +1,157 @@
+/* T E S T _ B N _ P O L Y _ S U B . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2013 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+
+
+#include "common.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <signal.h>
+
+#include "bu.h"
+#include "vmath.h"
+#include "bn.h"
+#include "magic.h"
+
+
+/* holds three polynomials to be used in test. */
+bn_poly_t input[3], output[3];
+
+struct bn_poly bn_Zero_poly = { BN_POLY_MAGIC, 0, {0.0} };
+
+
+/**
+ * Initialises polnomial storing a negative, positive and zero coefficients.
+ */
+void
+poly_init(void)
+{
+ /* stores o coefficients to polynomial for input and output. */
+ output[0] = bn_Zero_poly;
+ input[0] = bn_Zero_poly;
+ input[0].dgr = 2;
+ input[0].cf[0] = input[0].cf[1] = input[0].cf[2] = 0.0;
+
+ output[0].dgr = 2;
+ output[0].cf[0] = output[0].cf[1] = output[0].cf[2] = 0.0;
+
+ /* stores negative coefficients to polynomial. */
+ output[1] = bn_Zero_poly;
+ input[1] = bn_Zero_poly;
+ input[1].dgr = 2;
+ output[1].dgr = 2;
+
+ input[1].cf[0] = -4853;
+ input[1].cf[1] = -324;
+ input[1].cf[2] = -275;
+
+ /**
+ * The known values used for these tests are generated from
+ * GNU Octave, version 3.4.3
+ */
+ output[1].cf[0] = -9706;
+ output[1].cf[1] = -648;
+ output[1].cf[2] = -550;
+
+ /* stores positive coefficients to to polynomial input. */
+ output[2] = bn_Zero_poly;
+ input[2] = bn_Zero_poly;
+ input[2].dgr = 2;
+ output[2].dgr = 2;
+
+ input[2].cf[0] = 61685316;
+ input[2].cf[1] = 33552288;
+ input[2].cf[2] = 27339096;
+
+ output[2].cf[0] = 61695022;
+ output[2].cf[1] = 33552936;
+ output[2].cf[2] = 27339646;
+
+ return;
+}
+
+
+/* compares the values of the array and returns 0. */
+int
+check_results(fastf_t a[], fastf_t b[], int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++) {
+ if (!EQUAL(a[i],b[i]))
+ return -1;
+ }
+
+ return 0;
+}
+
+
+/* tests the polynomials to make sure bn_poly_add() works properly. */
+int
+test_bn_poly_sub(void)
+{
+ int val, val1, val2;
+ bn_poly_t a, b, c;
+ a = bn_Zero_poly, b = bn_Zero_poly, c = bn_Zero_poly;
+
+ bn_poly_sub(&a, &input[0], &input[0]);
+ bn_poly_sub(&b, &input[1], &input[0]);
+ bn_poly_sub(&c, &input[2], &input[1]);
+
+ val = check_results(a.cf,output[0].cf, output[0].dgr + 1);
+ val1 = check_results(b.cf, output[1].cf, output[1].dgr + 1);
+ val2 = check_results(c.cf, output[2].cf, output[2].dgr + 1);
+
+ if (val == 0 && val1 == 0 && val2 == 0)
+ return val;
+
+ return -1;
+}
+
+
+int
+main(void)
+{
+ int ret;
+ poly_init();
+ ret = test_bn_poly_sub();
+
+ if (ret == 0) {
+
+ bu_log("Function computes correctly\n");
+ exit(EXIT_SUCCESS);
+ } else
+ exit(EXIT_FAILURE);
+
+ return 0;
+}
+
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: brlcad/trunk/src/libbn/tests/bn_poly_sub.c
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits