def test_binary_xor(self): m = ConcreteModel() m.Y1 = BooleanVar() m.Y2 = BooleanVar() op_static = xor(m.Y1, m.Y2) op_class = m.Y1.xor(m.Y2) # op_operator = m.Y1 ^ m.Y2 for truth_combination in _generate_possible_truth_inputs(2): m.Y1.value, m.Y2.value = truth_combination[0], truth_combination[1] correct_value = operator.xor(*truth_combination) self.assertEqual(value(op_static), correct_value) self.assertEqual(value(op_class), correct_value)
def test_to_string(self): m = ConcreteModel() m.Y1 = BooleanVar() m.Y2 = BooleanVar() m.Y3 = BooleanVar() self.assertEqual(str(land(m.Y1, m.Y2, m.Y3)), "Y1 ∧ Y2 ∧ Y3") self.assertEqual(str(lor(m.Y1, m.Y2, m.Y3)), "Y1 ∨ Y2 ∨ Y3") self.assertEqual(str(equivalent(m.Y1, m.Y2)), "Y1 iff Y2") self.assertEqual(str(implies(m.Y1, m.Y2)), "Y1 --> Y2") self.assertEqual(str(xor(m.Y1, m.Y2)), "Y1 ⊻ Y2") self.assertEqual(str(atleast(1, m.Y1, m.Y2)), "atleast(1: [Y1, Y2])") self.assertEqual(str(atmost(1, m.Y1, m.Y2)), "atmost(1: [Y1, Y2])") self.assertEqual(str(exactly(1, m.Y1, m.Y2)), "exactly(1: [Y1, Y2])") # Precedence check self.assertEqual(str(m.Y1.implies(m.Y2).lor(m.Y3)), "(Y1 --> Y2) ∨ Y3")