summaryrefslogtreecommitdiffstats
path: root/sigcore
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-12-23 15:54:48 -0500
committerBen Boeckel <MathStuf@gmail.com>2008-12-23 15:54:48 -0500
commit0c516ea53898f35b81ad095abb6638aa41c78d63 (patch)
tree2723ce4060eacf40ca46370af8ae85f435abb2f8 /sigcore
parentc284b3d9011bcc51ca9bb5df5298756080ed5c2c (diff)
downloadsigen-0c516ea53898f35b81ad095abb6638aa41c78d63.tar.gz
sigen-0c516ea53898f35b81ad095abb6638aa41c78d63.tar.xz
sigen-0c516ea53898f35b81ad095abb6638aa41c78d63.zip
Added Range test class
Diffstat (limited to 'sigcore')
-rw-r--r--sigcore/test/CMakeLists.txt1
-rw-r--r--sigcore/test/TestRange.cpp173
2 files changed, 174 insertions, 0 deletions
diff --git a/sigcore/test/CMakeLists.txt b/sigcore/test/CMakeLists.txt
index 3fad7226..7af37ba1 100644
--- a/sigcore/test/CMakeLists.txt
+++ b/sigcore/test/CMakeLists.txt
@@ -5,3 +5,4 @@ SET(libraries
MAKE_TEST(Fraction libraries)
MAKE_TEST(Hat libraries)
MAKE_TEST(Matrix libraries)
+MAKE_TEST(Range libraries)
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)