Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
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_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)
Beispiel #5
0
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)
Beispiel #6
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
Beispiel #7
0
def test_Complement():
    assert Complement(Interval(1, 3), Interval(1, 2)) == Interval(2, 3, True)
    assert Complement(FiniteSet(1, 3, 4), FiniteSet(3, 4)) == FiniteSet(1)
    assert Complement(Union(Interval(0, 2),
                            FiniteSet(2, 3, 4)), Interval(1, 3)) == \
        Union(Interval(0, 1, False, True), FiniteSet(4))
Beispiel #8
0
def test_Reals():
    Z = Integers()
    assert Z.union(FiniteSet(2, 4)) == Z
    assert Z.contains(0) == true
Beispiel #9
0
def test_Rationals():
    Q = Rationals()
    assert Q.union(FiniteSet(2, 3)) == Q
    assert Q.contains(0) == true
Beispiel #10
0
def test_Contains():
    assert Contains(x, FiniteSet(0)) != false
    assert Contains(x, Interval(1, 1)) != false
    assert Contains(oo, Interval(-oo, oo)) == false
    assert Contains(-oo, Interval(-oo, oo)) == false