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/TestAssert.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
24 #include <basegfx/range/b1drange.hxx>
28 class b1Xrange
: public CppUnit::TestFixture
31 template <class Type
> void implCheck()
33 // test interval axioms
34 // (http://en.wikipedia.org/wiki/Interval_%28mathematics%29)
36 CPPUNIT_ASSERT_MESSAGE("default ctor - empty range", aRange
.isEmpty());
37 CPPUNIT_ASSERT_MESSAGE("center - get cop-out value since range is empty",
38 aRange
.getCenter() == 0);
40 // degenerate interval
42 CPPUNIT_ASSERT_MESSAGE("degenerate range - still, not empty!", !aRange
.isEmpty());
43 CPPUNIT_ASSERT_MESSAGE("degenerate range - size of 0", aRange
.getRange() == 0);
44 CPPUNIT_ASSERT_MESSAGE("same value as degenerate range - is inside range",
46 CPPUNIT_ASSERT_MESSAGE("center - must be the single range value", aRange
.getCenter() == 1);
50 CPPUNIT_ASSERT_MESSAGE("proper range - size of 1", aRange
.getRange() == 1);
51 CPPUNIT_ASSERT_MESSAGE("smaller value of range - is inside *closed* range",
53 CPPUNIT_ASSERT_MESSAGE("larger value of range - is inside *closed* range",
56 // center for proper interval that works for ints, too
58 CPPUNIT_ASSERT_MESSAGE("center - must be half of the range", aRange
.getCenter() == 2);
62 CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound",
63 aRange
.overlaps(aRange2
));
64 CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound, but only barely",
65 !aRange
.overlapsMore(aRange2
));
68 CPPUNIT_ASSERT_MESSAGE("range overlapping is fully overlapping now",
69 aRange
.overlapsMore(aRange3
));
73 aRange
.intersect(aRange4
);
74 CPPUNIT_ASSERT_MESSAGE("range intersection is yielding empty range!", !aRange
.isEmpty());
77 aRange
.intersect(aRange5
);
78 CPPUNIT_ASSERT_MESSAGE("range intersection is yielding nonempty range!", aRange
.isEmpty());
81 void check() { implCheck
<B1DRange
>(); }
83 // Change the following lines only, if you add, remove or rename
84 // member functions of the current class,
85 // because these macros are need by auto register mechanism.
87 CPPUNIT_TEST_SUITE(b1Xrange
);
89 CPPUNIT_TEST_SUITE_END();
92 } // namespace basegfx
94 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::b1Xrange
);
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */