|
13 | 13 | @static if VERSION > v"0.7-"
|
14 | 14 | @test getindices(d, (aa = :a, cc = :c)) == (aa = "Alice", cc = "Charlie")
|
15 | 15 | end
|
| 16 | + @test getindices(d, :) == d |
16 | 17 |
|
17 | 18 | v = [11, 12, 13]
|
18 | 19 | @test (getindices(v, 2)::Array{Int, 0})[] == 12
|
|
22 | 23 | @static if VERSION > v"0.7-"
|
23 | 24 | @test getindices(v, (a = 1, c = 3)) === (a = 11, c = 13)
|
24 | 25 | end
|
| 26 | + @test getindices(v, :) == v |
25 | 27 |
|
26 | 28 | t = (11, 12, 13)
|
27 | 29 | @test getindices(t, [1, 3]) == [11, 13]
|
|
30 | 32 | @static if VERSION > v"0.7-"
|
31 | 33 | @test getindices(t, (a = 1, c = 3)) === (a = 11, c = 13)
|
32 | 34 | end
|
| 35 | + @test getindices(t, :) == t |
33 | 36 |
|
34 | 37 | @static if VERSION > v"0.7-"
|
35 | 38 | nt = (a = 1, b = 2.0, c = "three")
|
36 | 39 | @test getindices(nt, [:a, :c]) == [1, "three"]
|
37 | 40 | @test getindices(nt, Dict(:aa => :a, :cc => :c)) == Dict(:aa => 1, :cc => "three")
|
38 | 41 | @test getindices(nt, (:a, :c)) == (1, "three")
|
39 | 42 | @test getindices(nt, (aa = :a, cc = :c)) == (aa = 1, cc = "three")
|
| 43 | + @test getindices(nt, :) == nt |
40 | 44 | end
|
41 | 45 | end
|
42 | 46 |
|
|
60 | 64 | @test d5 == Dict(:a => "Someone", :b => "Bob", :c => "Someone")
|
61 | 65 | end
|
62 | 66 |
|
| 67 | + d6 = copy(d) |
| 68 | + setindices!(d6, "Someone", :) |
| 69 | + @test d6 == Dict(:a => "Someone", :b => "Someone", :c => "Someone") |
| 70 | + |
63 | 71 | v = [11, 12, 13]
|
64 | 72 | v2 = copy(v)
|
65 | 73 | setindices!(v2, 20, [1, 3])
|
|
78 | 86 | setindices!(v5, 20, (a = 1, c = 3))
|
79 | 87 | @test v5 == [20, 12, 20]
|
80 | 88 | end
|
| 89 | + |
| 90 | + v6 = copy(v) |
| 91 | + setindices!(v6, 20, :) |
| 92 | + @test v6 == [20, 20, 20] |
81 | 93 | end
|
82 | 94 |
|
83 | 95 | @testset "view" begin
|
84 | 96 | d = Dict(:a => "Alice", :b => "Bob", :c => "Charlie")
|
| 97 | + d2 = copy(d) |
85 | 98 |
|
86 | 99 | @test view(d, [:a, :c])::ViewArray == ["Alice", "Charlie"]
|
87 | 100 | @test view(d, Dict(:aa => :a, :cc => :c))::ViewDict == Dict(:aa => "Alice", :cc => "Charlie")
|
88 | 101 |
|
89 | 102 | av = view(d, [:a, :c])
|
| 103 | + @test parent(av) === d |
| 104 | + @test av[1] == "Alice" |
| 105 | + @test Indexing.axes(av) === (Base.OneTo(2),) |
90 | 106 | av[1] = "Someone"
|
91 | 107 | @test d == Dict(:a => "Someone", :b => "Bob", :c => "Charlie")
|
92 | 108 |
|
93 |
| - dv = view(d, Dict(:aa => :a, :cc => :c)) |
| 109 | + dv = view(d2, Dict(:aa => :a, :cc => :c)) |
| 110 | + @test parent(dv) === d2 |
| 111 | + @test dv[:aa] == "Alice" |
| 112 | + @test keys(dv) ⊆ [:aa, :cc] # Probably will want to change this |
| 113 | + @test length(keys(dv)) == 2 |
| 114 | + @test haskey(dv, :aa) |
94 | 115 | dv[:aa] = "No-one"
|
95 |
| - @test d == Dict(:a => "No-one", :b => "Bob", :c => "Charlie") |
| 116 | + @test d2 == Dict(:a => "No-one", :b => "Bob", :c => "Charlie") |
96 | 117 |
|
97 | 118 | v = [11, 12, 13]
|
98 | 119 |
|
99 | 120 | @test view(v, Dict(:a =>1 , :c => 3))::ViewDict == Dict(:a => 11, :c => 13)
|
100 | 121 |
|
101 | 122 | dv2 = view(v, Dict(:a =>1 , :c => 3))
|
| 123 | + @test parent(dv2) === v |
| 124 | + @test dv2[:a] == 11 |
| 125 | + @test keys(dv2) ⊆ [:a, :c] |
| 126 | + @test length(keys(dv2)) == 2 |
| 127 | + @test haskey(dv2, :a) |
102 | 128 | dv2[:a] = 21
|
103 | 129 | @test v == [21, 12, 13]
|
| 130 | + |
| 131 | + @test ViewArray(d, [:b, :c])::ViewArray == ["Bob", "Charlie"] |
| 132 | + @test ViewVector(d, [:b, :c])::ViewVector == ["Bob", "Charlie"] |
| 133 | + @test ViewMatrix(d, [:b :c; :c :b])::ViewMatrix == ["Bob" "Charlie"; "Charlie" "Bob"] |
104 | 134 | end
|
0 commit comments