nss: upgrade to release 3.73
[LibreOffice.git] / basegfx / test / basegfxtools.cxx
bloba768357c13a5159ba6cc5495c25e090c97bc21a9
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
31 class KeyStopLerpTest : public CppUnit::TestFixture
33 utils::KeyStopLerp maKeyStops;
35 static std::vector<double> getTestVector()
37 std::vector<double> aStops(3);
38 aStops[0] = 0.1;
39 aStops[1] = 0.5;
40 aStops[2] = 0.9;
41 return aStops;
44 public:
45 KeyStopLerpTest()
46 : maKeyStops(getTestVector())
50 void test()
52 double fAlpha;
53 std::ptrdiff_t nIndex;
55 std::tie(nIndex, fAlpha) = maKeyStops.lerp(-1.0);
56 CPPUNIT_ASSERT_EQUAL_MESSAGE("-1.0", std::ptrdiff_t(0), nIndex);
57 CPPUNIT_ASSERT_EQUAL_MESSAGE("-1.0", 0.0, fAlpha);
59 std::tie(nIndex, fAlpha) = maKeyStops.lerp(0.1);
60 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.1", std::ptrdiff_t(0), nIndex);
61 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.1", 0.0, fAlpha);
63 std::tie(nIndex, fAlpha) = maKeyStops.lerp(0.3);
64 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.3", std::ptrdiff_t(0), nIndex);
65 CPPUNIT_ASSERT_MESSAGE("0.3", fTools::equal(fAlpha, 0.5));
67 std::tie(nIndex, fAlpha) = maKeyStops.lerp(0.5);
68 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.5", std::ptrdiff_t(0), nIndex);
69 CPPUNIT_ASSERT_MESSAGE("0.5", fTools::equal(fAlpha, 1.0));
71 std::tie(nIndex, fAlpha) = maKeyStops.lerp(0.51);
72 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.51", std::ptrdiff_t(1), nIndex);
73 CPPUNIT_ASSERT_MESSAGE("0.51", fTools::equal(fAlpha, 0.025));
75 std::tie(nIndex, fAlpha) = maKeyStops.lerp(0.9);
76 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.51", std::ptrdiff_t(1), nIndex);
77 CPPUNIT_ASSERT_MESSAGE("0.51", fTools::equal(fAlpha, 1.0));
79 std::tie(nIndex, fAlpha) = maKeyStops.lerp(1.0);
80 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.51", std::ptrdiff_t(1), nIndex);
81 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("0.51", 1.0, fAlpha, 1E-12);
84 // Change the following lines only, if you add, remove or rename
85 // member functions of the current class,
86 // because these macros are need by auto register mechanism.
88 CPPUNIT_TEST_SUITE(KeyStopLerpTest);
89 CPPUNIT_TEST(test);
90 CPPUNIT_TEST_SUITE_END();
93 CPPUNIT_TEST_SUITE_REGISTRATION(basegfxtools::KeyStopLerpTest);
94 } // namespace basegfxtools
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */