1 // Copyright Douglas Gregor 2002-2003. Use, modification and 2 // distribution is subject to the Boost Software License, Version 3 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 6 // For more information, see http://www.boost.org 7 8 #include <boost/logic/tribool.hpp> 9 #include <boost/test/minimal.hpp> 10 #include <iostream> 11 BOOST_TRIBOOL_THIRD_STATE(maybe)12BOOST_TRIBOOL_THIRD_STATE(maybe) 13 14 int test_main(int,char*[]) 15 { 16 using namespace boost::logic; 17 18 tribool x; // false 19 tribool y(true); // true 20 tribool z(maybe); // maybe 21 22 BOOST_CHECK(!x); 23 BOOST_CHECK(x == false); 24 BOOST_CHECK(false == x); 25 BOOST_CHECK(x != true); 26 BOOST_CHECK(true != x); 27 BOOST_CHECK(maybe(x == maybe)); 28 BOOST_CHECK(maybe(maybe == x)); 29 BOOST_CHECK(maybe(x != maybe)); 30 BOOST_CHECK(maybe(maybe != x)); 31 BOOST_CHECK(x == x); 32 BOOST_CHECK(!(x != x)); 33 BOOST_CHECK(!(x && true)); 34 BOOST_CHECK(!(true && x)); 35 BOOST_CHECK(x || true); 36 BOOST_CHECK(true || x); 37 38 BOOST_CHECK(y); 39 BOOST_CHECK(y == true); 40 BOOST_CHECK(true == y); 41 BOOST_CHECK(y != false); 42 BOOST_CHECK(false != y); 43 BOOST_CHECK(maybe(y == maybe)); 44 BOOST_CHECK(maybe(maybe == y)); 45 BOOST_CHECK(maybe(y != maybe)); 46 BOOST_CHECK(maybe(maybe != y)); 47 BOOST_CHECK(y == y); 48 BOOST_CHECK(!(y != y)); 49 50 BOOST_CHECK(maybe(z || !z)); 51 BOOST_CHECK(maybe(z == true)); 52 BOOST_CHECK(maybe(true == z)); 53 BOOST_CHECK(maybe(z == false)); 54 BOOST_CHECK(maybe(false == z)); 55 BOOST_CHECK(maybe(z == maybe)); 56 BOOST_CHECK(maybe(maybe == z)); 57 BOOST_CHECK(maybe(z != maybe)); 58 BOOST_CHECK(maybe(maybe != z)); 59 BOOST_CHECK(maybe(z == z)); 60 BOOST_CHECK(maybe(z != z)); 61 62 BOOST_CHECK(!(x == y)); 63 BOOST_CHECK(x != y); 64 BOOST_CHECK(maybe(x == z)); 65 BOOST_CHECK(maybe(x != z)); 66 BOOST_CHECK(maybe(y == z)); 67 BOOST_CHECK(maybe(y != z)); 68 69 BOOST_CHECK(!(x && y)); 70 BOOST_CHECK(x || y); 71 BOOST_CHECK(!(x && z)); 72 BOOST_CHECK(maybe(y && z)); 73 BOOST_CHECK(maybe(z && z)); 74 BOOST_CHECK(maybe(z || z)); 75 BOOST_CHECK(maybe(x || z)); 76 BOOST_CHECK(y || z); 77 78 BOOST_CHECK(maybe(y && maybe)); 79 BOOST_CHECK(maybe(maybe && y)); 80 BOOST_CHECK(!(x && maybe)); 81 BOOST_CHECK(!(maybe && x)); 82 83 BOOST_CHECK(maybe || y); 84 BOOST_CHECK(y || maybe); 85 BOOST_CHECK(maybe(x || maybe)); 86 BOOST_CHECK(maybe(maybe || x)); 87 88 // Test the if (z) ... else (!z) ... else ... idiom 89 if (z) { 90 BOOST_CHECK(false); 91 } 92 else if (!z) { 93 BOOST_CHECK(false); 94 } 95 else { 96 BOOST_CHECK(true); 97 } 98 99 z = true; 100 if (z) { 101 BOOST_CHECK(true); 102 } 103 else if (!z) { 104 BOOST_CHECK(false); 105 } 106 else { 107 BOOST_CHECK(false); 108 } 109 110 z = false; 111 if (z) { 112 BOOST_CHECK(false); 113 } 114 else if (!z) { 115 BOOST_CHECK(true); 116 } 117 else { 118 BOOST_CHECK(false); 119 } 120 121 std::cout << "no errors detected\n"; 122 return 0; 123 } 124