Skip to content

Commit d663591

Browse files
committed
Add tests for colons
1 parent 49922f0 commit d663591

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

test/hasvalue.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
@test getvalue(nt, @varname(a)) == [1]
66
@test hasvalue(nt, @varname(a[1]))
77
@test getvalue(nt, @varname(a[1])) == 1
8+
@test hasvalue(nt, @varname(a[:]))
9+
@test getvalue(nt, @varname(a[:])) == [1]
810
@test hasvalue(nt, @varname(b))
911
@test getvalue(nt, @varname(b)) == 2
1012
@test hasvalue(nt, @varname(c))
1113
@test getvalue(nt, @varname(c)) == (x=3, y=[4], z=(; p=[(; q=5)]))
14+
@test hasvalue(nt, @varname(c[:]))
15+
@test getvalue(nt, @varname(c[:])) == (x=3, y=[4], z=(; p=[(; q=5)]))
1216
@test hasvalue(nt, @varname(c.x))
1317
@test getvalue(nt, @varname(c.x)) == 3
1418
@test hasvalue(nt, @varname(c.y))
@@ -35,6 +39,8 @@
3539
@test getvalue(nt, @varname(d[2, 2])) == 1.0
3640
@test hasvalue(nt, @varname(d[3])) # linear indexing works....
3741
@test getvalue(nt, @varname(d[3])) == 0.5
42+
@test hasvalue(nt, @varname(d[:]))
43+
@test getvalue(nt, @varname(d[:])) == [1.0, 0.5, 0.5, 1.0]
3844
@test !hasvalue(nt, @varname(nope))
3945
@test !hasvalue(nt, @varname(a[2]))
4046
@test !hasvalue(nt, @varname(a[1][1]))
@@ -58,10 +64,14 @@
5864
@test getvalue(d, @varname(a)) == [1]
5965
@test hasvalue(d, @varname(a[1]))
6066
@test getvalue(d, @varname(a[1])) == 1
67+
@test hasvalue(d, @varname(a[:]))
68+
@test getvalue(d, @varname(a[:])) == [1]
6169
@test hasvalue(d, @varname(b))
6270
@test getvalue(d, @varname(b)) == 2
6371
@test hasvalue(d, @varname(c))
6472
@test getvalue(d, @varname(c)) == (x=3, y=[4], z=(; p=[(; q=5)]))
73+
@test hasvalue(d, @varname(c[:]))
74+
@test getvalue(d, @varname(c[:])) == (x=3, y=[4], z=(; p=[(; q=5)]))
6575
@test hasvalue(d, @varname(c.x))
6676
@test getvalue(d, @varname(c.x)) == 3
6777
@test hasvalue(d, @varname(c.y))
@@ -88,6 +98,8 @@
8898
@test getvalue(d, @varname(d[2, 2])) == 1.0
8999
@test hasvalue(d, @varname(d[3])) # linear indexing works....
90100
@test getvalue(d, @varname(d[3])) == 0.5
101+
@test hasvalue(d, @varname(d[:]))
102+
@test getvalue(d, @varname(d[:])) == [1.0, 0.5, 0.5, 1.0]
91103
@test !hasvalue(d, @varname(nope))
92104
@test !hasvalue(d, @varname(a[2]))
93105
@test !hasvalue(d, @varname(a[1][1]))
@@ -185,7 +197,7 @@ end
185197
)
186198
@test hasvalue(d, @varname(x), LKJCholesky(2, 1.0))
187199
@test getvalue(d, @varname(x), LKJCholesky(2, 1.0)) ==
188-
Cholesky(LowerTriangular([1.0 0.0; 2.0 3.0]))
200+
Cholesky(LowerTriangular([1.0 0.0; 2.0 3.0]))
189201
@test !hasvalue(d, @varname(x), LKJCholesky(3, 1.0))
190202
@test_throws ErrorException hasvalue(
191203
d, @varname(x), LKJCholesky(3, 1.0); error_on_incomplete=true
@@ -199,7 +211,7 @@ end
199211
)
200212
@test hasvalue(d, @varname(x), LKJCholesky(2, 1.0, :U))
201213
@test getvalue(d, @varname(x), LKJCholesky(2, 1.0, :U)) ==
202-
Cholesky(UpperTriangular([1.0 2.0; 0.0 3.0]))
214+
Cholesky(UpperTriangular([1.0 2.0; 0.0 3.0]))
203215
@test !hasvalue(d, @varname(x), LKJCholesky(3, 1.0, :U))
204216
@test_throws ErrorException hasvalue(
205217
d, @varname(x), LKJCholesky(3, 1.0, :U); error_on_incomplete=true

0 commit comments

Comments
 (0)