2 * Name : test_double_plus
3 * Author : Chris Koeritz
4 * Purpose: Tests the double_plus class out.
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 *
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>
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;
30 typedef double_plus floot;
32 class test_double_plus : public virtual unit_base, public virtual application_shell
35 test_double_plus() : application_shell() {}
36 DEFINE_CLASS_NAME("test_double_plus");
37 virtual int execute();
40 int test_double_plus::execute()
43 floot x1 = 43.8106392325;
45 ASSERT_EQUAL(x1, x2, "these doubles should be close enough");
48 floot y2 = 16.798273773;
49 ASSERT_INEQUAL(y1, y2, "these doubles shouldn't be close enough");
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");
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");
63 return final_report();
68 HOOPLE_MAIN(test_double_plus, )