Skip to content

Commit

Permalink
move from FactCheck to Base.Test
Browse files Browse the repository at this point in the history
  • Loading branch information
mlubin committed Nov 26, 2016
1 parent 7d5067c commit 4f352ad
Show file tree
Hide file tree
Showing 16 changed files with 5,295 additions and 5,603 deletions.
1 change: 0 additions & 1 deletion test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
FactCheck
Cbc
Clp
GLPKMathProgInterface
Expand Down
518 changes: 253 additions & 265 deletions test/callback.jl

Large diffs are not rendered by default.

120 changes: 63 additions & 57 deletions test/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,82 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#############################################################################
# JuMP
# An algebraic modelling langauge for Julia
# An algebraic modeling langauge for Julia
# See http://github.com/JuliaOpt/JuMP.jl
#############################################################################
# test/expr.jl
# Testing for AffExpr and QuadExpr
#############################################################################
using JuMP, FactCheck
using JuMP
using Base.Test

facts("[expr] Test expression construction") do
maff = Model()
@variable(maff, 0 <= x[1:5] <= 1)
@variable(maff, 0 <= LongName <= 99)
@testset "Expressions" begin

context("AffExpr") do
# Test affstr
a1 = x[1] + LongName + 5
@fact string(a1) --> "x[1] + LongName + 5"
# Test like term collection
a2 = 2*(x[2] + LongName + x[2]) + 0
@fact string(a2) --> "4 x[2] + 2 LongName"
# Test appending functionality
push!(a1, 5.0, x[2])
@fact string(a1) --> "x[1] + LongName + 5 x[2] + 5"
append!(a1, a2)
@fact string(a1) --> "x[1] + 3 LongName + 9 x[2] + 5"
append!(a1, 2.0)
@fact string(a1) --> "x[1] + 3 LongName + 9 x[2] + 7"
append!(a1, LongName)
@fact string(a1) --> "x[1] + 4 LongName + 9 x[2] + 7"
end
@testset "Test expression construction" begin
maff = Model()
@variable(maff, 0 <= x[1:5] <= 1)
@variable(maff, 0 <= LongName <= 99)

@testset "AffExpr" begin
# Test affstr
a1 = x[1] + LongName + 5
@test string(a1) == "x[1] + LongName + 5"
# Test like term collection
a2 = 2*(x[2] + LongName + x[2]) + 0
@test string(a2) == "4 x[2] + 2 LongName"
# Test appending functionality
push!(a1, 5.0, x[2])
@test string(a1) == "x[1] + LongName + 5 x[2] + 5"
append!(a1, a2)
@test string(a1) == "x[1] + 3 LongName + 9 x[2] + 5"
append!(a1, 2.0)
@test string(a1) == "x[1] + 3 LongName + 9 x[2] + 7"
append!(a1, LongName)
@test string(a1) == "x[1] + 4 LongName + 9 x[2] + 7"
end

context("QuadExpr") do
# Test string
q1 = x[1]*x[2] + 27.2*LongName + 5
@fact string(q1) --> "x[1]*x[2] + 27.2 LongName + 5"
# Test like term collection
q2 = x[1]*x[2] + x[2]*x[1]
@fact string(q2) --> "2 x[1]*x[2]"
@testset "QuadExpr" begin
# Test string
q1 = x[1]*x[2] + 27.2*LongName + 5
@test string(q1) == "x[1]*x[2] + 27.2 LongName + 5"
# Test like term collection
q2 = x[1]*x[2] + x[2]*x[1]
@test string(q2) == "2 x[1]*x[2]"
end
end
end

facts("[expr] Test getvalue(expr)") do
m = Model()
@variable(m, 1 <= x[1:3] <= 2)
setvalue(x[3], 2)
setvalue(x[2], 2)
setvalue(x[1], 1)
@fact getvalue(x[1]-x[2]+2x[3]-1.0) --> roughly(2.0)
@fact getvalue(x[1]*x[1]-2x[2]*x[1]+3x[2]+1) --> roughly(4.0)
end
@testset "Test getvalue(expr)" begin
m = Model()
@variable(m, 1 <= x[1:3] <= 2)
setvalue(x[3], 2)
setvalue(x[2], 2)
setvalue(x[1], 1)
@test isapprox(getvalue(x[1]-x[2]+2x[3]-1.0), 2.0)
@test isapprox(getvalue(x[1]*x[1]-2x[2]*x[1]+3x[2]+1), 4.0)
end

facts("[expr] Test expression iterators") do
m = Model()
@variable(m, x[1:10])
@testset "Test expression iterators" begin
m = Model()
@variable(m, x[1:10])

a1 = 1*x[1] + 2*x[2]
k = 1
for (coeff,var) in linearterms(a1)
if k == 1
@fact coeff --> 1
@fact var --> exactly(x[1])
elseif k == 2
@fact coeff --> 2
@fact var --> exactly(x[2])
a1 = 1*x[1] + 2*x[2]
k = 1
for (coeff,var) in linearterms(a1)
if k == 1
@test coeff == 1
@test var === x[1]
elseif k == 2
@test coeff == 2
@test var === x[2]
end
k += 1
end
k += 1
end

a2 = zero(AffExpr)
for (coeff, var) in linearterms(a2)
@fact coeff --> 0.0 # Shouldn't be called!
k = 0
a2 = zero(AffExpr)
for (coeff, var) in linearterms(a2)
k += 1
end
@test k == 0
end
end
12 changes: 6 additions & 6 deletions test/fuzzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ function test_approx_equal_exprs(ex1, ex2)
return res
end

println("[fuzzer] Check macros for expression construction")

for _ in 1:100
raff = random_aff_expr(N, vars)
ex = @eval @JuMP.Expression($raff)
@fact test_approx_equal_exprs(ex, eval(raff)) --> true
@testset "Fuzzing the macros" begin
for _ in 1:100
raff = random_aff_expr(N, vars)
ex = @eval @JuMP.Expression($raff)
@test test_approx_equal_exprs(ex, eval(raff))
end
end

0 comments on commit 4f352ad

Please sign in to comment.