Skip to content

Commit 5f113ab

Browse files
committed
test quick_cancel
1 parent 71adb02 commit 5f113ab

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

src/types.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ function (::Type{Div{T}})(n, d, simplified=false; metadata=nothing) where {T}
858858
_iszero(n) && return zero(typeof(n))
859859
_isone(d) && return n
860860
d isa Number && _isone(-d) && return -1 * n
861+
n isa Rat && d isa Rat && return n // d # maybe called by oblivious code in simplify
861862

862863
# GCD coefficient upon construction
863864
rat, nc = ratcoeff(n)

test/polyform.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using SymbolicUtils: PolyForm, Term, symtype
22
using Test, SymbolicUtils
33

4+
include("utils.jl")
5+
46
@testset "div and polyform" begin
57
@syms x y z
68
@test repr(PolyForm(x-y)) == "x - y"
@@ -31,3 +33,14 @@ end
3133
#@test expand(identity(a * b) - b * a) == 0
3234
@test expand(a * b - b * a) == 0
3335
end
36+
37+
@testset "simplify_fractions with quick-cancel" begin
38+
@syms x y
39+
@test simplify_fractions(x/2x) == 1//2
40+
@test simplify_fractions(2x//x) == 2
41+
@eqtest simplify_fractions((x+y) * (x-y) / (x+y)) == (x-y)
42+
@eqtest simplify_fractions(x^3 * y / x) == y*x^2
43+
@eqtest simplify_fractions(2x^3 * y / x) == 2y*x^2
44+
@eqtest simplify_fractions(x / (3(x^3)*y)) == simplify_fractions(1/(3*(y*x^2)))
45+
@eqtest simplify_fractions(2x / (3(x^3)*y)) == simplify_fractions(2/(3*(y*x^2)))
46+
end

test/runtests.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,10 @@ if v"1.6" ≤ VERSION < v"1.7-beta3.0"
1717
else
1818
@warn "Skipping doctests"
1919
end
20-
21-
# == / != syntax is nice, let's use it in tests
22-
macro eqtest(expr)
23-
@assert expr.head == :call && expr.args[1] in [:(==), :(!=)]
24-
if expr.args[1] == :(==)
25-
:(@test isequal($(expr.args[2]), $(expr.args[3])))
26-
else
27-
:(@test !isequal($(expr.args[2]), $(expr.args[3])))
28-
end |> esc
29-
end
3020
SymbolicUtils.show_simplified[] = false
3121

22+
include("utils.jl")
23+
3224
if haskey(ENV, "SU_BENCHMARK_ONLY")
3325
include("benchmark.jl")
3426
else

test/utils.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# == / != syntax is nice, let's use it in tests
3+
macro eqtest(expr)
4+
@assert expr.head == :call && expr.args[1] in [:(==), :(!=)]
5+
if expr.args[1] == :(==)
6+
:(@test isequal($(expr.args[2]), $(expr.args[3])))
7+
else
8+
:(@test !isequal($(expr.args[2]), $(expr.args[3])))
9+
end |> esc
10+
end

0 commit comments

Comments
 (0)