tests.cxx (32f0a145) tests.cxx (7969c931)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 10 unchanged lines hidden (view full) ---

19 *
20 *************************************************************/
21
22
23// MARKER(update_precomp.py): autogen include statement, do not remove
24#include "precompiled_tools.hxx"
25// autogenerated file with codegen.pl
26
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 10 unchanged lines hidden (view full) ---

19 *
20 *************************************************************/
21
22
23// MARKER(update_precomp.py): autogen include statement, do not remove
24#include "precompiled_tools.hxx"
25// autogenerated file with codegen.pl
26
27#include <testshl/simpleheader.hxx>
27#include "gtest/gtest.h"
28#include <rtl/math.hxx>
29#include <tools/fract.hxx>
30
31#include <stdio.h>
32
33namespace tools
34{
35
28#include <rtl/math.hxx>
29#include <tools/fract.hxx>
30
31#include <stdio.h>
32
33namespace tools
34{
35
36class FractionTest : public CppUnit::TestFixture
36class FractionTest : public ::testing::Test
37{
38public:
37{
38public:
39 void setUp()
39 void SetUp()
40 {
41 }
42
40 {
41 }
42
43 void tearDown()
43 void TearDown()
44 {
45 }
44 {
45 }
46};
46
47
47 void testFraction()
48 {
49 const Fraction aFract(1082130431,1073741824);
50 CPPUNIT_ASSERT_MESSAGE( "Fraction #1 not approximately equal to 1.007812499068677",
51 rtl::math::approxEqual((double)aFract,1.007812499068677) );
48TEST_F(FractionTest, testFraction)
49{
50 const Fraction aFract(1082130431,1073741824);
51 ASSERT_TRUE(rtl::math::approxEqual((double)aFract,1.007812499068677)) << "Fraction #1 not approximately equal to 1.007812499068677";
52
52
53 Fraction aFract2( aFract );
54 aFract2.ReduceInaccurate(8);
55 CPPUNIT_ASSERT_MESSAGE( "Fraction #2 not 1",
56 aFract2.GetNumerator() == 1 &&
57 aFract2.GetDenominator() == 1 );
53 Fraction aFract2( aFract );
54 aFract2.ReduceInaccurate(8);
55 ASSERT_TRUE(aFract2.GetNumerator() == 1 &&
56 aFract2.GetDenominator() == 1) << "Fraction #2 not 1";
58
57
59 Fraction aFract3( 0x7AAAAAAA, 0x35555555 );
60 CPPUNIT_ASSERT_MESSAGE( "Fraction #3 cancellation wrong",
61 aFract3.GetNumerator() == 0x7AAAAAAA &&
62 aFract3.GetDenominator() == 0x35555555 );
63 aFract3.ReduceInaccurate(30);
64 CPPUNIT_ASSERT_MESSAGE( "Fraction #3 ReduceInaccurate errorneously cut precision",
65 aFract3.GetNumerator() == 0x7AAAAAAA &&
66 aFract3.GetDenominator() == 0x35555555 );
58 Fraction aFract3( 0x7AAAAAAA, 0x35555555 );
59 ASSERT_TRUE(aFract3.GetNumerator() == 0x7AAAAAAA &&
60 aFract3.GetDenominator() == 0x35555555) << "Fraction #3 cancellation wrong";
61 aFract3.ReduceInaccurate(30);
62 ASSERT_TRUE(aFract3.GetNumerator() == 0x7AAAAAAA &&
63 aFract3.GetDenominator() == 0x35555555) << "Fraction #3 ReduceInaccurate errorneously cut precision";
67
64
68 aFract3.ReduceInaccurate(29);
69 CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 29 bits failed",
70 aFract3.GetNumerator() == 0x3D555555 &&
71 aFract3.GetDenominator() == 0x1AAAAAAA );
65 aFract3.ReduceInaccurate(29);
66 ASSERT_TRUE(aFract3.GetNumerator() == 0x3D555555 &&
67 aFract3.GetDenominator() == 0x1AAAAAAA) << "Fraction #3 reduce to 29 bits failed";
72
68
73 aFract3.ReduceInaccurate(9);
74 CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 9 bits failed",
75 aFract3.GetNumerator() == 0x0147 &&
76 aFract3.GetDenominator() == 0x008E );
69 aFract3.ReduceInaccurate(9);
70 ASSERT_TRUE(aFract3.GetNumerator() == 0x0147 &&
71 aFract3.GetDenominator() == 0x008E) << "Fraction #3 reduce to 9 bits failed";
77
72
78 aFract3.ReduceInaccurate(1);
79 CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 1 bit failed",
80 aFract3.GetNumerator() == 2 &&
81 aFract3.GetDenominator() == 1 );
73 aFract3.ReduceInaccurate(1);
74 ASSERT_TRUE(aFract3.GetNumerator() == 2 &&
75 aFract3.GetDenominator() == 1) << "Fraction #3 reduce to 1 bit failed";
82
76
83 aFract3.ReduceInaccurate(0);
84 CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 0 bits failed",
85 aFract3.GetNumerator() == 2 &&
86 aFract3.GetDenominator() == 1 );
77 aFract3.ReduceInaccurate(0);
78 ASSERT_TRUE(aFract3.GetNumerator() == 2 &&
79 aFract3.GetDenominator() == 1) << "Fraction #3 reduce to 0 bits failed";
87
88#if SAL_TYPES_SIZEOFLONG == 8
80
81#if SAL_TYPES_SIZEOFLONG == 8
89 Fraction aFract4(0x7AAAAAAAAAAAAAAA, 0x3555555555555555);
90 CPPUNIT_ASSERT_MESSAGE( "Fraction #4 cancellation wrong",
91 aFract4.GetNumerator() == 0x7AAAAAAAAAAAAAAA &&
92 aFract4.GetDenominator() == 0x3555555555555555 );
93 aFract4.ReduceInaccurate(62);
94 CPPUNIT_ASSERT_MESSAGE( "Fraction #4 ReduceInaccurate errorneously cut precision",
95 aFract4.GetNumerator() == 0x7AAAAAAAAAAAAAAA &&
96 aFract4.GetDenominator() == 0x3555555555555555 );
82 Fraction aFract4(0x7AAAAAAAAAAAAAAA, 0x3555555555555555);
83 ASSERT_TRUE(aFract4.GetNumerator() == 0x7AAAAAAAAAAAAAAA &&
84 aFract4.GetDenominator() == 0x3555555555555555) << "Fraction #4 cancellation wrong";
85 aFract4.ReduceInaccurate(62);
86 ASSERT_TRUE(aFract4.GetNumerator() == 0x7AAAAAAAAAAAAAAA &&
87 aFract4.GetDenominator() == 0x3555555555555555) << "Fraction #4 ReduceInaccurate errorneously cut precision";
97
88
98 aFract4.ReduceInaccurate(61);
99 CPPUNIT_ASSERT_MESSAGE( "Fraction #4 ReduceInaccurate reduce to 61 bit failed",
100 aFract4.GetNumerator() == 0x3D55555555555555 &&
101 aFract4.GetDenominator() == 0x1AAAAAAAAAAAAAAA );
89 aFract4.ReduceInaccurate(61);
90 ASSERT_TRUE(aFract4.GetNumerator() == 0x3D55555555555555 &&
91 aFract4.GetDenominator() == 0x1AAAAAAAAAAAAAAA) << "Fraction #4 ReduceInaccurate reduce to 61 bit failed";
102#endif
92#endif
103 }
93}
104
94
105 CPPUNIT_TEST_SUITE(FractionTest);
106 CPPUNIT_TEST(testFraction);
107 CPPUNIT_TEST_SUITE_END();
108};
109
110// -----------------------------------------------------------------------------
111CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(tools::FractionTest, "FractionTest");
112} // namespace tools
113
114
95} // namespace tools
96
97
115// -----------------------------------------------------------------------------
116
117// this macro creates an empty function, which will called by the RegisterAllFunctions()
118// to let the user the possibility to also register some functions by hand.
119NOADDITIONAL;
120
98int main(int argc, char **argv)
99{
100 ::testing::InitGoogleTest(&argc, argv);
101 return RUN_ALL_TESTS();
102}