716a14b13f23ea4982ea9db24a3910515a5adea9
[feisty_meow.git] / nucleus / library / tests_timely / test_earth_time.cpp
1 /*
2 *  Name   : test_earth_time                                                   *
3 *  Author : Chris Koeritz                                                     *
4 **
5 * Copyright (c) 2007-$now By Author.  This program is free software; you can  *
6 * redistribute it and/or modify it under the terms of the GNU General Public  *
7 * License as published by the Free Software Foundation; either version 2 of   *
8 * the License or (at your option) any later version.  This is online at:      *
9 *     http://www.fsf.org/copyleft/gpl.html                                    *
10 * Please send any updates to: fred@gruntose.com                               *
11 */
12
13 #define DEBUG_EARTH_TIME
14   // set this to enable debugging features of the string class.
15
16 #include <application/hoople_main.h>
17 #include <basis/functions.h>
18 #include <basis/guards.h>
19 #include <basis/astring.h>
20 #include <loggers/file_logger.h>
21 #include <mathematics/chaos.h>
22 #include <structures/static_memory_gremlin.h>
23 #include <timely/earth_time.h>
24 #include <timely/time_stamp.h>
25 #include <unit_test/unit_base.h>
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 using namespace application;
32 using namespace basis;
33 using namespace mathematics;
34 using namespace filesystem;
35 using namespace loggers;
36 using namespace structures;
37 using namespace textual;
38 using namespace timely;
39 using namespace unit_test;
40
41 #undef LOG
42 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
43 #undef BASE_LOG
44 #define BASE_LOG(s) STAMPED_EMERGENCY_LOG(program_wide_logger::get(), s)
45
46 const int TIME_FORMAT = clock_time::MERIDIAN | clock_time::SECONDS
47     | clock_time::MILLISECONDS;
48   // the way we like to see our seconds get printed out.
49
50 //////////////
51
52 class test_earth_time : virtual public unit_base, virtual public application_shell
53 {
54 public:
55   test_earth_time() {}
56   DEFINE_CLASS_NAME("test_earth_time");
57
58   virtual int execute();
59
60   void run_test_01();
61   void run_test_02();
62 };
63
64 //////////////
65
66 void test_earth_time::run_test_01()
67 {
68   FUNCDEF("run_test_01");
69   // this test makes sure that clock_time's normalize is working as expected.
70
71   time_locus checker_1(clock_time(12, 0, 60), day_in_year(), 2007);
72   clock_time::normalize(checker_1);
73   time_locus compare_1(clock_time(12, 1, 0), day_in_year(), 2007);
74 //BASE_LOG(astring("a=") + checker_1.text_form(TIME_FORMAT));
75 //BASE_LOG(astring("b=") + compare_1.text_form(TIME_FORMAT));
76   ASSERT_EQUAL(checker_1, compare_1, "normalize should not fail test 1");
77
78   time_locus checker_2(clock_time(12, 0, -1), day_in_year(), 2007);
79   clock_time::normalize(checker_2);
80   time_locus compare_2(clock_time(11, 59, 59), day_in_year(), 2007);
81   ASSERT_EQUAL(checker_2, compare_2, "normalize should not fail test 2");
82
83   time_locus checker_3(clock_time(11, 59, 61), day_in_year(), 2007);
84   clock_time::normalize(checker_3);
85   time_locus compare_3(clock_time(12, 00, 01), day_in_year(), 2007);
86   ASSERT_EQUAL(checker_3, compare_3, "normalize should not fail test 3");
87
88   time_locus checker_4(clock_time(12, 54, -61), day_in_year(), 2007);
89   clock_time::normalize(checker_4);
90   time_locus compare_4(clock_time(12, 52, 59), day_in_year(), 2007);
91   ASSERT_EQUAL(checker_4, compare_4, "normalize should not fail test 4");
92
93   time_locus checker_5(clock_time(12, -32, -62), day_in_year(), 2007);
94   clock_time::normalize(checker_5);
95   time_locus compare_5(clock_time(11, 26, 58), day_in_year(), 2007);
96   ASSERT_EQUAL(checker_5, compare_5, "normalize should not fail test 5");
97 }
98
99 void test_earth_time::run_test_02()
100 {
101   FUNCDEF("run_test_02");
102   // this test makes sure that day_in_year's normalize is working as expected.
103
104   time_locus checker_1(clock_time(0, 0, -1), day_in_year(JANUARY, 1), 2007);
105   time_locus::normalize(checker_1);
106   time_locus compare_1(clock_time(23, 59, 59), day_in_year(DECEMBER, 31), 2006);
107 //BASE_LOG(astring("a=") + checker_1.text_form(TIME_FORMAT));
108 //BASE_LOG(astring("b=") + compare_1.text_form(TIME_FORMAT));
109   ASSERT_EQUAL(checker_1, compare_1, "normalize should not fail test 1");
110
111   time_locus checker_2(clock_time(23, 59, 60), day_in_year(DECEMBER, 31), 2007);
112   time_locus::normalize(checker_2);
113   time_locus compare_2(clock_time(0, 0, 0), day_in_year(JANUARY, 1), 2008);
114   ASSERT_EQUAL(checker_2, compare_2, "normalize should not fail test 2");
115
116
117 //add more cases!
118 //  test leap years
119 //  test lotso things.
120
121 }
122
123 int test_earth_time::execute()
124 {
125   FUNCDEF("execute");
126
127   run_test_01();
128   run_test_02(); 
129
130   return final_report();
131 }
132
133 //////////////
134
135 HOOPLE_MAIN(test_earth_time, )
136