Boolean operands are created either by creating boolean variables (which are the simplest boolean operands) or by using operand properties that produce boolean operands.
The simplest boolean operands, boolean variables, can be created using
Mixin#bool_var
.
bool_operand = bool_var
A couple of examples of properties that produce boolean operands include
the BoolOperand#&
property, which produces a new boolean operand
representing the AND operation applied to two boolean operands:
new_bool_operand = bool_operand1 + bool_operand2
The BoolEnumOperand#conjunction
property produces a new boolean
operand representing the conjunction of all boolean operands in an
enumeration:
new_bool_operand = bool_enum.conjunction
Generated from BoolConstraintReceiver
.
true
true(options = {})
Constrains the boolean operand to be true.
# +b1+ and +b2+ must be true. (b1 & b2).must_be.true # (+b1+ implies +b2+) and (+b3+ implies +b2+) must be true. ((b1.implies b2) & (b3.implies b2)).must_be.true # +b1+ and +b2+ must be true. We reify it with +bool+ and select the # strength +domain+. (b1 & b2).must_be.true(:reify => bool, :strength => :domain)
false
false(options = {})
Constrains the boolean operand to be false.
# +b1+ and +b2+ must be false. (b1 & b2).must_be.false # (+b1+ implies +b2+) and (+b3+ implies +b2+) must be false. ((b1.implies b2) & (b3.implies b2)).must_be.false # +b1+ and +b2+ must be false. We reify it with +bool+ and select the # strength +domain+. (b1 & b2).must_be.false(:reify => bool, :strength => :domain)
==
==(bool_op, options = {})
Constrains the boolean operand to be equal to bool_op
. Any of
==, equal
and equal_to
may be used for equality.
# +b1+ and +b2+ must equal +b1+ or +b2+. (b1 & b2).must == (b1 | b2) # +b1+ and +b2+ must not equal +b3+. We reify it with +bool+ and select # the strength +domain+. (b1 & b2).must_not.equal(b3, :reify => bool, :select => :domain)
imply
imply(bool_op, options = {})
Constrains the boolean operand to imply bool_op
.
# +b1+ must imply +b2+ b1.must.imply b2 # +b1+ and +b2+ must not imply +b3+. We reify it with +bool+ and select # +domain+ as strength. (b1 & b2).must_not.imply(b3, :reify => bool, :strength => :domain)
Generated from BoolOperand
.
&
&(bool_op)
Produces a new BoolOperand representing this operand AND bool_op
.
# (+b1+ and +b2+) or +b3+
(b1 & b1) | b3
|
|(bool_op)
Produces a new BoolOperand representing this operand OR bool_op
.
# +b1+ and +b2+
b1 & b2
^
^(bool_op)
Produces a new BoolOperand representing this operand XOR bool_op
.
# (+b1+ and +b2+) or (+b3+ exclusive or +b1+)
(b1 & b2) | (b3 ^ b1)
implies
implies(bool_op)
Produces a new BoolOperand representing that this operand implies
bool_op
.
# (+b1+ implies +b2+) and (+b3+ implies +b2+)
(b1.implies b2) & (b3.implies b2)
+
+(op2)
Produces an IntOperand representing the value of this boolean operand (0 or
1) plus op2
.
# +bool1+ plus +bool2+
bool1 + bool2
-
-(op2)
Produces an IntOperand representing the value of this boolean operand (0 or
1) minus op2
.
# +bool1+ minus +bool2+
bool1 - bool2
*
*(fixnum)
Produces an IntOperand representing the value of this boolean operand (0 or 1) times a constant.
# +bool+ times 17 bool * 17