• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

test/TestDecimal.cpp

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #include <spl/Debug.h>
00018 
00019 #ifdef DEBUG
00020 #include <spl/Decimal.h>
00021 #include <spl/Log.h>
00022 
00023 static void _TestDecimal1()
00024 {
00025         Decimal d(0.65);
00026         UNIT_ASSERT("double", d.ToDouble() == 0.65);
00027         UNIT_ASSERT("string", d.ToString()->Equals("0.6500"));
00028         UNIT_ASSERT("int", d.ToInt() == 0);
00029 
00030         DEBUG_CLEAR_MEM_CHECK_POINTS();
00031         DEBUG_DUMP_MEM_LEAKS();
00032         UNIT_ASSERT_MEM_NOTED("Date test 1.0");
00033 
00034         Log::SWriteOkFail( "Decimal test 1" );
00035 }
00036 
00037 static void _TestDecimal2()
00038 {
00039         Decimal d1(0.65);
00040         Decimal d2(0.25);
00041 
00042         Decimal sum = d1 + d2;
00043         UNIT_ASSERT("sum", sum.ToDouble() == 0.9);
00044 
00045         Decimal dif = d1 - d2;
00046         UNIT_ASSERT("diff", dif.ToDouble() == 0.4);
00047 
00048         Decimal product = d1 * 2;
00049         UNIT_ASSERT("*", product.ToDouble() == 1.3);
00050 
00051         product = d1 / 5;
00052         UNIT_ASSERT("/", product.ToDouble() == 0.13);
00053 
00054         UNIT_ASSERT("==", product == 0.13);
00055         UNIT_ASSERT("==", !(d1 == d2));
00056         UNIT_ASSERT("!=", (d1 != d2));
00057         UNIT_ASSERT(">", (d1 > d2));
00058         UNIT_ASSERT("<", !(d1 < d2));
00059         UNIT_ASSERT(">=", (d1 >= d2));
00060         UNIT_ASSERT("<=", !(d1 <= d2));
00061 
00062         d1 = 0.25;
00063         UNIT_ASSERT("==", d1 == 0.25);
00064         UNIT_ASSERT("==", (d1 == d2));
00065         UNIT_ASSERT("!=", !(d1 != d2));
00066         UNIT_ASSERT(">", !(d1 > d2));
00067         UNIT_ASSERT("<", !(d1 < d2));
00068         UNIT_ASSERT(">=", (d1 >= d2));
00069         UNIT_ASSERT("<=", (d1 <= d2));
00070 
00071         Log::SWriteOkFail( "Decimal test 2" );
00072 }
00073 
00074 void _TestDecimal()
00075 {
00076         _TestDecimal1();
00077         DEBUG_CLEAR_MEM_CHECK_POINTS();
00078         DEBUG_DUMP_MEM_LEAKS();
00079 
00080         _TestDecimal2();
00081         DEBUG_CLEAR_MEM_CHECK_POINTS();
00082         DEBUG_DUMP_MEM_LEAKS();
00083 }
00084 
00085 
00086 #endif