first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / tests_mathematics / test_double_plus.cpp
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
14 #include <application/hoople_main.h>
15 #include <basis/astring.h>
16 #include <geometric/angle.h>
17 #include <loggers/program_wide_logger.h>
18 #include <mathematics/double_plus.h>
19 #include <structures/static_memory_gremlin.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
30 typedef double_plus floot;
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
66 //////////////
67
68 HOOPLE_MAIN(test_double_plus, )
69