Skip to content

Commit

Permalink
Add CI (#5)
Browse files Browse the repository at this point in the history
* Add CI

* Fix line endings

* Excluding failing test on Windows

---------

Co-authored-by: Benoît Legat <[email protected]>
  • Loading branch information
odow and blegat authored Aug 19, 2024
1 parent 3852adc commit 584d846
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 22 deletions.
File renamed without changes.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 18 additions & 16 deletions test/MOI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/assets/einstein.fzn
Original file line number Diff line number Diff line change
Expand Up @@ -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;
solve satisfy;
12 changes: 7 additions & 5 deletions test/chuffed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 584d846

Please sign in to comment.