def test_sets(): x = Integer(2) y = Integer(3) x1 = sympy.Integer(2) y1 = sympy.Integer(3) assert Interval(x, y) == Interval(x1, y1) assert Interval(x1, y) == Interval(x1, y1) assert Interval(x, y)._sympy_() == sympy.Interval(x1, y1) assert sympify(sympy.Interval(x1, y1)) == Interval(x, y) assert sympify(sympy.EmptySet()) == EmptySet() assert sympy.EmptySet() == EmptySet()._sympy_() assert FiniteSet(x, y) == FiniteSet(x1, y1) assert FiniteSet(x1, y) == FiniteSet(x1, y1) assert FiniteSet(x, y)._sympy_() == sympy.FiniteSet(x1, y1) assert sympify(sympy.FiniteSet(x1, y1)) == FiniteSet(x, y) x = Interval(1, 2) y = Interval(2, 3) x1 = sympy.Interval(1, 2) y1 = sympy.Interval(2, 3) assert Union(x, y) == Union(x1, y1) assert Union(x1, y) == Union(x1, y1) assert Union(x, y)._sympy_() == sympy.Union(x1, y1) assert sympify(sympy.Union(x1, y1)) == Union(x, y) assert Complement(x, y) == Complement(x1, y1) assert Complement(x1, y) == Complement(x1, y1) assert Complement(x, y)._sympy_() == sympy.Complement(x1, y1) assert sympify(sympy.Complement(x1, y1)) == Complement(x, y)
def test_FiniteSet(): x = Symbol("x") A = FiniteSet(1, 2, 3) B = FiniteSet(3, 4, 5) AorB = Union(A, B) AandB = A.intersection(B) assert AandB == FiniteSet(3) assert FiniteSet(EmptySet()) != EmptySet() assert FiniteSet(FiniteSet(1, 2, 3)) != FiniteSet(1, 2, 3)
def test_solve(): x = Symbol("x") reals = Interval(-oo, oo) assert solve(1, x, reals) == EmptySet() assert solve(0, x, reals) == reals assert solve(x + 3, x, reals) == FiniteSet(-3) assert solve(x + 3, x, Interval(0, oo)) == EmptySet() assert solve(x, x, reals) == FiniteSet(0) assert solve(x**2 + 1, x) == FiniteSet(-I, I) assert solve(x**2 - 2*x + 1, x) == FiniteSet(1) assert solve(Eq(x**3 + 3*x**2 + 3*x, -1), x, reals) == FiniteSet(-1) assert solve(x**3 - x, x) == FiniteSet(0, 1, -1)
def test_ConditionSet(): x = Symbol("x") i1 = Interval(-oo, oo) f1 = FiniteSet(0, 1, 2, 4) cond1 = Ge(x**2, 9) assert ConditionSet(x, And(Eq(0, 1), i1.contains(x))) == EmptySet() assert ConditionSet(x, And(Gt(1, 0), i1.contains(x))) == i1 assert ConditionSet(x, And(cond1, f1.contains(x))) == FiniteSet(4)
def test_sets(): x = Integer(2) y = Integer(3) x1 = sympy.Integer(2) y1 = sympy.Integer(3) assert Interval(x, y) == Interval(x1, y1) assert Interval(x1, y) == Interval(x1, y1) assert Interval(x, y)._sympy_() == sympy.Interval(x1, y1) assert sympify(sympy.Interval(x1, y1)) == Interval(x, y) assert sympify(sympy.S.EmptySet) == EmptySet() assert sympy.S.EmptySet == EmptySet()._sympy_() assert sympify(sympy.S.UniversalSet) == UniversalSet() assert sympy.S.UniversalSet == UniversalSet()._sympy_() assert sympify(sympy.S.Reals) == Reals() assert sympy.S.Reals == Reals()._sympy_() assert sympify(sympy.S.Rationals) == Rationals() assert sympy.S.Rationals == Rationals()._sympy_() assert sympify(sympy.S.Integers) == Integers() assert sympy.S.Integers == Integers()._sympy_() assert FiniteSet(x, y) == FiniteSet(x1, y1) assert FiniteSet(x1, y) == FiniteSet(x1, y1) assert FiniteSet(x, y)._sympy_() == sympy.FiniteSet(x1, y1) assert sympify(sympy.FiniteSet(x1, y1)) == FiniteSet(x, y) x = Interval(1, 2) y = Interval(2, 3) x1 = sympy.Interval(1, 2) y1 = sympy.Interval(2, 3) assert Union(x, y) == Union(x1, y1) assert Union(x1, y) == Union(x1, y1) assert Union(x, y)._sympy_() == sympy.Union(x1, y1) assert sympify(sympy.Union(x1, y1)) == Union(x, y) assert Complement(x, y) == Complement(x1, y1) assert Complement(x1, y) == Complement(x1, y1) assert Complement(x, y)._sympy_() == sympy.Complement(x1, y1) assert sympify(sympy.Complement(x1, y1)) == Complement(x, y)
def test_Union(): assert Union(Interval(1, 2), Interval(2, 3)) == Interval(1, 3) assert Union(Interval(1, 2), Interval(2, 3, True)) == Interval(1, 3) assert Union(Interval(1, 3), Interval(2, 4)) == Interval(1, 4) assert Union(Interval(1, 2), Interval(1, 3)) == Interval(1, 3) assert Union(Interval(1, 3), Interval(1, 2)) == Interval(1, 3) assert Union(Interval(1, 3, False, True), Interval(1, 2)) == \ Interval(1, 3, False, True) assert Union(Interval(1, 3), Interval(1, 2, False, True)) == Interval(1, 3) assert Union(Interval(1, 2, True), Interval(1, 3)) == Interval(1, 3) assert Union(Interval(1, 2, True), Interval(1, 3, True)) == \ Interval(1, 3, True) assert Union(Interval(1, 2, True), Interval(1, 3, True, True)) == \ Interval(1, 3, True, True) assert Union(Interval(1, 2, True, True), Interval(1, 3, True)) == \ Interval(1, 3, True) assert Union(Interval(1, 3), Interval(2, 3)) == Interval(1, 3) assert Union(Interval(1, 3, False, True), Interval(2, 3)) == \ Interval(1, 3) assert Union(Interval(1, 2, False, True), Interval(2, 3, True)) != \ Interval(1, 3) assert Union(Interval(1, 2), EmptySet()) == Interval(1, 2) assert Union(EmptySet()) == EmptySet()
def test_Interval(): assert Interval(0, oo) == Interval(0, oo, False, True) assert Interval(-oo, 0) == Interval(-oo, 0, True, False) assert Interval(oo, -oo) == EmptySet() assert Interval(oo, oo) == EmptySet() assert Interval(-oo, -oo) == EmptySet() assert isinstance(Interval(1, 1), FiniteSet) assert Interval(1, 0) == EmptySet() assert Interval(1, 1, False, True) == EmptySet() assert Interval(1, 1, True, False) == EmptySet() assert Interval(1, 1, True, True) == EmptySet() assert Interval(1, 2).union(Interval(2, 3)) == Interval(1, 3)
def test_Interval(): assert Interval(0, oo) == Interval(0, oo, False, True) assert Interval(0, oo) == Interval(0, oo, left_open=False, right_open=True) assert Interval(-oo, 0) == Interval(-oo, 0, True, False) assert Interval(-oo, 0) == Interval(-oo, 0, left_open=True, right_open=False) assert Interval(oo, -oo) == EmptySet() assert Interval(oo, oo) == EmptySet() assert Interval(-oo, -oo) == EmptySet() assert isinstance(Interval(1, 1), FiniteSet) assert Interval(1, 0) == EmptySet() assert Interval(1, 1, False, True) == EmptySet() assert Interval(1, 1, True, False) == EmptySet() assert Interval(1, 1, True, True) == EmptySet() assert Interval(1, 2).union(Interval(2, 3)) == Interval(1, 3) assert Interval(-oo, 0).start == -oo assert Interval(-oo, 0).end == 0
def test_ImageSet(): x = Symbol("x") i1 = Interval(0, 1) assert ImageSet(x, x**2, EmptySet()) == EmptySet() assert ImageSet(x, 1, i1) == FiniteSet(1) assert ImageSet(x, x, i1) == i1
def test_EmptySet(): E = EmptySet() assert E.intersection(UniversalSet()) == E