summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/logic/test/tribool_rename_test.cpp
blob: 3a5b066b31a859c46323cdaf1b4440d72a1e85b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright Douglas Gregor 2002-2003. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// For more information, see http://www.boost.org

#include <boost/logic/tribool.hpp>
#include <boost/test/minimal.hpp>
#include <iostream>

BOOST_TRIBOOL_THIRD_STATE(maybe)

int test_main(int,char*[])
{
  using namespace boost::logic;

  tribool x; // false
  tribool y(true); // true
  tribool z(maybe); // maybe

  BOOST_CHECK(!x);
  BOOST_CHECK(x == false);
  BOOST_CHECK(false == x);
  BOOST_CHECK(x != true);
  BOOST_CHECK(true != x);
  BOOST_CHECK(maybe(x == maybe));
  BOOST_CHECK(maybe(maybe == x));
  BOOST_CHECK(maybe(x != maybe));
  BOOST_CHECK(maybe(maybe != x));
  BOOST_CHECK(x == x);
  BOOST_CHECK(!(x != x));
  BOOST_CHECK(!(x && true));
  BOOST_CHECK(!(true && x));
  BOOST_CHECK(x || true);
  BOOST_CHECK(true || x);

  BOOST_CHECK(y);
  BOOST_CHECK(y == true);
  BOOST_CHECK(true == y);
  BOOST_CHECK(y != false);
  BOOST_CHECK(false != y);
  BOOST_CHECK(maybe(y == maybe));
  BOOST_CHECK(maybe(maybe == y));
  BOOST_CHECK(maybe(y != maybe));
  BOOST_CHECK(maybe(maybe != y));
  BOOST_CHECK(y == y);
  BOOST_CHECK(!(y != y));

  BOOST_CHECK(maybe(z || !z));
  BOOST_CHECK(maybe(z == true));
  BOOST_CHECK(maybe(true == z));
  BOOST_CHECK(maybe(z == false));
  BOOST_CHECK(maybe(false == z));
  BOOST_CHECK(maybe(z == maybe));
  BOOST_CHECK(maybe(maybe == z));
  BOOST_CHECK(maybe(z != maybe));
  BOOST_CHECK(maybe(maybe != z));
  BOOST_CHECK(maybe(z == z));
  BOOST_CHECK(maybe(z != z));

  BOOST_CHECK(!(x == y));
  BOOST_CHECK(x != y);
  BOOST_CHECK(maybe(x == z));
  BOOST_CHECK(maybe(x != z));
  BOOST_CHECK(maybe(y == z));
  BOOST_CHECK(maybe(y != z));

  BOOST_CHECK(!(x && y));
  BOOST_CHECK(x || y);
  BOOST_CHECK(!(x && z));
  BOOST_CHECK(maybe(y && z));
  BOOST_CHECK(maybe(z && z));
  BOOST_CHECK(maybe(z || z));
  BOOST_CHECK(maybe(x || z));
  BOOST_CHECK(y || z);

  BOOST_CHECK(maybe(y && maybe));
  BOOST_CHECK(maybe(maybe && y));
  BOOST_CHECK(!(x && maybe));
  BOOST_CHECK(!(maybe && x));

  BOOST_CHECK(maybe || y);
  BOOST_CHECK(y || maybe);
  BOOST_CHECK(maybe(x || maybe));
  BOOST_CHECK(maybe(maybe || x));

  // Test the if (z) ... else (!z) ... else ... idiom
  if (z) {
    BOOST_CHECK(false);
  }
  else if (!z) {
    BOOST_CHECK(false);
  }
  else {
    BOOST_CHECK(true);
  }

  z = true;
  if (z) {
    BOOST_CHECK(true);
  }
  else if (!z) {
    BOOST_CHECK(false);
  }
  else {
    BOOST_CHECK(false);
  }

  z = false;
  if (z) {
    BOOST_CHECK(false);
  }
  else if (!z) {
    BOOST_CHECK(true);
  }
  else {
    BOOST_CHECK(false);
  }

  std::cout << "no errors detected\n";
  return 0;
}