feisty meow concerns codebase  2.140
test_ellipse.cpp
Go to the documentation of this file.
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 
16 #include <basis/astring.h>
17 #include <basis/guards.h>
19 #include <geometric/ellipse.h>
20 #include <geometric/point.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 
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)));
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 
81 
82 HOOPLE_MAIN(test_ellipse, )
83 
The application_shell is a base object for console programs.
a_sprintf is a specialization of astring that provides printf style support.
Definition: astring.h:440
contents get(angular_units unit) const
retrieves the current angular measure.
Definition: angle.h:202
Provides a geometric point that use double floating points numbers.
double_angle provides a non-templated class for forward declarations.
Definition: angle.h:97
Represents a geometric ellipse.
Definition: ellipse.h:28
numeric_type x() const
Definition: point.h:47
numeric_type y() const
Definition: point.h:48
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition: enhance_cpp.h:45
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition: enhance_cpp.h:57
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition: hoople_main.h:61
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
Contains all of our objects for geometry and avoids name clashes.
Definition: angle.h:25
@ DEGREES
Definition: angle.h:30
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
Definition: averager.h:21
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55
Useful support functions for unit testing, especially within hoople.
Definition: unit_base.cpp:35
cartesian_point e_point
#define test_name()
#define ASSERT_EQUAL(a, b, test_name)
Definition: unit_base.h:38