first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / graphiq / library / tests_geometric / test_angle.cpp
1 /*
2 *  Name   : test_angle                                                        *
3 *  Author : Chris Koeritz                                                     *
4 *  Purpose:                                                                   *
5 *    Tests the angle class.                                                   *
6 **
7 * Copyright (c) 2001-$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 <geometric/angle.h>
18 #include <loggers/program_wide_logger.h>
19 #include <mathematics/double_plus.h>
20 #include <structures/static_memory_gremlin.h>
21 #include <unit_test/unit_base.h>
22
23 using namespace application;
24 using namespace basis;
25 using namespace geometric;
26 using namespace loggers;
27 using namespace mathematics;
28 using namespace structures;
29 using namespace unit_test;
30
31 typedef double_plus floot;
32
33 class test_angle : public virtual unit_base, public virtual application_shell
34 {
35 public:
36   test_angle() : application_shell() {}
37   DEFINE_CLASS_NAME("test_angle");
38   virtual int execute();
39 };
40
41 int test_angle::execute()
42 {
43   FUNCDEF("execute");
44   {
45     // first test group: double angle inverse trigonometrics.
46     angle<double> a(30.3, DEGREES);
47     ASSERT_EQUAL(floot(a.get(RADIANS)), floot(.528835), "radian conversion should be right");
48     
49     outcome retval;
50     angle<double> at = angle<double>::arctangent(28.3, 29.5, retval);
51     ASSERT_EQUAL(floot(at.get(DEGREES)), floot(43.8106), "atan should be what we expect");
52     angle<double> as = angle<double>::arcsine(17.6, 82.3, retval);
53     ASSERT_EQUAL(floot(as.get(DEGREES)), floot(12.3482), "asin should be what we expect");
54     angle<double> ac = angle<double>::arccosine(17.2, 42.0, retval);
55     ASSERT_EQUAL(floot(ac.get(DEGREES)), floot(65.8251), "acos should be what we expect");
56   }
57   {
58     // second test: packing an angle.
59     angle<double> q(128, DEGREES);
60     byte_array pacd;
61     int siz = q.packed_size();
62     q.pack(pacd);
63     ASSERT_EQUAL(siz, pacd.length(), "packed size should report proper length");
64     angle<double> x;
65     x.unpack(pacd);
66     ASSERT_EQUAL(floot(q.get(RADIANS)), floot(x.get(RADIANS)),
67         "unpacking should return original value");
68     ASSERT_FALSE(pacd.length(), "unpacking should consume entire array");
69   }
70
71   return final_report();
72 }
73
74 //////////////
75
76 HOOPLE_MAIN(test_angle, )
77