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 <sal/types.h>
21 #include <cppunit/TestAssert.h>
22 #include <cppunit/TestFixture.h>
23 #include <cppunit/extensions/HelperMacros.h>
25 #include <basegfx/tools/keystoplerp.hxx>
26 #include <basegfx/numeric/ftools.hxx>
28 using namespace ::basegfx
;
30 namespace basegfxtools
33 class KeyStopLerpTest
: public CppUnit::TestFixture
35 tools::KeyStopLerp maKeyStops
;
37 static std::vector
<double> getTestVector()
39 std::vector
<double> aStops(3);
48 maKeyStops(getTestVector())
55 std::ptrdiff_t nIndex
;
57 std::tie(nIndex
,fAlpha
) = maKeyStops
.lerp(-1.0);
58 CPPUNIT_ASSERT_MESSAGE("-1.0", nIndex
==0 && fAlpha
==0.0);
60 std::tie(nIndex
,fAlpha
) = maKeyStops
.lerp(0.1);
61 CPPUNIT_ASSERT_MESSAGE("0.1", nIndex
==0 && fAlpha
==0.0);
63 std::tie(nIndex
,fAlpha
) = maKeyStops
.lerp(0.3);
64 CPPUNIT_ASSERT_MESSAGE("0.3", nIndex
==0 && fTools::equal(fAlpha
,0.5));
66 std::tie(nIndex
,fAlpha
) = maKeyStops
.lerp(0.5);
67 CPPUNIT_ASSERT_MESSAGE("0.5", nIndex
==0 && fTools::equal(fAlpha
,1.0));
69 std::tie(nIndex
,fAlpha
) = maKeyStops
.lerp(0.51);
70 CPPUNIT_ASSERT_MESSAGE("0.51", nIndex
==1 && fTools::equal(fAlpha
,0.025));
72 std::tie(nIndex
,fAlpha
) = maKeyStops
.lerp(0.9);
73 CPPUNIT_ASSERT_MESSAGE("0.51", nIndex
==1 && fTools::equal(fAlpha
,1.0));
75 std::tie(nIndex
,fAlpha
) = maKeyStops
.lerp(1.0);
76 CPPUNIT_ASSERT_MESSAGE("0.51", nIndex
==1 && fAlpha
==1.0);
79 // Change the following lines only, if you add, remove or rename
80 // member functions of the current class,
81 // because these macros are need by auto register mechanism.
83 CPPUNIT_TEST_SUITE(KeyStopLerpTest
);
85 CPPUNIT_TEST_SUITE_END();
88 CPPUNIT_TEST_SUITE_REGISTRATION(basegfxtools::KeyStopLerpTest
);
89 } // namespace basegfxtools
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */