summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@l3000.localdomain>2010-12-05 07:40:46 -0500
committerSøren Sandmann Pedersen <ssp@l3000.localdomain>2010-12-20 10:48:49 -0500
commita8d4a2ce61839f9a4caa750aec34b80a7f8f6adc (patch)
tree20713a391d98fff15e756ad3d1e807fe01204489
parentfb290aa852279607faae172fd2bb35ab9e66684c (diff)
Check against test data
-rw-r--r--dda.c27
-rw-r--r--testdata.c13
-rw-r--r--testdata.h12
3 files changed, 27 insertions, 25 deletions
diff --git a/dda.c b/dda.c
index 80d91c6..323128a 100644
--- a/dda.c
+++ b/dda.c
@@ -2,7 +2,7 @@
#include <stdio.h>
#include <math.h>
-#include "testdata.h"
+#include "testdata.c"
#define N_STEPS (4)
#define STEP (1/((double)N_STEPS))
@@ -48,15 +48,27 @@ sample_step_y (double y)
}
static void
-dda (double x0, double y0, double x1, double y1)
+dda (test_data_t *testdata)
{
+ double x0 = testdata->segment.x0;
+ double y0 = testdata->segment.y0;
+ double x1 = testdata->segment.x1;
+ double y1 = testdata->segment.y1;
double y = next_sample_y (y0);
+ int i = 0;
while (y < next_sample_y (y1))
{
double x = ((y - y0) / (y1 - y0)) * (x1 - x0) + x0;
double xi = next_sample_x (x);
+ if (testdata->points[i++] != xi ||
+ testdata->points[i++] != y)
+ {
+ printf ("error\n");
+ exit (-1);
+ }
+
y += sample_step_y (y);
}
}
@@ -65,16 +77,9 @@ int
main ()
{
int i;
- for (i = 0; i < 1000; ++i)
+ for (i = 0; i < sizeof testdata / sizeof testdata[0]; ++i)
{
- double x0, y0, x1, y1;
-
- x0 = drand48() * 4;
- y0 = drand48() * 4;
- x1 = x0 + (0.5 - drand48()) * 4;
- y1 = y0 + drand48() * 4;
-
- dda (x0, y0, x1, y1);
+ dda (&(testdata[i]));
}
return 0;
diff --git a/testdata.c b/testdata.c
index 6e3c4e2..eb52b28 100644
--- a/testdata.c
+++ b/testdata.c
@@ -1,6 +1,15 @@
-#include "testdata.h"
+typedef struct test_data_t test_data_t;
+struct test_data_t
+{
+ struct
+ {
+ double x0, y0, x1, y1;
+ } segment;
+
+ double points[100];
+};
-test_data_t data[] =
+static test_data_t testdata[] =
{
{ { 0.000000, 0.003942, 1.833476, 0.710512 },
},
diff --git a/testdata.h b/testdata.h
deleted file mode 100644
index 7f28c34..0000000
--- a/testdata.h
+++ /dev/null
@@ -1,12 +0,0 @@
-typedef struct test_data_t test_data_t;
-struct test_data_t
-{
- struct
- {
- double x0, y0, x1, y1;
- } segment;
-
- double points[100];
-};
-
-extern test_data_t data[];