tribool_rename_test.cpp 2.7 KB

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