Bump version to 6.4-15
[LibreOffice.git] / basegfx / test / basegfxtools.cxx
blob7259a9980c70ac506581e00d1e74694988921221
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/TestAssert.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
24 #include <basegfx/utils/keystoplerp.hxx>
25 #include <basegfx/numeric/ftools.hxx>
27 using namespace ::basegfx;
29 namespace basegfxtools
32 class KeyStopLerpTest : public CppUnit::TestFixture
34 utils::KeyStopLerp maKeyStops;
36 static std::vector<double> getTestVector()
38 std::vector<double> aStops(3);
39 aStops[0] = 0.1;
40 aStops[1] = 0.5;
41 aStops[2] = 0.9;
42 return aStops;
45 public:
46 KeyStopLerpTest() :
47 maKeyStops(getTestVector())
51 void test()
53 double fAlpha;
54 std::ptrdiff_t nIndex;
56 std::tie(nIndex,fAlpha) = maKeyStops.lerp(-1.0);
57 CPPUNIT_ASSERT_EQUAL_MESSAGE("-1.0", std::ptrdiff_t(0), nIndex);
58 CPPUNIT_ASSERT_EQUAL_MESSAGE("-1.0", 0.0, fAlpha);
60 std::tie(nIndex,fAlpha) = maKeyStops.lerp(0.1);
61 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.1", std::ptrdiff_t(0), nIndex);
62 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.1", 0.0, fAlpha);
64 std::tie(nIndex,fAlpha) = maKeyStops.lerp(0.3);
65 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.3", std::ptrdiff_t(0), nIndex);
66 CPPUNIT_ASSERT_MESSAGE("0.3", fTools::equal(fAlpha,0.5));
68 std::tie(nIndex,fAlpha) = maKeyStops.lerp(0.5);
69 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.5", std::ptrdiff_t(0), nIndex);
70 CPPUNIT_ASSERT_MESSAGE("0.5", fTools::equal(fAlpha,1.0));
72 std::tie(nIndex,fAlpha) = maKeyStops.lerp(0.51);
73 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.51", std::ptrdiff_t(1), nIndex);
74 CPPUNIT_ASSERT_MESSAGE("0.51", fTools::equal(fAlpha,0.025));
76 std::tie(nIndex,fAlpha) = maKeyStops.lerp(0.9);
77 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.51", std::ptrdiff_t(1), nIndex);
78 CPPUNIT_ASSERT_MESSAGE("0.51", fTools::equal(fAlpha,1.0));
80 std::tie(nIndex,fAlpha) = maKeyStops.lerp(1.0);
81 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.51", std::ptrdiff_t(1), nIndex);
82 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("0.51", 1.0, fAlpha, 1E-12);
85 // Change the following lines only, if you add, remove or rename
86 // member functions of the current class,
87 // because these macros are need by auto register mechanism.
89 CPPUNIT_TEST_SUITE(KeyStopLerpTest);
90 CPPUNIT_TEST(test);
91 CPPUNIT_TEST_SUITE_END();
94 CPPUNIT_TEST_SUITE_REGISTRATION(basegfxtools::KeyStopLerpTest);
95 } // namespace basegfxtools
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */