Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to TestItems for test setup #15

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
AztecDiamonds = "8762d9c5-fcab-4007-8fd1-c6de73397726"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
17 changes: 12 additions & 5 deletions test/core.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
@testset "core" begin
@testitem "core" begin
include("verify_tiling.jl")

D = diamond(100)
@test verify_tiling(D)

dr = dr_path(D)
@test dr[end] == -0.5
end

@testset "Tiling" begin
@testitem "Tiling" begin
using AztecDiamonds: NONE

D = diamond(100)
D′ = copy(D)

Expand All @@ -21,9 +25,10 @@ end
@test_throws BoundsError D[51, 51] = NONE
end

using AztecDiamonds: DiamondFaces

@testset "DiamondFaces" begin
@testitem "DiamondFaces" begin
using AztecDiamonds: DiamondFaces

df = DiamondFaces(10)
df′ = foldl(vcat, df; init=Union{}[])

Expand All @@ -32,7 +37,9 @@ using AztecDiamonds: DiamondFaces
@test length(df′[1]) == 3
end

@testset "KernelAbstractions CPU" begin
@testitem "KernelAbstractions CPU" begin
include("verify_tiling.jl")

D = ka_diamond(100, Array)
@test verify_tiling(D)
end
5 changes: 3 additions & 2 deletions test/cuda.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Adapt, CUDA
@testitem "CUDA" tags=[:cuda] begin
include("verify_tiling.jl")
using CUDA, Adapt

@testset "CUDA" begin
D = ka_diamond(200, CuArray)
D_cpu = adapt(Array, D)
@test verify_tiling(D_cpu)
Expand Down
6 changes: 3 additions & 3 deletions test/makie.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CairoMakie
using CairoMakie: Axis
@testitem "Makie" begin
using CairoMakie
using CairoMakie: Axis

@testset "Makie" begin
D = diamond(100)

f = Figure()
Expand Down
34 changes: 4 additions & 30 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,11 @@
using AztecDiamonds
using AztecDiamonds: inds, NONE, UP, RIGHT
using Test
using TestItemRunner, CUDA

function verify_tiling(t::Tiling)
(; N, x) = t
for (i, j) in Iterators.product(inds(N)...)
if checkbounds(Bool, t, i, j)
if t[i, j] == NONE && get(t, (i-1, j), NONE) != UP && get(t, (i, j-1), NONE) != RIGHT
error("Square ($i, $j) is not covered by any tile!")
end
else
if x[i, j] != NONE
error("Square ($i, $j) should be empty, is $(x[i, j])")
end
if get(x, CartesianIndex(i-1, j), NONE) == UP
error("Square ($i, $j) should be empty, is covered from below by ($(i-1), $j)")
end
if get(x, CartesianIndex(i, j-1), NONE) == RIGHT
error("Square ($i, $j) should be empty, is covered from the left by ($i, $(j-1))")
end
end
end
return true
end

using CUDA
iscuda((; tags)) = :cuda in tags

if !(haskey(ENV, "BUILDKITE") && CUDA.functional()) # skip non-gpu tests on Buildkite CI
include("core.jl")
include("show.jl")
include("makie.jl")
@run_package_tests filter=!iscuda verbose=true
end

if CUDA.functional()
include("cuda.jl")
@run_package_tests filter=iscuda verbose=true
end
8 changes: 4 additions & 4 deletions test/show.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Images
@testitem "image show" begin
using Images

@testset "image show" begin
D = diamond(100)
@test Base.showable("image/png", D)
@test repr("image/png", D) isa Vector{UInt8}
Expand All @@ -12,8 +12,8 @@ using Images
@test !Base.showable("image/png", Tiling(0))
end

@testset "pretty printing" begin
@test summary(Tiling(2)) == "2-order Tiling{Matrix{AztecDiamonds.Edge}}"
@testitem "pretty printing" begin
@test summary(Tiling(2)) == "2-order $Tiling{Matrix{AztecDiamonds.Edge}}"

N = 20
D = diamond(N)
Expand Down
23 changes: 23 additions & 0 deletions test/verify_tiling.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using AztecDiamonds: inds, NONE, UP, RIGHT

function verify_tiling(t::Tiling)
(; N, x) = t
for (i, j) in Iterators.product(inds(N)...)
if checkbounds(Bool, t, i, j)
if t[i, j] == NONE && get(t, (i-1, j), NONE) != UP && get(t, (i, j-1), NONE) != RIGHT
error("Square ($i, $j) is not covered by any tile!")
end
else
if x[i, j] != NONE
error("Square ($i, $j) should be empty, is $(x[i, j])")
end
if get(x, CartesianIndex(i-1, j), NONE) == UP
error("Square ($i, $j) should be empty, is covered from below by ($(i-1), $j)")
end
if get(x, CartesianIndex(i, j-1), NONE) == RIGHT
error("Square ($i, $j) should be empty, is covered from the left by ($i, $(j-1))")
end
end
end
return true
end
Loading