1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cppunit/TestFixture.h>
21 #include <cppunit/extensions/HelperMacros.h>
23 #include <basegfx/tuple/b3dtuple.hxx>
24 #include <basegfx/tuple/b3ituple.hxx>
28 class B3DTupleTest
: public CppUnit::TestFixture
34 CPPUNIT_ASSERT_EQUAL(true, aTuple
.equalZero());
39 B3DTuple
aTuple(1.0, 1.0, 1.0);
40 CPPUNIT_ASSERT_EQUAL(true, aTuple
.equal({ 1.0, 1.0, 1.0 }));
41 CPPUNIT_ASSERT_EQUAL(false, aTuple
.equal({ 0.99, 0.99, 0.99 }));
44 void testOperatorAddition()
46 B3DTuple
aTuple(4.0, 8.0, 1.0);
47 aTuple
+= { 2.0, 3.0, 4.0 };
49 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.0, aTuple
.getX(), 1e-2);
50 CPPUNIT_ASSERT_DOUBLES_EQUAL(11.0, aTuple
.getY(), 1e-2);
51 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, aTuple
.getZ(), 1e-2);
53 B3ITuple
aTupleInt(4, 8, 1);
54 aTupleInt
+= { 2, 3, 4 };
56 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), aTupleInt
.getX());
57 CPPUNIT_ASSERT_EQUAL(sal_Int32(11), aTupleInt
.getY());
58 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aTupleInt
.getZ());
61 void testOperatorSubstraction()
63 B3DTuple
aTuple(4.0, 8.0, 1.0);
64 aTuple
-= { 2.0, 3.0, 4.0 };
66 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, aTuple
.getX(), 1e-2);
67 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, aTuple
.getY(), 1e-2);
68 CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.0, aTuple
.getZ(), 1e-2);
70 B3ITuple
aTupleInt(4, 8, 1);
71 aTupleInt
-= { 2, 3, 4 };
73 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aTupleInt
.getX());
74 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aTupleInt
.getY());
75 CPPUNIT_ASSERT_EQUAL(sal_Int32(-3), aTupleInt
.getZ());
78 void testOperatorMultiply()
80 B3DTuple
aTuple(4.0, 8.0, 1.0);
81 aTuple
*= { 2.0, 3.0, 4.0 };
83 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.0, aTuple
.getX(), 1e-2);
84 CPPUNIT_ASSERT_DOUBLES_EQUAL(24.0, aTuple
.getY(), 1e-2);
85 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0, aTuple
.getZ(), 1e-2);
89 CPPUNIT_ASSERT_DOUBLES_EQUAL(16.0, aTuple
.getX(), 1e-2);
90 CPPUNIT_ASSERT_DOUBLES_EQUAL(48.0, aTuple
.getY(), 1e-2);
91 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.0, aTuple
.getZ(), 1e-2);
93 B3ITuple
aTupleInt(4, 8, 1);
94 aTupleInt
*= { 2, 3, 4 };
96 CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aTupleInt
.getX());
97 CPPUNIT_ASSERT_EQUAL(sal_Int32(24), aTupleInt
.getY());
98 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aTupleInt
.getZ());
102 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), aTupleInt
.getX());
103 CPPUNIT_ASSERT_EQUAL(sal_Int32(48), aTupleInt
.getY());
104 CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aTupleInt
.getZ());
107 void testOperatorDivide()
109 B3DTuple
aTuple(4.0, 8.0, 9.0);
110 aTuple
/= { 2.0, 8.0, 3.0 };
112 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, aTuple
.getX(), 1e-2);
113 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, aTuple
.getY(), 1e-2);
114 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, aTuple
.getZ(), 1e-2);
116 B3ITuple
aTupleInt(4, 8, 9);
117 aTupleInt
/= { 2, 8, 3 };
119 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aTupleInt
.getX());
120 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aTupleInt
.getY());
121 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aTupleInt
.getZ());
124 void testOperatorEqualUnequal()
126 B3DTuple
aTuple(4.0, 8.0, 9.0);
127 B3DTuple aTuple2
= aTuple
;
129 CPPUNIT_ASSERT_EQUAL(true, aTuple
== aTuple
);
130 CPPUNIT_ASSERT_EQUAL(true, aTuple
== aTuple2
);
131 CPPUNIT_ASSERT_EQUAL(true, aTuple
== B3DTuple(4.0, 8.0, 9.0));
132 CPPUNIT_ASSERT_EQUAL(false, aTuple
== B3DTuple(4.0, 7.99, 9.0));
133 CPPUNIT_ASSERT_EQUAL(false, aTuple
== B3DTuple(3.99, 8.0, 9.0));
135 CPPUNIT_ASSERT_EQUAL(false, aTuple
!= aTuple
);
136 CPPUNIT_ASSERT_EQUAL(false, aTuple
!= aTuple2
);
137 CPPUNIT_ASSERT_EQUAL(false, aTuple
!= B3DTuple(4.0, 8.0, 9.0));
138 CPPUNIT_ASSERT_EQUAL(true, aTuple
!= B3DTuple(4.0, 7.99, 9.0));
139 CPPUNIT_ASSERT_EQUAL(true, aTuple
!= B3DTuple(3.99, 8.0, 9.0));
141 B3ITuple
aTupleInt(4, 8, 9);
142 B3ITuple aTupleInt2
= aTupleInt
;
144 CPPUNIT_ASSERT_EQUAL(true, aTupleInt
== aTupleInt
);
145 CPPUNIT_ASSERT_EQUAL(true, aTupleInt
== aTupleInt2
);
146 CPPUNIT_ASSERT_EQUAL(true, aTupleInt
== B3ITuple(4, 8, 9));
147 CPPUNIT_ASSERT_EQUAL(false, aTupleInt
== B3ITuple(4, 7, 9));
148 CPPUNIT_ASSERT_EQUAL(false, aTupleInt
== B3ITuple(3, 8, 9));
150 CPPUNIT_ASSERT_EQUAL(false, aTupleInt
!= aTupleInt
);
151 CPPUNIT_ASSERT_EQUAL(false, aTupleInt
!= aTupleInt2
);
152 CPPUNIT_ASSERT_EQUAL(false, aTupleInt
!= B3ITuple(4, 8, 9));
153 CPPUNIT_ASSERT_EQUAL(true, aTupleInt
!= B3ITuple(4, 7, 9));
154 CPPUNIT_ASSERT_EQUAL(true, aTupleInt
!= B3ITuple(3, 8, 9));
157 void testOperatorMinus()
159 B3DTuple aTupleMinus
= -B3DTuple(4.0, 8.0, 1.0);
160 CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.0, aTupleMinus
.getX(), 1e-2);
161 CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.0, aTupleMinus
.getY(), 1e-2);
162 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, aTupleMinus
.getZ(), 1e-2);
163 B3DTuple aTupleZero
= -B3DTuple(0.0, 0.0, 0.0);
164 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, aTupleZero
.getX(), 1e-2);
165 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, aTupleZero
.getY(), 1e-2);
166 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, aTupleZero
.getZ(), 1e-2);
168 B3ITuple aTupleIntMinus
= -B3ITuple(4, 8, 1);
169 CPPUNIT_ASSERT_EQUAL(sal_Int32(-4), aTupleIntMinus
.getX());
170 CPPUNIT_ASSERT_EQUAL(sal_Int32(-8), aTupleIntMinus
.getY());
171 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aTupleIntMinus
.getZ());
172 B3ITuple aTupleIntZero
= -B3ITuple(0, 0, 0);
173 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aTupleIntZero
.getX());
174 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aTupleIntZero
.getY());
175 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aTupleIntZero
.getZ());
178 CPPUNIT_TEST_SUITE(B3DTupleTest
);
179 CPPUNIT_TEST(testEmpty
);
180 CPPUNIT_TEST(testEquals
);
181 CPPUNIT_TEST(testOperatorAddition
);
182 CPPUNIT_TEST(testOperatorSubstraction
);
183 CPPUNIT_TEST(testOperatorMultiply
);
184 CPPUNIT_TEST(testOperatorDivide
);
185 CPPUNIT_TEST(testOperatorEqualUnequal
);
186 CPPUNIT_TEST(testOperatorMinus
);
187 CPPUNIT_TEST_SUITE_END();
190 } // namespace basegfx
192 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::B3DTupleTest
);
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */