nss: upgrade to release 3.73
[LibreOffice.git] / basegfx / test / B1DRangeTest.cxx
blob22cf662defe5e11e10f4aca216462602fd0c03e5
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/range/b1drange.hxx>
26 namespace basegfx
28 class b1Xrange : public CppUnit::TestFixture
30 public:
31 template <class Type> void implCheck()
33 // test interval axioms
34 // (http://en.wikipedia.org/wiki/Interval_%28mathematics%29)
35 Type aRange;
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
41 aRange.expand(1);
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",
45 aRange.isInside(1));
46 CPPUNIT_ASSERT_MESSAGE("center - must be the single range value", aRange.getCenter() == 1);
48 // proper interval
49 aRange.expand(2);
50 CPPUNIT_ASSERT_MESSAGE("proper range - size of 1", aRange.getRange() == 1);
51 CPPUNIT_ASSERT_MESSAGE("smaller value of range - is inside *closed* range",
52 aRange.isInside(1));
53 CPPUNIT_ASSERT_MESSAGE("larger value of range - is inside *closed* range",
54 aRange.isInside(2));
56 // center for proper interval that works for ints, too
57 aRange.expand(3);
58 CPPUNIT_ASSERT_MESSAGE("center - must be half of the range", aRange.getCenter() == 2);
60 // check overlap
61 Type aRange2(0, 1);
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));
67 Type aRange3(0, 2);
68 CPPUNIT_ASSERT_MESSAGE("range overlapping is fully overlapping now",
69 aRange.overlapsMore(aRange3));
71 // check intersect
72 Type aRange4(3, 4);
73 aRange.intersect(aRange4);
74 CPPUNIT_ASSERT_MESSAGE("range intersection is yielding empty range!", !aRange.isEmpty());
76 Type aRange5(5, 6);
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);
88 CPPUNIT_TEST(check);
89 CPPUNIT_TEST_SUITE_END();
90 }; // class b1Xrange
92 } // namespace basegfx
94 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::b1Xrange);
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */