| 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 | #include <boost/logic/tribool.hpp> |
|---|
| 7 | #include <boost/test/minimal.hpp> |
|---|
| 8 | #include <iostream> |
|---|
| 9 | |
|---|
| 10 | int test_main(int, char*[]) |
|---|
| 11 | { |
|---|
| 12 | using namespace boost::logic; |
|---|
| 13 | |
|---|
| 14 | tribool x; // false |
|---|
| 15 | tribool y(true); // true |
|---|
| 16 | tribool z(indeterminate); // indeterminate |
|---|
| 17 | |
|---|
| 18 | BOOST_CHECK(!x); |
|---|
| 19 | BOOST_CHECK(x == false); |
|---|
| 20 | BOOST_CHECK(false == x); |
|---|
| 21 | BOOST_CHECK(x != true); |
|---|
| 22 | BOOST_CHECK(true != x); |
|---|
| 23 | BOOST_CHECK(indeterminate(x == indeterminate)); |
|---|
| 24 | BOOST_CHECK(indeterminate(indeterminate == x)); |
|---|
| 25 | BOOST_CHECK(indeterminate(x != indeterminate)); |
|---|
| 26 | BOOST_CHECK(indeterminate(indeterminate != x)); |
|---|
| 27 | BOOST_CHECK(x == x); |
|---|
| 28 | BOOST_CHECK(!(x != x)); |
|---|
| 29 | BOOST_CHECK(!(x && true)); |
|---|
| 30 | BOOST_CHECK(!(true && x)); |
|---|
| 31 | BOOST_CHECK(x || true); |
|---|
| 32 | BOOST_CHECK(true || x); |
|---|
| 33 | |
|---|
| 34 | BOOST_CHECK(y); |
|---|
| 35 | BOOST_CHECK(y == true); |
|---|
| 36 | BOOST_CHECK(true == y); |
|---|
| 37 | BOOST_CHECK(y != false); |
|---|
| 38 | BOOST_CHECK(false != y); |
|---|
| 39 | BOOST_CHECK(indeterminate(y == indeterminate)); |
|---|
| 40 | BOOST_CHECK(indeterminate(indeterminate == y)); |
|---|
| 41 | BOOST_CHECK(indeterminate(y != indeterminate)); |
|---|
| 42 | BOOST_CHECK(indeterminate(indeterminate != y)); |
|---|
| 43 | BOOST_CHECK(y == y); |
|---|
| 44 | BOOST_CHECK(!(y != y)); |
|---|
| 45 | |
|---|
| 46 | BOOST_CHECK(indeterminate(z || !z)); |
|---|
| 47 | BOOST_CHECK(indeterminate(z == true)); |
|---|
| 48 | BOOST_CHECK(indeterminate(true == z)); |
|---|
| 49 | BOOST_CHECK(indeterminate(z == false)); |
|---|
| 50 | BOOST_CHECK(indeterminate(false == z)); |
|---|
| 51 | BOOST_CHECK(indeterminate(z == indeterminate)); |
|---|
| 52 | BOOST_CHECK(indeterminate(indeterminate == z)); |
|---|
| 53 | BOOST_CHECK(indeterminate(z != indeterminate)); |
|---|
| 54 | BOOST_CHECK(indeterminate(indeterminate != z)); |
|---|
| 55 | BOOST_CHECK(indeterminate(z == z)); |
|---|
| 56 | BOOST_CHECK(indeterminate(z != z)); |
|---|
| 57 | |
|---|
| 58 | BOOST_CHECK(!(x == y)); |
|---|
| 59 | BOOST_CHECK(x != y); |
|---|
| 60 | BOOST_CHECK(indeterminate(x == z)); |
|---|
| 61 | BOOST_CHECK(indeterminate(x != z)); |
|---|
| 62 | BOOST_CHECK(indeterminate(y == z)); |
|---|
| 63 | BOOST_CHECK(indeterminate(y != z)); |
|---|
| 64 | |
|---|
| 65 | BOOST_CHECK(!(x && y)); |
|---|
| 66 | BOOST_CHECK(x || y); |
|---|
| 67 | BOOST_CHECK(!(x && z)); |
|---|
| 68 | BOOST_CHECK(indeterminate(y && z)); |
|---|
| 69 | BOOST_CHECK(indeterminate(z && z)); |
|---|
| 70 | BOOST_CHECK(indeterminate(z || z)); |
|---|
| 71 | BOOST_CHECK(indeterminate(x || z)); |
|---|
| 72 | BOOST_CHECK(y || z); |
|---|
| 73 | |
|---|
| 74 | BOOST_CHECK(indeterminate(y && indeterminate)); |
|---|
| 75 | BOOST_CHECK(indeterminate(indeterminate && y)); |
|---|
| 76 | BOOST_CHECK(!(x && indeterminate)); |
|---|
| 77 | BOOST_CHECK(!(indeterminate && x)); |
|---|
| 78 | |
|---|
| 79 | BOOST_CHECK(indeterminate || y); |
|---|
| 80 | BOOST_CHECK(y || indeterminate); |
|---|
| 81 | BOOST_CHECK(indeterminate(x || indeterminate)); |
|---|
| 82 | BOOST_CHECK(indeterminate(indeterminate || x)); |
|---|
| 83 | |
|---|
| 84 | // Test the if (z) ... else (!z) ... else ... idiom |
|---|
| 85 | if (z) { |
|---|
| 86 | BOOST_CHECK(false); |
|---|
| 87 | } |
|---|
| 88 | else if (!z) { |
|---|
| 89 | BOOST_CHECK(false); |
|---|
| 90 | } |
|---|
| 91 | else { |
|---|
| 92 | BOOST_CHECK(true); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | z = true; |
|---|
| 96 | if (z) { |
|---|
| 97 | BOOST_CHECK(true); |
|---|
| 98 | } |
|---|
| 99 | else if (!z) { |
|---|
| 100 | BOOST_CHECK(false); |
|---|
| 101 | } |
|---|
| 102 | else { |
|---|
| 103 | BOOST_CHECK(false); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | z = false; |
|---|
| 107 | if (z) { |
|---|
| 108 | BOOST_CHECK(false); |
|---|
| 109 | } |
|---|
| 110 | else if (!z) { |
|---|
| 111 | BOOST_CHECK(true); |
|---|
| 112 | } |
|---|
| 113 | else { |
|---|
| 114 | BOOST_CHECK(false); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | std::cout << "no errors detected\n"; |
|---|
| 118 | return 0; |
|---|
| 119 | } |
|---|