feisty meow concerns codebase 2.140
test_angle.cpp
Go to the documentation of this file.
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
16#include <basis/astring.h>
17#include <geometric/angle.h>
21#include <unit_test/unit_base.h>
22
23using namespace application;
24using namespace basis;
25using namespace geometric;
26using namespace loggers;
27using namespace mathematics;
28using namespace structures;
29using namespace unit_test;
30
32
33class test_angle : public virtual unit_base, public virtual application_shell
34{
35public:
36 test_angle() : application_shell() {}
37 DEFINE_CLASS_NAME("test_angle");
38 virtual int execute();
39};
40
41int 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");
65 x.unpack(pacd);
67 "unpacking should return original value");
68 ASSERT_FALSE(pacd.length(), "unpacking should consume entire array");
69 }
70
71 return final_report();
72}
73
75
76HOOPLE_MAIN(test_angle, )
77
The application_shell is a base object for console programs.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
application_shell()
constructs an application_shell to serve as the root of the program.
int length() const
Returns the current reported length of the allocated C array.
Definition array.h:115
A very common template for a dynamic array of bytes.
Definition byte_array.h:36
Outcomes describe the state of completion for an operation.
Definition outcome.h:31
contents get(angular_units unit) const
retrieves the current angular measure.
Definition angle.h:202
static angle arcsine(contents opposite, contents hypotenuse, basis::outcome &retval)
returns the asin of the angle.
Definition angle.h:217
static angle arctangent(contents opposite, contents adjacent, basis::outcome &retval)
returns the atan of the angle.
Definition angle.h:228
virtual bool unpack(basis::byte_array &packed_form)
unpacks the angle from the "packed_form".
Definition angle.h:174
static angle arccosine(contents adjacent, contents hypotenuse, basis::outcome &retval)
returns the acos of the angle.
Definition angle.h:206
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition enhance_cpp.h:42
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition enhance_cpp.h:54
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
@ RADIANS
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
double_plus floot
#define ASSERT_EQUAL(a, b, test_name)
Definition unit_base.h:38
#define ASSERT_FALSE(a, test_name)
Definition unit_base.h:50