lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [5806] Test relational operators for class minmax


From: Greg Chicares
Subject: [lmi-commits] [5806] Test relational operators for class minmax
Date: Sun, 27 Oct 2013 11:33:10 +0000

Revision: 5806
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5806
Author:   chicares
Date:     2013-10-27 11:32:56 +0000 (Sun, 27 Oct 2013)
Log Message:
-----------
Test relational operators for class minmax

Modified Paths:
--------------
    lmi/trunk/miscellany_test.cpp

Modified: lmi/trunk/miscellany_test.cpp
===================================================================
--- lmi/trunk/miscellany_test.cpp       2013-10-25 23:15:25 UTC (rev 5805)
+++ lmi/trunk/miscellany_test.cpp       2013-10-27 11:32:56 UTC (rev 5806)
@@ -30,7 +30,7 @@
 
 #include "test_tools.hpp"
 
-#include <cstdio> // std::remove()
+#include <cstdio>                       // std::remove()
 #include <fstream>
 
 void test_files_are_identical()
@@ -75,9 +75,34 @@
     BOOST_TEST(!files_are_identical(f0, f1));
 }
 
+void test_minmax()
+{
+    double const zero = 0.0;
+    double const one  = 1.0;
+
+    std::vector<double> w;
+    w.push_back(one );
+    w.push_back(zero);
+
+    // Test const-correctness.
+    std::vector<double> const v = w;
+    minmax<double> const m(v);
+    BOOST_TEST(zero == m.minimum());
+    BOOST_TEST(one  == m.maximum());
+
+    // Motivation for relational operators: to write this...
+    BOOST_TEST(zero <= m.minimum() && m.maximum() <= one);
+    // ...more compactly:
+#if !defined __BORLANDC__
+    BOOST_TEST(  zero <= m && m <= one );
+    BOOST_TEST(!(zero <  m || m <  one));
+#endif // !defined __BORLANDC__
+}
+
 int test_main(int, char*[])
 {
     test_files_are_identical();
+    test_minmax();
 
     return 0;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]