runtests.jl 2.1 KB
Newer Older
1
2
using COBREXA, Test

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
3
using Aqua
Taneli Pusa's avatar
Taneli Pusa committed
4
using Distributed
5
using Downloads
6
using JSON
Laurent Heirendt's avatar
Laurent Heirendt committed
7
using JuMP
8
9
10
using LinearAlgebra
using MAT
using OrderedCollections
St. Elmo's avatar
St. Elmo committed
11
using OSQP
12
13
using SHA
using SparseArrays
St. Elmo's avatar
format    
St. Elmo committed
14
using Statistics
15
using Tulip
16
using GLPK # for MILPs
Sylvain Arreckx's avatar
Sylvain Arreckx committed
17

18
19
20
# tolerance for comparing analysis results (should be a bit bigger than the
# error tolerance in computations)
TEST_TOLERANCE = 10 * COBREXA._constants.tolerance
21
QP_TEST_TOLERANCE = 1e-2 # for OSQP
22

23
24
print_timing(fn, t) = @info "$(fn) done in $(round(t; digits = 2))s"

25
# helper functions for running tests en masse
26
function run_test_file(path...)
27
28
    fn = joinpath(path...)
    t = @elapsed include(fn)
29
    print_timing(fn, t)
Sylvain Arreckx's avatar
Sylvain Arreckx committed
30
end
Sylvain Arreckx's avatar
Sylvain Arreckx committed
31

32
function run_test_dir(dir, comment = "Directory $dir/")
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
33
    @testset "$comment" begin
34
        run_test_file.(joinpath.(dir, filter(fn -> endswith(fn, ".jl"), readdir(dir))))
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
35
36
37
    end
end

38
39
# set up the workers for Distributed, so that the tests that require more
# workers do not unnecessarily load the stuff multiple times
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
40
41
42
43
44
45
46
47
48
49
#W = addprocs(2)
#t = @elapsed @everywhere using COBREXA, Tulip, JuMP
#print_timing("import of packages", t)
#t = @elapsed @everywhere begin
#model = Model(Tulip.Optimizer)
#@variable(model, 0 <= x <= 1)
#@objective(model, Max, x)
#optimize!(model)
#end
#print_timing("JuMP+Tulip code warmup", t)
50

51
52
53
54
55
# make sure there's a directory for temporary data
tmpdir = "tmpfiles"
isdir(tmpdir) || mkdir(tmpdir)
tmpfile(x...) = joinpath(tmpdir, x...)

Sylvain Arreckx's avatar
Sylvain Arreckx committed
56
# load the test models
57
58
run_test_file("data_static.jl")
run_test_file("data_downloaded.jl")
Sylvain Arreckx's avatar
Sylvain Arreckx committed
59

Sylvain Arreckx's avatar
Sylvain Arreckx committed
60
# import base files
61
@testset "COBREXA test suite" begin
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
62
63
64
65
66
67
68
69
70
71
72
    #run_test_dir(joinpath("base", "types", "abstract"), "Abstract types")
    #run_test_dir(joinpath("base", "types"), "Base model types")
    #run_test_dir(joinpath("base", "logging"), "Logging")
    #run_test_dir("base", "Base functionality")
    #run_test_dir(joinpath("base", "utils"), "Utilities")
    #run_test_dir("io", "I/O functions")
    #run_test_dir("reconstruction")
    #run_test_dir("analysis")
    #run_test_dir(joinpath("analysis", "sampling"), "Sampling")
    #run_test_file("analysis/smoment.jl")
    run_test_file("analysis/gecko.jl")
73
end
74

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
75
#rmprocs(W)