Files
utility/test/tribool_test.cpp
T

128 lines
3.0 KiB
C++
Raw Normal View History

2003-09-18 19:58:27 +00:00
// Copyright (C) 2002-2003 Doug Gregor (gregod@cs.rpi.edu)
2002-08-01 16:07:33 +00:00
//
// Permission to copy, use, sell and distribute this software is granted
// provided this copyright notice appears in all copies.
// Permission to modify the code and to distribute modified code is granted
// provided this copyright notice appears in all copies, and a notice
// that the code was modified is included with the copyright notice.
//
// This software is provided "as is" without express or implied warranty,
// and with no claim as to its suitability for any purpose.
2003-09-18 19:58:27 +00:00
2002-08-01 16:07:33 +00:00
// For more information, see http://www.boost.org
#include <boost/tribool.hpp>
#include <cassert>
#include <iostream>
int main()
{
using namespace boost;
tribool x; // false
tribool y(true); // true
tribool z(indeterminate); // indeterminate
assert(!x);
assert(x == false);
assert(false == x);
assert(x != true);
assert(true != x);
2003-09-18 19:58:27 +00:00
assert(indeterminate(x == indeterminate));
assert(indeterminate(indeterminate == x));
assert(indeterminate(x != indeterminate));
assert(indeterminate(indeterminate != x));
2002-08-01 16:07:33 +00:00
assert(x == x);
assert(!(x != x));
assert(!(x && true));
assert(!(true && x));
assert(x || true);
assert(true || x);
assert(y);
assert(y == true);
assert(true == y);
assert(y != false);
assert(false != y);
2003-09-18 19:58:27 +00:00
assert(indeterminate(y == indeterminate));
assert(indeterminate(indeterminate == y));
assert(indeterminate(y != indeterminate));
assert(indeterminate(indeterminate != y));
2002-08-01 16:07:33 +00:00
assert(y == y);
assert(!(y != y));
2003-09-18 19:58:27 +00:00
assert(indeterminate(z || !z));
2002-08-02 17:11:57 +00:00
assert(indeterminate(z == true));
assert(indeterminate(true == z));
assert(indeterminate(z == false));
assert(indeterminate(false == z));
2003-09-18 19:58:27 +00:00
assert(indeterminate(z == indeterminate));
assert(indeterminate(indeterminate == z));
assert(indeterminate(z != indeterminate));
assert(indeterminate(indeterminate != z));
assert(indeterminate(z == z));
assert(indeterminate(z != z));
2002-08-01 16:07:33 +00:00
assert(!(x == y));
assert(x != y);
2003-09-18 19:58:27 +00:00
assert(indeterminate(x == z));
assert(indeterminate(x != z));
assert(indeterminate(y == z));
assert(indeterminate(y != z));
2002-08-01 16:07:33 +00:00
assert(!(x && y));
assert(x || y);
assert(!(x && z));
2003-09-18 19:58:27 +00:00
assert(indeterminate(y && z));
assert(indeterminate(z && z));
assert(indeterminate(z || z));
2003-09-18 19:58:27 +00:00
assert(indeterminate(x || z));
2002-08-01 16:07:33 +00:00
assert(y || z);
2002-08-01 20:07:31 +00:00
assert(indeterminate(y && indeterminate));
assert(indeterminate(indeterminate && y));
assert(!(x && indeterminate));
assert(!(indeterminate && x));
assert(indeterminate || y);
assert(y || indeterminate);
assert(indeterminate(x || indeterminate));
assert(indeterminate(indeterminate || x));
2003-09-18 19:58:27 +00:00
// Test the if (z) ... else (!z) ... else ... idiom
2002-08-02 17:11:57 +00:00
if (z) {
assert(false);
}
else if (!z) {
assert(false);
}
else {
assert(true);
}
2003-09-18 19:58:27 +00:00
z = true;
if (z) {
assert(true);
}
else if (!z) {
assert(false);
}
else {
assert(false);
}
z = false;
if (z) {
assert(false);
}
else if (!z) {
assert(true);
}
else {
assert(false);
}
2002-08-01 16:07:33 +00:00
std::cout << "no errors detected\n";
return 0;
}