getting changes from cakelampvm
[feisty_meow.git] / graphiq / library / tests_geometric / test_ellipse.cpp
1 /*
2 *  Name   : test_ellipse                                                      *
3 *  Author : Chris Koeritz                                                     *
4 *  Purpose:                                                                   *
5 *    Tests the ellipse class.                                                 *
6 **
7 * Copyright (c) 1993-$now By Author.  This program is free software; you can  *
8 * redistribute it and/or modify it under the terms of the GNU General Public  *
9 * License as published by the Free Software Foundation; either version 2 of   *
10 * the License or (at your option) any later version.  This is online at:      *
11 *     http://www.fsf.org/copyleft/gpl.html                                    *
12 * Please send any updates to: fred@gruntose.com                               *
13 */
14
15 #include <application/hoople_main.h>
16 #include <basis/astring.h>
17 #include <basis/guards.h>
18 #include <geometric/cartesian_objects.h>
19 #include <geometric/ellipse.h>
20 #include <geometric/point.h>
21 #include <mathematics/double_plus.h>
22 #include <structures/static_memory_gremlin.h>
23 #include <unit_test/unit_base.h>
24
25 using namespace application;
26 using namespace basis;
27 using namespace geometric;
28 using namespace loggers;
29 using namespace mathematics;
30 using namespace structures;
31 using namespace unit_test;
32
33 typedef cartesian_point e_point; 
34
35 class test_ellipse : virtual public unit_base, virtual public application_shell
36 {
37 public:
38   test_ellipse() : application_shell() {}
39   DEFINE_CLASS_NAME("test_ellipse");
40   int execute();
41   point<double> supposed_good_value(const angle<double> &rotation);
42 };
43
44 point<double> test_ellipse::supposed_good_value(const angle<double> &rotation)
45 {
46   double_plus rot(rotation.get(DEGREES));
47 //log(a_sprintf("rotation coming in is %f", rot.value()));
48   if (rot == double_plus(0.0)) return point<double>(25.000000, 20.0000);
49   if (rot == double_plus(35.3)) return point<double>(24.7134, 23.3372);
50   if (rot == double_plus(70.6)) return point<double>(22.8791, 28.1757);
51   if (rot == double_plus(105.9)) return point<double>(17.5249, 11.3112);
52   if (rot == double_plus(141.2)) return point<double>(15.3608, 16.2700);
53   if (rot == double_plus(176.5)) return point<double>(15.0023, 19.6943);
54   if (rot == double_plus(211.8)) return point<double>(15.2242, 22.9611);
55   if (rot == double_plus(247.1)) return point<double>(16.7732, 27.6388);
56   if (rot == double_plus(282.4)) return point<double>(22.0127, 10.8459);
57   if (rot == double_plus(317.7)) return point<double>(24.5511, 15.8588);
58   if (rot == double_plus(353.0)) return point<double>(24.9906, 19.3872);
59   return point<double>(0, 0);  // unknown angle.
60 }
61
62 int test_ellipse::execute()
63 {
64   FUNCDEF("execute");
65   ellipse fred(e_point(20, 20), 5, 10);
66   for (double i = 0; i < 360.0; i += 35.3) {
67     e_point where(fred.location(double_angle(i, DEGREES)));
68     a_sprintf test_name("%.2f", double_angle(i, DEGREES).get(DEGREES));
69 //    log(astring(astring::SPRINTF, "at angle %f ellipse is at ", i) + where.text_form());
70     point<double> compare = supposed_good_value(double_angle(i, DEGREES));
71     // right now point is not orderable, so we compare x and y but use the same test name.
72     ASSERT_EQUAL(double_plus(where.x()), double_plus(compare.x()),
73         test_name + " rotation should have proper position");
74     ASSERT_EQUAL(double_plus(where.y()), double_plus(compare.y()),
75         test_name + " rotation should have proper position");
76   }
77   return final_report();
78 }
79
80 //////////////
81
82 HOOPLE_MAIN(test_ellipse, )
83