diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-12-23 15:54:48 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-12-23 15:54:48 -0500 |
| commit | 0c516ea53898f35b81ad095abb6638aa41c78d63 (patch) | |
| tree | 2723ce4060eacf40ca46370af8ae85f435abb2f8 /sigcore/test/TestRange.cpp | |
| parent | c284b3d9011bcc51ca9bb5df5298756080ed5c2c (diff) | |
| download | sigen-0c516ea53898f35b81ad095abb6638aa41c78d63.tar.gz sigen-0c516ea53898f35b81ad095abb6638aa41c78d63.tar.xz sigen-0c516ea53898f35b81ad095abb6638aa41c78d63.zip | |
Added Range test class
Diffstat (limited to 'sigcore/test/TestRange.cpp')
| -rw-r--r-- | sigcore/test/TestRange.cpp | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/sigcore/test/TestRange.cpp b/sigcore/test/TestRange.cpp new file mode 100644 index 00000000..88e76c7a --- /dev/null +++ b/sigcore/test/TestRange.cpp @@ -0,0 +1,173 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Sicvore includes +#include "../Range.h" + +// QtTest includes +#include <QtTest/QTest> + +class TestRange : public QObject +{ + Q_OBJECT + + private slots: + void set(); + void setMinimum(); + void setMaximum(); + void valid(); + void in(); + void intersection(); + void setUnion(); + void negation(); + void addition(); + void subtraction(); + void multiplication(); + void division(); + void equality(); +}; + +void TestRange::set() +{ + Sigcore::Range range(4., 5.); + + QCOMPARE(range.minimum(), 4.); + QCOMPARE(range.maximum(), 5.); + + range.set(2., 9.); + + QCOMPARE(range.minimum(), 2.); + QCOMPARE(range.maximum(), 9.); +} + +void TestRange::setMinimum() +{ + Sigcore::Range range(0., 5.); + + range.setMinimum(2.); + + QCOMPARE(range.minimum(), 2.); + + range.setMinimum(7.); + + QCOMPARE(range.minimum(), 7.); + QCOMPARE(range.maximum(), 7.); +} + +void TestRange::setMaximum() +{ + Sigcore::Range range(3., 8.); + + range.setMaximum(5.); + + QCOMPARE(range.maximum(), 5.); + + range.setMaximum(1.); + + QCOMPARE(range.maximum(), 1.); + QCOMPARE(range.maximum(), 1.); +} + +void TestRange::valid() +{ + Sigcore::Range range(0., 5.); + + QCOMPARE(range.valid(), true); + + range.set(7., 5.); + + QCOMPARE(range.valid(), false); +} + +void TestRange::in() +{ + Sigcore::Range range(0., 5.); + + QCOMPARE(range.in(3.), true); + QCOMPARE(range.in(6.), false); + QCOMPARE(range.in(Sigcore::Range(4., 6.)), true); + QCOMPARE(range.in(Sigcore::Range(4., 6.)), false); +} + +void TestRange::intersection() +{ + Sigcore::Range range(0., 5.); + + QCOMPARE(range & Sigcore::Range(1., 3.), Sigcore::Range(1., 3.)); + QCOMPARE(range & Sigcore::Range(3., 6.), Sigcore::Range(3., 5.)); +} + +void TestRange::setUnion() +{ + Sigcore::Range range(0., 5.); + + QCOMPARE(range | Sigcore::Range(1., 3.), Sigcore::Range(0., 5.)); + QCOMPARE(range | Sigcore::Range(3., 6.), Sigcore::Range(0., 6.)); +} + +void TestRange::negation() +{ + Sigcore::Range range(1., 3.); + + QCOMPARE(-range, Sigcore::Range(-3., -1.)); +} + +void TestRange::addition() +{ + Sigcore::Range range(1., 3.); + + QCOMPARE(range + Sigcore::Range(2., 4.), Sigcore::Range(3., 7.)); + QCOMPARE(range + 2., Sigcore::Range(3., 5.)); +} + +void TestRange::subtraction() +{ + Sigcore::Range range(1., 3.); + + QCOMPARE(range - Sigcore::Range(2., 4.), Sigcore::Range(-3., 1.)); + QCOMPARE(range - 2., Sigcore::Range(-1., 1.)); +} + +void TestRange::multiplication() +{ + Sigcore::Range range(1., 3.); + + QCOMPARE(range * Sigcore::Range(2., 4.), Sigcore::Range(2., 12.)); + QCOMPARE(range * Sigcore::Range(-2., 4.), Sigcore::Range(-6., 12.)); + QCOMPARE(range * 2., Sigcore::Range(2., 6.)); + QCOMPARE(range * -2., Sigcore::Range(-6., -2.)); +} + +void TestRange::division() +{ + Sigcore::Range range(1., 3.); + + QCOMPARE(range / Sigcore::Range(2., 4.), Sigcore::Range(2., 12.)); + QCOMPARE((range / Sigcore::Range(-2., 4.)).valid(), false); + QCOMPARE(range / 2., Sigcore::Range(.5, 1.5)); + QCOMPARE(range / -2., Sigcore::Range(-1.5, -.5)); +} + +void TestRange::equality() +{ + Sigcore::Range range(1., 3.); + + QVERIFY(range == Sigcore::Range(1., 3.)); + QVERIFY(range != Sigcore::Range(1., 4.)); +} + +QTEST_APPLESS_MAIN(TestRange) |
