Skip to content

Commit

Permalink
Move tests to TestItems.jl (#30)
Browse files Browse the repository at this point in the history
* Move tests to TestItems.jl

* Add 1.8 and 1.9 to CI. Rm 1.7. Keep 1.6
  • Loading branch information
Azzaare authored Feb 3, 2023
1 parent 420d0c5 commit a7a78f2
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 100 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
matrix:
version:
- "1.6"
- "1.7"
- "^1.8.0-0"
- "1.8"
- "^1.9.0-0"
- 'nightly'
os:
- ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
name = "PatternFolds"
uuid = "c18a7f1d-76ad-4ce4-950d-5419b888513b"
authors = ["Jean-Francois Baffier"]
version = "0.2.2"
version = "0.2.3"

[deps]
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"
Lazy = "50d2b5c4-7a5e-59d5-8109-a42b560f39c0"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"

[compat]
Intervals = "1"
Lazy = "0.15"
Reexport = "1"
TestItems = "0.1"
julia = "1.6"

[extras]
Expand Down
1 change: 1 addition & 0 deletions src/PatternFolds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using Reexport
@reexport using Intervals
using Lazy
using Random
using TestItems

# exports
export IntervalsFold
Expand Down
35 changes: 35 additions & 0 deletions src/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,38 @@ function Base.rand(v::V) where {V <: Set{<:IntervalsFold}}
r < z[1] && return rand(z[2])
end
end

@testitem "IntervalsFold" tags=[:intervals] begin
i01 = Interval{Open,Closed}(0.0, 1.0)
i23 = Interval{Open,Closed}(2.0, 3.0)
i45 = Interval{Open,Closed}(4.0, 5.0)
i67 = Interval{Open,Closed}(6.0, 7.0)
i89 = Interval{Open,Closed}(8.0, 9.0)
isf_dict = Dict([
IntervalsFold(i01, 2.0, 5) => Dict(
:pattern => i01,
:gap => 2.0,
:folds => 5,
:length => 5,
:size => 5.0,
:unfold => [i01, i23, i45, i67, i89],
:reverse => reverse([i01, i23, i45, i67, i89]),
),
])

for (isf, results) in isf_dict
@test pattern(isf) == results[:pattern]
@test gap(isf) == results[:gap]
@test folds(isf) == results[:folds]
@test length(isf) == results[:length]
@test size(isf) == results[:size]
@test unfold(isf) == results[:unfold]
@test ndims(isf) == 1
for i in 1:1000
@test rand(isf) isf
end
@test collect(isf) == [i for i in isf] == unfold(isf)
@test collect(Iterators.reverse(isf)) == reverse(collect(isf)) == results[:reverse]
end
@test isempty(IntervalsFold(Interval{Open, Closed}(1.0, 1.0), 1.0, 1))
end
55 changes: 55 additions & 0 deletions src/vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,58 @@ function unfold(mvf::VectorFold; from=1, to=folds(mvf))
end

make_vector_fold(pattern, gap, fold, ::Val{:mutable}) = VectorFold(pattern, gap, fold)

@testitem "VectorFold" tags=[:vectors] begin
vf_dict = Dict([
make_vector_fold([1,2], 10, 5, :immutable) => Dict(
:pattern => [1,2],
:gap => 10,
:folds => 5,
:length => 10,
:unfold => [1,2,11,12,21,22,31,32,41,42],
:reverse => reverse([1,2,11,12,21,22,31,32,41,42]),
),
make_vector_fold([1,2], 10, 5, :mutable) => Dict(
:pattern => [1,2],
:gap => 10,
:folds => 5,
:length => 10,
:unfold => [1,2,11,12,21,22,31,32,41,42],
:reverse => reverse([1,2,11,12,21,22,31,32,41,42]),
),
])

for (vf, results) in vf_dict
@test pattern(vf) == results[:pattern]
@test gap(vf) == results[:gap]
@test folds(vf) == results[:folds]
@test length(vf) == results[:length]
@test unfold(vf) == results[:unfold]
@test ndims(vf) == 1
@test mapreduce(x -> x vf, *, rand(vf, 10))
@test collect(vf) == [i for i in vf] == unfold(vf)
@test collect(Iterators.reverse(vf)) == results[:reverse]
@test reverse(collect(vf)) == results[:reverse]
end
@test isempty(make_vector_fold(Vector(),1,1,:immutable))
@test isempty(make_vector_fold(Vector(),1,1))

v1 = make_vector_fold([42,3,45,6],13,4)
w1 = unfold(v1)
v11 = fold(w1)

@test unfold(v11) == w1

v2 = make_vector_fold([34,34,43,43],10,3)
w2 = unfold(v2)
v22 = fold(w2)

@test unfold(v22) == w2

v3 = make_vector_fold([42,3,45,6],13,4,:immutable)
w3 = unfold(v3)
v33 = fold(w3)

@test unfold(v33) == w3
collect(Iterators.reverse(v33))
end
3 changes: 0 additions & 3 deletions test/Project.toml

This file was deleted.

34 changes: 0 additions & 34 deletions test/intervals.jl

This file was deleted.

8 changes: 2 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using PatternFolds
using Test
using TestItemRunner

@testset "PatternFolds.jl" begin
include("vector.jl")
include("intervals.jl")
end
@run_package_tests
54 changes: 0 additions & 54 deletions test/vector.jl

This file was deleted.

0 comments on commit a7a78f2

Please sign in to comment.