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 B1DRangeTest
: public CppUnit::TestFixture
31 void checkIntervalAxioms()
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_EQUAL_MESSAGE("center - get cop-out value since range is empty", 0.0,
40 // degenerate interval
42 CPPUNIT_ASSERT_EQUAL(B1DRange(1.0, 1.0), aRange
);
43 CPPUNIT_ASSERT_MESSAGE("degenerate range - still, not empty!", !aRange
.isEmpty());
44 CPPUNIT_ASSERT_EQUAL_MESSAGE("degenerate range - size of 0", 0.0, aRange
.getRange());
45 CPPUNIT_ASSERT_MESSAGE("same value as degenerate range - is inside range",
46 aRange
.isInside(1.0));
47 CPPUNIT_ASSERT_EQUAL_MESSAGE("center - must be the single range value", 1.0,
52 CPPUNIT_ASSERT_EQUAL(B1DRange(1.0, 2.0), aRange
);
53 CPPUNIT_ASSERT_EQUAL_MESSAGE("proper range - size of 1", 1.0, aRange
.getRange());
54 CPPUNIT_ASSERT_MESSAGE("smaller value of range - is inside *closed* range",
56 CPPUNIT_ASSERT_MESSAGE("larger value of range - is inside *closed* range",
59 // center for proper interval that works for ints, too
61 CPPUNIT_ASSERT_EQUAL(B1DRange(1.0, 3.0), aRange
);
62 CPPUNIT_ASSERT_EQUAL_MESSAGE("center - must be half of the range", 2.0, aRange
.getCenter());
67 B1DRange
aRange(1.0, 3.0);
68 B1DRange
aRange2(0.0, 1.0);
70 CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound",
71 aRange
.overlaps(aRange2
));
72 CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound, but only barely",
73 !aRange
.overlapsMore(aRange2
));
75 B1DRange
aRange3(0.0, 2.0);
76 CPPUNIT_ASSERT_MESSAGE("range overlapping is fully overlapping now",
77 aRange
.overlapsMore(aRange3
));
82 B1DRange
aRange(1.0, 3.0);
83 B1DRange
aRange2(3.0, 4.0);
84 aRange
.intersect(aRange2
);
85 CPPUNIT_ASSERT_MESSAGE("range intersection is yielding empty range!", !aRange
.isEmpty());
87 B1DRange
aRange3(5.0, 6.0);
88 aRange
.intersect(aRange3
);
89 CPPUNIT_ASSERT_MESSAGE("range intersection is yielding nonempty range!", aRange
.isEmpty());
92 CPPUNIT_TEST_SUITE(B1DRangeTest
);
93 CPPUNIT_TEST(checkIntervalAxioms
);
94 CPPUNIT_TEST(checkOverlap
);
95 CPPUNIT_TEST(checkIntersect
);
96 CPPUNIT_TEST_SUITE_END();
99 } // namespace basegfx
101 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::B1DRangeTest
);
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */