From 584d846991d463f4cbc7871910cd894eb63c2d4d Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Mon, 19 Aug 2024 23:38:39 +1200 Subject: [PATCH] Add CI (#5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add CI * Fix line endings * Excluding failing test on Windows --------- Co-authored-by: Benoît Legat --- {.workflows => .github/workflows}/TagBot.yml | 0 .github/workflows/ci.yml | 38 ++++++++++++++++++++ test/MOI.jl | 34 +++++++++--------- test/assets/einstein.fzn | 2 +- test/chuffed.jl | 12 ++++--- 5 files changed, 64 insertions(+), 22 deletions(-) rename {.workflows => .github/workflows}/TagBot.yml (100%) create mode 100644 .github/workflows/ci.yml diff --git a/.workflows/TagBot.yml b/.github/workflows/TagBot.yml similarity index 100% rename from .workflows/TagBot.yml rename to .github/workflows/TagBot.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cd1ec81 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: CI +on: + push: + branches: [master] + pull_request: + types: [opened, synchronize, reopened] +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + version: ['1.6', '1'] # Test against LTS and current minor release + os: [ubuntu-latest, macOS-latest, windows-latest] + arch: [x64] + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: actions/cache@v1 + env: + cache-name: cache-artifacts + with: + path: ~/.julia/artifacts + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + restore-keys: | + ${{ runner.os }}-test-${{ env.cache-name }}- + ${{ runner.os }}-test- + ${{ runner.os }}- + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 + - uses: julia-actions/julia-processcoverage@v1 + - uses: codecov/codecov-action@v1 + with: + file: lcov.info diff --git a/test/MOI.jl b/test/MOI.jl index d78889e..57f98bb 100644 --- a/test/MOI.jl +++ b/test/MOI.jl @@ -5,27 +5,29 @@ @testset "MOI interface" begin @testset "basic.fzn" begin - model = optimizer(Int) + if !Sys.iswindows() # FIXME Windows (both 32 and 64 bits) ends with `INFEASIBLE` on Github ci + model = optimizer(Int) - @test MOI.supports_add_constrained_variable(model, MOI.Integer) - @test MOI.supports_constraint(CP.FlatZinc.Model(), MOI.ScalarAffineFunction{Int}, MOI.LessThan{Int}) + @test MOI.supports_add_constrained_variable(model, MOI.Integer) + @test MOI.supports_constraint(CP.FlatZinc.Model(), MOI.ScalarAffineFunction{Int}, MOI.LessThan{Int}) - # x ∈ {1, 2, 3} - x, x_int = MOI.add_constrained_variable(model, MOI.Integer()) - c1 = MOI.add_constraint(model, -1 * x, MOI.LessThan(-1)) - c2 = MOI.add_constraint(model, 1 * x, MOI.LessThan(3)) + # x ∈ {1, 2, 3} + x, x_int = MOI.add_constrained_variable(model, MOI.Integer()) + c1 = MOI.add_constraint(model, -1 * x, MOI.LessThan(-1)) + c2 = MOI.add_constraint(model, 1 * x, MOI.LessThan(3)) - @test MOI.is_valid(model, x) - @test MOI.is_valid(model, x_int) - @test MOI.is_valid(model, c1) - @test MOI.is_valid(model, c2) + @test MOI.is_valid(model, x) + @test MOI.is_valid(model, x_int) + @test MOI.is_valid(model, c1) + @test MOI.is_valid(model, c2) - MOI.optimize!(model) + MOI.optimize!(model) - @test MOI.get(model, MOI.TerminationStatus()) === MOI.OPTIMAL - @test MOI.get(model, MOI.ResultCount()) ≥ 1 - @test MOI.get(model, MOI.VariablePrimal(), x) ∈ Set([1, 2, 3]) - @test MOI.get(model, MOI.VariablePrimal(1), x) ∈ Set([1, 2, 3]) + @test MOI.get(model, MOI.TerminationStatus()) === MOI.OPTIMAL + @test MOI.get(model, MOI.ResultCount()) ≥ 1 + @test MOI.get(model, MOI.VariablePrimal(), x) ∈ Set([1, 2, 3]) + @test MOI.get(model, MOI.VariablePrimal(1), x) ∈ Set([1, 2, 3]) + end end @testset "Infeasible" begin diff --git a/test/assets/einstein.fzn b/test/assets/einstein.fzn index fbdf8ed..8622639 100644 --- a/test/assets/einstein.fzn +++ b/test/assets/einstein.fzn @@ -35,4 +35,4 @@ constraint int_lin_eq([-1, -1, 1], [INT____00001, a[4], k[3]], 0) :: defines_var constraint int_lin_eq([-1, -1, 1], [INT____00005, c[5], s[4]], 0) :: defines_var(INT____00005); constraint int_lin_eq([-1, -1, 1], [INT____00007, d[5], k[3]], 0) :: defines_var(INT____00007); constraint int_plus(INT____00003, k[2], a[5]) :: defines_var(INT____00003); -solve satisfy; \ No newline at end of file +solve satisfy; diff --git a/test/chuffed.jl b/test/chuffed.jl index 89c5563..dbca341 100644 --- a/test/chuffed.jl +++ b/test/chuffed.jl @@ -3,31 +3,33 @@ # Use of this source code is governed by an MIT-style license that can be found # in the LICENSE.md file or at https://opensource.org/licenses/MIT. +normalize(x) = replace(x, "\r\n" => "\n") + # TODO: move the samples to CP?? Not all solvers will understand all FZN files :/. @testset "Sanity check for Chuffed" begin @testset "basic.fzn" begin out_string = Chuffed.run_chuffed(@__DIR__() * "/assets/basic.fzn") - @test out_string == "x = 3;\r\n\r\n----------\r\n" + @test normalize(out_string) == "x = 3;\n\n----------\n" end @testset "one_solution.fzn" begin out_string = Chuffed.run_chuffed(@__DIR__() * "/assets/one_solution.fzn") - @test out_string == "x = 10;\r\n\r\n----------\r\n==========\r\n" + @test normalize(out_string) == "x = 10;\n\n----------\n==========\n" end @testset "several_solutions.fzn" begin out_string = Chuffed.run_chuffed(["-a", @__DIR__() * "/assets/several_solutions.fzn"]) - @test out_string == "xs = array1d(1..2, [2, 3]);\r\n\r\n----------\r\nxs = array1d(1..2, [1, 3]);\r\n\r\n----------\r\nxs = array1d(1..2, [1, 2]);\r\n\r\n----------\r\n==========\r\n" + @test normalize(out_string) == "xs = array1d(1..2, [2, 3]);\n\n----------\nxs = array1d(1..2, [1, 3]);\n\n----------\nxs = array1d(1..2, [1, 2]);\n\n----------\n==========\n" end @testset "puzzle.fzn" begin out_string = Chuffed.run_chuffed(@__DIR__() * "/assets/puzzle.fzn") - @test out_string == "x = array2d(1..4, 1..4, [5, 1, 8, 8, 9, 3, 8, 6, 9, 7, 7, 8, 1, 7, 8, 9]);\r\n\r\n----------\r\n" + @test normalize(out_string) == "x = array2d(1..4, 1..4, [5, 1, 8, 8, 9, 3, 8, 6, 9, 7, 7, 8, 1, 7, 8, 9]);\n\n----------\n" end @testset "einstein.fzn" begin out_string = Chuffed.run_chuffed(@__DIR__() * "/assets/einstein.fzn") - @test out_string == "a = array1d(1..5, [5, 4, 3, 1, 2]);\r\nc = array1d(1..5, [3, 4, 5, 1, 2]);\r\nd = array1d(1..5, [2, 4, 3, 5, 1]);\r\nk = array1d(1..5, [3, 1, 2, 5, 4]);\r\ns = array1d(1..5, [3, 5, 2, 1, 4]);\r\n\r\n----------\r\n" + @test normalize(out_string) == "a = array1d(1..5, [5, 4, 3, 1, 2]);\nc = array1d(1..5, [3, 4, 5, 1, 2]);\nd = array1d(1..5, [2, 4, 3, 5, 1]);\nk = array1d(1..5, [3, 1, 2, 5, 4]);\ns = array1d(1..5, [3, 5, 2, 1, 4]);\n\n----------\n" end end