Repository: sympy/sympy
File: sympy/calculus/tests/test_singularities.py (Python)

Code before:
    assert not is_strictly_decreasing(
        1/(x**2 - 3*x), Interval.Ropen(-oo, Rational(3, 2)))
    assert not is_strictly_decreasing(-x**2, Interval(-oo, 0))
    assert not is_strictly_decreasing(1)
    assert is_strictly_decreasing(1/(x**2 - 3*x), Interval.open(Rational(3,2), 3))
    assert is_strictly_decreasing(1/(x**2 - 3*x), Interval.open(1.5, 3))


def test_is_monotonic():
    """Test whether is_monotonic returns correct value."""
    assert is_monotonic(1/(x**2 - 3*x), Interval.open(Rational(3,2), 3))
    assert is_monotonic(1/(x**2 - 3*x), Interval.open(1.5, 3))
    assert is_monotonic(1/(x**2 - 3*x), Interval.Lopen(3, oo))
    assert is_monotonic(x**3 - 3*x**2 + 4*x, S.Reals)
    assert not is_monotonic(-x**2, S.Reals)
    assert is_monotonic(x**2 + y + 1, Interval(1, 2), x)
    raises(NotImplementedError, lambda: is_monotonic(x**2 + y + 1))


def test_issue_23401():
    x = Symbol('x')
    expr = (x + 1)/(-1.0e-3*x**2 + 0.1*x + 0.1)
    assert is_increasing(expr, Interval(1,2), x)


def test_monotonicity_with_poles():
    """Test that monotonicity functions check only derivative sign.

    Monotonicity functions (is_monotonic, is_increasing, etc.) check only
    whether the derivative has the appropriate sign, without verifying continuity.
    For applications that require both monotonicity and continuity (such as
    integration tests), continuity should be checked separately.
    """
    assert is_increasing(tan(x), Interval(0, 1), x)
    assert is_increasing(tan(x), Interval.open(-pi/2, pi/2), x)

    assert is_decreasing(1/x, Interval.open(0, 1), x)
    assert is_decreasing(1/x, Interval(-1, -0.1), x)


Review comment (bug):
These tests are ok if you want to defensively lock in this behavior. But now we need tests that affirm the new behavior for integration, perhaps something that failed on the issue page that now passes. Preferably something that tests both regions of changed code.

Code after:
    assert not is_strictly_decreasing(
        1/(x**2 - 3*x), Interval.Ropen(-oo, Rational(3, 2)))
    assert not is_strictly_decreasing(-x**2, Interval(-oo, 0))
    assert not is_strictly_decreasing(1)
    assert is_strictly_decreasing(1/(x**2 - 3*x), Interval.open(Rational(3,2), 3))
    assert is_strictly_decreasing(1/(x**2 - 3*x), Interval.open(1.5, 3))


def test_is_monotonic():
    """Test whether is_monotonic returns correct value."""
    assert is_monotonic(1/(x**2 - 3*x), Interval.open(Rational(3,2), 3))
    assert is_monotonic(1/(x**2 - 3*x), Interval.open(1.5, 3))
    assert is_monotonic(1/(x**2 - 3*x), Interval.Lopen(3, oo))
    assert is_monotonic(x**3 - 3*x**2 + 4*x, S.Reals)
    assert not is_monotonic(-x**2, S.Reals)
    assert is_monotonic(x**2 + y + 1, Interval(1, 2), x)
    raises(NotImplementedError, lambda: is_monotonic(x**2 + y + 1))


def test_issue_23401():
    x = Symbol('x')
    expr = (x + 1)/(-1.0e-3*x**2 + 0.1*x + 0.1)
    assert is_increasing(expr, Interval(1,2), x)


def test_monotonicity_with_interior_singularities():
    assert is_monotonic(tan(x), Interval(0, 5), x) is False
    assert is_increasing(tan(x), Interval(0, 5), x) is False

    assert is_monotonic(1/x, Interval(-1, 1), x) is False
    assert is_increasing(1/x, Interval(-1, 1), x) is False
    assert is_decreasing(1/x, Interval(-1, 1), x) is False

    assert is_increasing(tan(x), Interval(0, 1), x) is True
    assert is_increasing(tan(x), Interval.open(-pi/2, pi/2), x) is True

    assert is_decreasing(1/x, Interval.open(0, 1), x) is True
    assert is_decreasing(1/x, Interval(-1, Rational(-1, 10)), x) is True
    assert not is_decreasing(1/x, Interval(-1, 1), x)
    assert not is_increasing(1/x, Interval(-1, 1), x)