feisty meow concerns codebase  2.140
test_double_plus.cpp
Go to the documentation of this file.
1 /*
2 * Name : test_double_plus
3 * Author : Chris Koeritz
4 * Purpose: Tests the double_plus class out.
5 **
6 * Copyright (c) 2001-$now By Author. This program is free software; you can *
7 * redistribute it and/or modify it under the terms of the GNU General Public *
8 * License as published by the Free Software Foundation; either version 2 of *
9 * the License or (at your option) any later version. This is online at: *
10 * http://www.fsf.org/copyleft/gpl.html *
11 * Please send any updates to: fred@gruntose.com *
12 */
13 
15 #include <basis/astring.h>
16 #include <geometric/angle.h>
20 #include <unit_test/unit_base.h>
21 
22 using namespace application;
23 using namespace basis;
24 using namespace geometric;
25 using namespace loggers;
26 using namespace mathematics;
27 using namespace structures;
28 using namespace unit_test;
29 
31 
32 class test_double_plus : public virtual unit_base, public virtual application_shell
33 {
34 public:
35  test_double_plus() : application_shell() {}
36  DEFINE_CLASS_NAME("test_double_plus");
37  virtual int execute();
38 };
39 
40 int test_double_plus::execute()
41 {
42  FUNCDEF("execute");
43  floot x1 = 43.8106392325;
44  floot x2 = 43.8106;
45  ASSERT_EQUAL(x1, x2, "these doubles should be close enough");
46 
47  floot y1 = 16.78;
48  floot y2 = 16.798273773;
49  ASSERT_INEQUAL(y1, y2, "these doubles shouldn't be close enough");
50 
51  floot z1(16.8, 0.1);
52  floot z2(16.798273773, 0.1);
53  ASSERT_EQUAL(a_sprintf("%.3f", z2.truncate()), astring("16.800"),
54  "truncate should calculate proper string");
55  ASSERT_EQUAL(z1, z2, "these doubles should be close enough with short delta");
56 
57  floot q1(16.75, 0.01);
58  floot q2(16.749273773, 0.01);
59  ASSERT_EQUAL(a_sprintf("%.3f", q2.truncate()), astring("16.750"),
60  "wider truncate should calculate proper string");
61  ASSERT_EQUAL(q1, q2, "next couple doubles should be close enough with small delta");
62 
63  return final_report();
64 }
65 
67 
68 HOOPLE_MAIN(test_double_plus, )
69 
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
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
#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
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_INEQUAL(a, b, test_name)
Definition: unit_base.h:42