xref: /aoo41x/main/tools/test/tests.cxx (revision 89b56da7)
1*89b56da7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*89b56da7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*89b56da7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*89b56da7SAndrew Rist  * distributed with this work for additional information
6*89b56da7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*89b56da7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*89b56da7SAndrew Rist  * "License"); you may not use this file except in compliance
9*89b56da7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*89b56da7SAndrew Rist  *
11*89b56da7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*89b56da7SAndrew Rist  *
13*89b56da7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*89b56da7SAndrew Rist  * software distributed under the License is distributed on an
15*89b56da7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*89b56da7SAndrew Rist  * KIND, either express or implied.  See the License for the
17*89b56da7SAndrew Rist  * specific language governing permissions and limitations
18*89b56da7SAndrew Rist  * under the License.
19*89b56da7SAndrew Rist  *
20*89b56da7SAndrew Rist  *************************************************************/
21*89b56da7SAndrew Rist 
22*89b56da7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
26cdf0e10cSrcweir #include "precompiled_tools.hxx"
27cdf0e10cSrcweir // autogenerated file with codegen.pl
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <testshl/simpleheader.hxx>
30cdf0e10cSrcweir #include <rtl/math.hxx>
31cdf0e10cSrcweir #include <tools/fract.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <stdio.h>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace tools
36cdf0e10cSrcweir {
37cdf0e10cSrcweir 
38cdf0e10cSrcweir class FractionTest : public CppUnit::TestFixture
39cdf0e10cSrcweir {
40cdf0e10cSrcweir public:
41cdf0e10cSrcweir     void setUp()
42cdf0e10cSrcweir     {
43cdf0e10cSrcweir     }
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     void tearDown()
46cdf0e10cSrcweir     {
47cdf0e10cSrcweir     }
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     void testFraction()
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         const Fraction aFract(1082130431,1073741824);
52cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Fraction #1 not approximately equal to 1.007812499068677",
53cdf0e10cSrcweir                                 rtl::math::approxEqual((double)aFract,1.007812499068677) );
54cdf0e10cSrcweir 
55cdf0e10cSrcweir         Fraction aFract2( aFract );
56cdf0e10cSrcweir         aFract2.ReduceInaccurate(8);
57cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Fraction #2 not 1",
58cdf0e10cSrcweir                                 aFract2.GetNumerator() == 1 &&
59cdf0e10cSrcweir                                 aFract2.GetDenominator() == 1 );
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         Fraction aFract3( 0x7AAAAAAA, 0x35555555 );
62cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 cancellation wrong",
63cdf0e10cSrcweir                                 aFract3.GetNumerator() == 0x7AAAAAAA &&
64cdf0e10cSrcweir                                 aFract3.GetDenominator() == 0x35555555 );
65cdf0e10cSrcweir         aFract3.ReduceInaccurate(30);
66cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 ReduceInaccurate errorneously cut precision",
67cdf0e10cSrcweir                                 aFract3.GetNumerator() == 0x7AAAAAAA &&
68cdf0e10cSrcweir                                 aFract3.GetDenominator() == 0x35555555 );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         aFract3.ReduceInaccurate(29);
71cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 29 bits failed",
72cdf0e10cSrcweir                                 aFract3.GetNumerator() == 0x3D555555 &&
73cdf0e10cSrcweir                                 aFract3.GetDenominator() == 0x1AAAAAAA );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         aFract3.ReduceInaccurate(9);
76cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 9 bits failed",
77cdf0e10cSrcweir                                 aFract3.GetNumerator() == 0x0147 &&
78cdf0e10cSrcweir                                 aFract3.GetDenominator() == 0x008E );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir         aFract3.ReduceInaccurate(1);
81cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 1 bit failed",
82cdf0e10cSrcweir                                 aFract3.GetNumerator() == 2 &&
83cdf0e10cSrcweir                                 aFract3.GetDenominator() == 1 );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         aFract3.ReduceInaccurate(0);
86cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 0 bits failed",
87cdf0e10cSrcweir                                 aFract3.GetNumerator() == 2 &&
88cdf0e10cSrcweir                                 aFract3.GetDenominator() == 1 );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir #if SAL_TYPES_SIZEOFLONG == 8
91cdf0e10cSrcweir 		Fraction aFract4(0x7AAAAAAAAAAAAAAA, 0x3555555555555555);
92cdf0e10cSrcweir 		CPPUNIT_ASSERT_MESSAGE( "Fraction #4 cancellation wrong",
93cdf0e10cSrcweir 						        aFract4.GetNumerator() == 0x7AAAAAAAAAAAAAAA &&
94cdf0e10cSrcweir 								aFract4.GetDenominator() == 0x3555555555555555 );
95cdf0e10cSrcweir 		aFract4.ReduceInaccurate(62);
96cdf0e10cSrcweir 		CPPUNIT_ASSERT_MESSAGE( "Fraction #4 ReduceInaccurate errorneously cut precision",
97cdf0e10cSrcweir 								aFract4.GetNumerator() == 0x7AAAAAAAAAAAAAAA &&
98cdf0e10cSrcweir 								aFract4.GetDenominator() == 0x3555555555555555 );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 		aFract4.ReduceInaccurate(61);
101cdf0e10cSrcweir 		CPPUNIT_ASSERT_MESSAGE( "Fraction #4 ReduceInaccurate reduce to 61 bit failed",
102cdf0e10cSrcweir 								aFract4.GetNumerator() == 0x3D55555555555555 &&
103cdf0e10cSrcweir 								aFract4.GetDenominator() == 0x1AAAAAAAAAAAAAAA );
104cdf0e10cSrcweir #endif
105cdf0e10cSrcweir 	}
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(FractionTest);
108cdf0e10cSrcweir     CPPUNIT_TEST(testFraction);
109cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
110cdf0e10cSrcweir };
111cdf0e10cSrcweir 
112cdf0e10cSrcweir // -----------------------------------------------------------------------------
113cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(tools::FractionTest, "FractionTest");
114cdf0e10cSrcweir } // namespace tools
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 
117cdf0e10cSrcweir // -----------------------------------------------------------------------------
118cdf0e10cSrcweir 
119cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions()
120cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand.
121cdf0e10cSrcweir NOADDITIONAL;
122cdf0e10cSrcweir 
123