def test_equality_constraint_constructors(): a = pyqubo.Array.create("a", shape=(2, 2), vartype="SPIN") c1 = EqualityConstraint(variables_1=a) assert c1.get_variables_1() == {a[0, 0], a[0, 1], a[1, 0], a[1, 1]} assert c1.get_variables_2() == set() assert c1.get_label() == "Default Equality Constraint" assert c1.get_strength() == 1.0 c2 = EqualityConstraint(variables_2=a) assert c2.get_variables_1() == set() assert c2.get_variables_2() == {a[0, 0], a[0, 1], a[1, 0], a[1, 1]} assert c2.get_label() == "Default Equality Constraint" assert c2.get_strength() == 1.0 c3 = EqualityConstraint(label="my label") assert c3.get_variables_1() == set() assert c3.get_variables_2() == set() assert c3.get_label() == "my label" assert c3.get_strength() == 1.0 c4 = EqualityConstraint(strength=20) assert c4.get_variables_1() == set() assert c4.get_variables_2() == set() assert c4.get_label() == "Default Equality Constraint" assert c4.get_strength() == 20.0
def test_equality_constraint(): c = EqualityConstraint() assert c.get_constraint_class() == "EqualityConstraint" assert c.get_variables_1() == set() assert c.get_variables_2() == set() assert c.get_label() == "Default Equality Constraint" assert c.get_strength() == 1.0 x0 = pyqubo.Spin("x0") x1 = pyqubo.Spin("x1") y0 = pyqubo.Binary("y0") y1 = pyqubo.Binary("y1") c.add_variable_to_1(x0) assert c.get_variables_1() == {x0} assert c.get_variables_2() == set() c.add_variable_to_1([x1]) assert c.get_variables_1() == {x0, x1} assert c.get_variables_2() == set() c.add_variable_to_2({y0}) assert c.get_variables_1() == {x0, x1} assert c.get_variables_2() == {y0} c.add_variable_to_2(variables=[y0, y1]) assert c.get_variables_1() == {x0, x1} assert c.get_variables_2() == {y0, y1} c.remove_variable_from_1(variables=x0) assert c.get_variables_1() == {x1} assert c.get_variables_2() == {y0, y1} c.remove_variable_from_2(variables=y1) assert c.get_variables_1() == {x1} assert c.get_variables_2() == {y0} with pytest.raises(ValueError): c.remove_variable_from_1(variables=[x0]) with pytest.raises(ValueError): c.remove_variable_from_2(variables=[y1])