Skip to content

Commit 4c5e825

Browse files
authored
Refactor test/traversing.jl (#1184)
1 parent 3927a9d commit 4c5e825

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

test/traversing.jl

+20-27
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
@testitem "Traversing" setup = [Setup] begin
2+
# LinearPath
23
grid = cartgrid(100, 100)
3-
for path in [LinearPath(), RandomPath(), ShiftedPath(LinearPath(), 0), SourcePath(1:3)]
4-
p = traverse(grid, path)
5-
@test length(p) == 100 * 100
6-
end
7-
8-
grid = cartgrid(100, 100)
9-
p = traverse(grid, LinearPath())
10-
@test p == 1:(100 * 100)
4+
path = LinearPath()
5+
@test traverse(grid, path) == 1:10000
116

7+
# RandomPath
128
grid = cartgrid(100, 100)
13-
p = traverse(grid, RandomPath())
14-
@test all(1 .≤ collect(p) .≤ 100 * 100)
159
path = RandomPath(StableRNG(123))
10+
@test all(1 .≤ traverse(grid, path) .≤ 10000)
1611
grid = cartgrid(3, 3)
12+
path = RandomPath(StableRNG(123))
1713
@test traverse(grid, path) == [4, 7, 2, 1, 3, 8, 5, 6, 9]
1814

15+
# SourcePath
1916
grid = cartgrid(3, 3)
2017
pset = PointSet(centroid.(grid))
2118
for sdomain in [grid, pset]
22-
t = traverse(sdomain, SourcePath([1, 9]))
23-
@test collect(t) == [1, 9, 2, 4, 6, 8, 5, 3, 7]
24-
25-
t = traverse(sdomain, SourcePath([1]))
26-
@test collect(t) == [1, 2, 4, 5, 3, 7, 6, 8, 9]
19+
spath = SourcePath([1, 9])
20+
@test traverse(sdomain, spath) == [1, 9, 2, 4, 6, 8, 5, 3, 7]
21+
spath = SourcePath([1])
22+
@test traverse(sdomain, spath) == [1, 2, 4, 5, 3, 7, 6, 8, 9]
2723
end
2824

25+
# ShiftedPath
2926
grid = cartgrid(3, 3)
3027
path = LinearPath()
3128
for offset in [0, 1, -1]
@@ -36,42 +33,38 @@
3633
@test collect(st) == circshift(t, -offset)
3734
end
3835

36+
# MultiGridPath
3937
path = MultiGridPath()
40-
4138
grid = cartgrid(3, 3)
4239
@test traverse(grid, path) == [1, 3, 7, 9, 2, 4, 5, 6, 8]
43-
4440
grid = cartgrid(3, 4)
4541
@test traverse(grid, path) == [1, 3, 10, 12, 2, 7, 8, 9, 4, 5, 6, 11]
46-
4742
grid = CartesianGrid(3, 3, 2)
4843
@test traverse(grid, path) == [1, 3, 7, 9, 10, 12, 16, 18, 2, 4, 5, 6, 8, 11, 13, 14, 15, 17]
49-
5044
grid = RectilinearGrid(T.(0:3), T.(0:3))
5145
@test traverse(grid, path) == [1, 3, 7, 9, 2, 4, 5, 6, 8]
52-
5346
grid = RectilinearGrid(T.(0:0.5:2), T.(0:0.5:2))
5447
@test traverse(grid, path) == [1, 4, 13, 16, 3, 9, 11, 2, 5, 6, 7, 8, 10, 12, 14, 15]
55-
5648
cgrid = cartgrid(4, 4)
5749
rgrid = RectilinearGrid(T.(0:4), T.(0:4))
5850
@test traverse(cgrid, path) == traverse(rgrid, path)
59-
6051
grid = cartgrid(3, 4)
6152
vgrid = view(grid, 3:10)
6253
@test traverse(vgrid, path) == [3, 10, 7, 8, 9, 4, 5, 6]
6354

55+
# visual tests
6456
if visualtests
6557
paths = [LinearPath(), RandomPath(StableRNG(123)), ShiftedPath(LinearPath(), 10), SourcePath(1:3), MultiGridPath()]
6658

6759
fnames = ["linear-path", "random-path", "shifted-path", "source-path", "multi-grid-path"]
6860

6961
for (path, fname) in zip(paths, fnames)
70-
for d in (6, 7)
71-
agrid = cartgrid(d, d)
72-
elems = [agrid[i] for i in traverse(agrid, path)]
73-
fig = viz(elems, color=1:length(elems))
74-
@test_reference "data/$fname-$(d)x$(d).png" fig
62+
for n in (6, 7)
63+
agrid = cartgrid(n, n)
64+
pinds = collect(traverse(agrid, path))
65+
pgrid = view(agrid, pinds)
66+
fig = viz(pgrid, color=1:nelements(pgrid))
67+
@test_reference "data/$fname-$(n)x$(n).png" fig
7568
end
7669
end
7770
end

0 commit comments

Comments
 (0)