[mlpack-svn] r15047 - mlpack/trunk/src/mlpack/tests

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri May 10 15:20:57 EDT 2013


Author: rcurtin
Date: 2013-05-10 15:20:57 -0400 (Fri, 10 May 2013)
New Revision: 15047

Modified:
   mlpack/trunk/src/mlpack/tests/math_test.cpp
Log:
Finally add test for Range::Contains(Range).


Modified: mlpack/trunk/src/mlpack/tests/math_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/math_test.cpp	2013-05-10 19:20:36 UTC (rev 15046)
+++ mlpack/trunk/src/mlpack/tests/math_test.cpp	2013-05-10 19:20:57 UTC (rev 15047)
@@ -522,4 +522,60 @@
   BOOST_REQUIRE(x.Contains(10.0));
 }
 
+/**
+ * Test that Range::Contains() works on other Ranges.  It should return false
+ * unless the ranges overlap at all.
+ */
+BOOST_AUTO_TEST_CASE(RangeContainsRange)
+{
+  // Empty ranges should not contain each other.
+  Range a;
+  Range b;
+
+  BOOST_REQUIRE_EQUAL(a.Contains(b), false);
+  BOOST_REQUIRE_EQUAL(b.Contains(a), false);
+
+  // Completely disparate ranges.
+  a = Range(-5.0, -3.0);
+  b = Range(3.0, 5.0);
+
+  BOOST_REQUIRE_EQUAL(a.Contains(b), false);
+  BOOST_REQUIRE_EQUAL(b.Contains(a), false);
+
+  // Overlapping at the end-point; this is containment of the end point.
+  a = Range(-5.0, 0.0);
+  b = Range(0.0, 5.0);
+
+  BOOST_REQUIRE_EQUAL(a.Contains(b), true);
+  BOOST_REQUIRE_EQUAL(b.Contains(a), true);
+
+  // Partially overlapping.
+  a = Range(-5.0, 2.0);
+  b = Range(-2.0, 5.0);
+
+  BOOST_REQUIRE_EQUAL(a.Contains(b), true);
+  BOOST_REQUIRE_EQUAL(b.Contains(a), true);
+
+  // One range encloses the other.
+  a = Range(-5.0, 5.0);
+  b = Range(-3.0, 3.0);
+
+  BOOST_REQUIRE_EQUAL(a.Contains(b), true);
+  BOOST_REQUIRE_EQUAL(b.Contains(a), true);
+
+  // Identical ranges.
+  a = Range(-3.0, 3.0);
+  b = Range(-3.0, 3.0);
+
+  BOOST_REQUIRE_EQUAL(a.Contains(b), true);
+  BOOST_REQUIRE_EQUAL(b.Contains(a), true);
+
+  // Single-point ranges.
+  a = Range(0.0, 0.0);
+  b = Range(0.0, 0.0);
+
+  BOOST_REQUIRE_EQUAL(a.Contains(b), true);
+  BOOST_REQUIRE_EQUAL(b.Contains(a), true);
+}
+
 BOOST_AUTO_TEST_SUITE_END();




More information about the mlpack-svn mailing list