Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Nov 30, 2023
1 parent a6a5107 commit 4885963
Show file tree
Hide file tree
Showing 10 changed files with 888 additions and 880 deletions.
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
DataScienceTraits = "6cb2f572-2d2b-4ba6-bdb3-e710fa044d6c"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
879 changes: 1 addition & 878 deletions test/basics.jl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/feature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Map(:z => identity),
Replace(1.0 => 2.0),
Coalesce(value=0.0),
Coerce(:z => DST.Continuous),
Coerce(:z => Continuous),
Indicator(:z),
Identity(),
Center(),
Expand Down
77 changes: 77 additions & 0 deletions test/georef.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
@testset "georef" begin
table = Table(x=rand(3), y=[1, 2, 3], z=["a", "b", "c"])
tuple = (x=rand(3), y=[1, 2, 3], z=["a", "b", "c"])

# explicit domain types
gtb = georef(table, PointSet(rand(2, 3)))
@test domain(gtb) isa PointSet
gtb = georef(tuple, PointSet(rand(2, 3)))
@test domain(gtb) isa PointSet
gtb = georef(table, CartesianGrid(3))
@test domain(gtb) isa CartesianGrid
gtb = georef(tuple, CartesianGrid(3))
@test domain(gtb) isa CartesianGrid

# vectors of geometries
gtb = georef(table, rand(Point2, 3))
@test domain(gtb) isa PointSet
gtb = georef(tuple, rand(Point2, 3))
@test domain(gtb) isa PointSet
gtb = georef(table, collect(CartesianGrid(3)))
@test domain(gtb) isa GeometrySet
gtb = georef(tuple, collect(CartesianGrid(3)))
@test domain(gtb) isa GeometrySet

# coordinates of point set
gtb = georef(table, rand(2, 3))
@test domain(gtb) isa PointSet
gtb = georef(tuple, rand(2, 3))
@test domain(gtb) isa PointSet

# coordinates names in table
gtb = georef(table, (:x, :y))
@test domain(gtb) isa PointSet
@test propertynames(gtb) == [:z, :geometry]
gtb = georef(tuple, (:x, :y))
@test domain(gtb) isa PointSet
@test propertynames(gtb) == [:z, :geometry]
gtb = georef(table, [:x, :y])
@test domain(gtb) isa PointSet
@test propertynames(gtb) == [:z, :geometry]
gtb = georef(tuple, [:x, :y])
@test domain(gtb) isa PointSet
@test propertynames(gtb) == [:z, :geometry]
gtb = georef(table, ("x", "y"))
@test domain(gtb) isa PointSet
@test propertynames(gtb) == [:z, :geometry]
gtb = georef(tuple, ("x", "y"))
@test domain(gtb) isa PointSet
@test propertynames(gtb) == [:z, :geometry]
gtb = georef(table, ["x", "y"])
@test domain(gtb) isa PointSet
@test propertynames(gtb) == [:z, :geometry]
gtb = georef(tuple, ["x", "y"])
@test domain(gtb) isa PointSet
@test propertynames(gtb) == [:z, :geometry]

# grid data
tuple1D = (x=rand(10), y=rand(10))
gtb = georef(tuple1D)
@test domain(gtb) == CartesianGrid(10)
tuple2D = (x=rand(10, 10), y=rand(10, 10))
gtb = georef(tuple2D)
@test domain(gtb) == CartesianGrid(10, 10)
tuple3D = (x=rand(10, 10, 10), y=rand(10, 10, 10))
gtb = georef(tuple3D)
@test domain(gtb) == CartesianGrid(10, 10, 10)
# different types
tuple1D = (x=[rand(9); missing], y=rand(10))
gtb = georef(tuple1D)
@test domain(gtb) == CartesianGrid(10)
tuple2D = (x=rand(10, 10), y=BitArray(rand(Bool, 10, 10)))
gtb = georef(tuple2D)
@test domain(gtb) == CartesianGrid(10, 10)
# throws: different sizes
tuple2D = (x=rand(3, 3), y=rand(5, 5))
@test_throws AssertionError georef(tuple2D)
end
36 changes: 36 additions & 0 deletions test/indices.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@testset "indices" begin
# -------------
# PARTITIONING
# -------------
t = georef((a=rand(100), b=rand(100)), CartesianGrid(10, 10))
for method in [
UniformPartition(2),
FractionPartition(0.5),
BlockPartition(2),
BallPartition(2),
BisectPointPartition(Vec(1, 1), Point(5, 5)),
BisectFractionPartition(Vec(1, 1), 0.5),
PlanePartition(Vec(1, 1)),
DirectionPartition(Vec(1, 1)),
PredicatePartition((i, j) -> iseven(i + j)),
SpatialPredicatePartition((x, y) -> norm(x + y) < 5),
ProductPartition(UniformPartition(2), UniformPartition(2)),
HierarchicalPartition(UniformPartition(2), UniformPartition(2))
]
Π = partition(t, method)
inds = reduce(vcat, indices(Π))
@test sort(inds) == 1:100
end

# ---------
# SAMPLING
# ---------
t = georef((z=rand(50, 50),))
s = sample(t, UniformSampling(100))
@test nrow(s) == 100

# --------
# SORTING
# --------
# TODO
end
53 changes: 53 additions & 0 deletions test/noattribs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@testset "No attributes" begin
pset = PointSet((0, 0), (1, 1), (2, 2))
gtb = GeoTable(pset)
@test ncol(gtb) == 1

# GeoTableRows
rows = Tables.rows(gtb)
sch = Tables.schema(rows)
@test sch.names == (:geometry,)
@test sch.types == (Point2,)
row, state = iterate(rows)
@test Tables.columnnames(row) == (:geometry,)
@test Tables.getcolumn(row, :geometry) == pset[1]
row, state = iterate(rows, state)
@test Tables.columnnames(row) == (:geometry,)
@test Tables.getcolumn(row, :geometry) == pset[2]
row, state = iterate(rows, state)
@test Tables.columnnames(row) == (:geometry,)
@test Tables.getcolumn(row, :geometry) == pset[3]
@test isnothing(iterate(rows, state))

# dataframe interface
@test propertynames(gtb) == [:geometry]
@test gtb.geometry == pset
@test gtb[1:2, [:geometry]].geometry == view(pset, 1:2)
@test gtb[1, [:geometry]].geometry == pset[1]
@test gtb[1, :].geometry == pset[1]
@test gtb[:, [:geometry]] == gtb
ngtb = georef((; x=rand(3)), pset)
hgtb = hcat(gtb, ngtb)
@test propertynames(hgtb) == [:x, :geometry]
@test hgtb.x == ngtb.x
@test hgtb.geometry == pset
npset = PointSet((4, 4), (5, 5), (6, 6))
ngtb = GeoTable(npset)
vgtb = vcat(gtb, ngtb)
@test propertynames(vgtb) == [:geometry]
@test vgtb.geometry == PointSet([collect(pset); collect(npset)])

# viewing
v = view(gtb, [1, 3])
@test isnothing(values(v))
@test v.geometry == view(pset, [1, 3])

# throws
@test_throws ErrorException gtb.test
@test_throws AssertionError gtb[[1, 3], [:test]]
@test_throws AssertionError gtb[2, [:test]]
@test_throws AssertionError gtb[:, [:test]]
@test_throws AssertionError gtb[:, r"test"]
ngtb = georef((; x=rand(3)), npset)
@test_throws ArgumentError vcat(gtb, ngtb)
end
Loading

0 comments on commit 4885963

Please sign in to comment.