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 #include <boost/tuple/tuple.hpp>
30 using namespace ::basegfx
;
31 using namespace ::boost::tuples
;
33 namespace basegfxtools
36 class KeyStopLerpTest
: public CppUnit::TestFixture
38 tools::KeyStopLerp maKeyStops
;
40 static std::vector
<double> getTestVector()
42 std::vector
<double> aStops(3);
51 maKeyStops(getTestVector())
63 std::ptrdiff_t nIndex
;
65 tie(nIndex
,fAlpha
) = maKeyStops
.lerp(-1.0);
66 CPPUNIT_ASSERT_MESSAGE("-1.0", nIndex
==0 && fAlpha
==0.0);
68 tie(nIndex
,fAlpha
) = maKeyStops
.lerp(0.1);
69 CPPUNIT_ASSERT_MESSAGE("0.1", nIndex
==0 && fAlpha
==0.0);
71 tie(nIndex
,fAlpha
) = maKeyStops
.lerp(0.3);
72 CPPUNIT_ASSERT_MESSAGE("0.3", nIndex
==0 && fTools::equal(fAlpha
,0.5));
74 tie(nIndex
,fAlpha
) = maKeyStops
.lerp(0.5);
75 CPPUNIT_ASSERT_MESSAGE("0.5", nIndex
==0 && fTools::equal(fAlpha
,1.0));
77 tie(nIndex
,fAlpha
) = maKeyStops
.lerp(0.51);
78 CPPUNIT_ASSERT_MESSAGE("0.51", nIndex
==1 && fTools::equal(fAlpha
,0.025));
80 tie(nIndex
,fAlpha
) = maKeyStops
.lerp(0.9);
81 CPPUNIT_ASSERT_MESSAGE("0.51", nIndex
==1 && fTools::equal(fAlpha
,1.0));
83 tie(nIndex
,fAlpha
) = maKeyStops
.lerp(1.0);
84 CPPUNIT_ASSERT_MESSAGE("0.51", nIndex
==1 && fAlpha
==1.0);
87 // Change the following lines only, if you add, remove or rename
88 // member functions of the current class,
89 // because these macros are need by auto register mechanism.
91 CPPUNIT_TEST_SUITE(KeyStopLerpTest
);
93 CPPUNIT_TEST_SUITE_END();
96 // -----------------------------------------------------------------------------
97 CPPUNIT_TEST_SUITE_REGISTRATION(basegfxtools::KeyStopLerpTest
);
98 } // namespace basegfxtools
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */