@@ -112,4 +112,111 @@ using Test, PreallocationTools, ForwardDiff
112112        copy_cache. du[1 , 1 ] =  - 999 
113113        @test  cache. du[1 , 1 ] !=  - 999 
114114    end 
115+ end 
116+ 
117+ @testset  " fill! dispatches"   begin 
118+     @testset  " DiffCache fill!"   begin 
119+         u =  rand (10 )
120+         cache =  DiffCache (u, 5 )
121+         
122+         #  Fill with non-zero values initially
123+         fill! (cache. du, 1.0 )
124+         fill! (cache. dual_du, 2.0 )
125+         push! (cache. any_du, 3.0 )
126+         
127+         #  Test fill! with 0
128+         fill! (cache, 0.0 )
129+         @test  all (cache. du .==  0 )
130+         @test  all (cache. dual_du .==  0 )
131+         @test  all (cache. any_du .===  nothing )
132+         
133+         #  Test fill! with other values
134+         fill! (cache, 5.0 )
135+         @test  all (cache. du .==  5.0 )
136+         @test  all (cache. dual_du .==  5.0 )
137+     end 
138+     
139+     @testset  " FixedSizeDiffCache fill!"   begin 
140+         u =  rand (10 )
141+         cache =  FixedSizeDiffCache (u, Val{5 })
142+         
143+         #  Fill with non-zero values initially
144+         fill! (cache. du, 1.0 )
145+         fill! (cache. dual_du, 2.0 )
146+         push! (cache. any_du, 3.0 )
147+         
148+         #  Test fill! with 0
149+         fill! (cache, 0.0 )
150+         @test  all (cache. du .==  0 )
151+         @test  all (cache. dual_du .==  0 )
152+         @test  all (cache. any_du .===  nothing )
153+         
154+         #  Test fill! with other values
155+         fill! (cache, 3.0 )
156+         @test  all (cache. du .==  3.0 )
157+         @test  all (cache. dual_du .==  3.0 )
158+     end 
159+     
160+     @testset  " LazyBufferCache fill!"   begin 
161+         lbc =  LazyBufferCache (identity)
162+         u =  rand (10 )
163+         v =  rand (5 , 5 )
164+         
165+         #  Create and fill buffers
166+         buf1 =  lbc[u]
167+         fill! (buf1, 1.0 )
168+         buf2 =  lbc[v]
169+         fill! (buf2, 2.0 )
170+         
171+         #  Test fill! with 0
172+         fill! (lbc, 0.0 )
173+         @test  all (buf1 .==  0 )
174+         @test  all (buf2 .==  0 )
175+         #  Check that the buffers are still in the cache
176+         @test  lbc[u] ===  buf1
177+         @test  lbc[v] ===  buf2
178+         
179+         #  Test fill! with other values
180+         fill! (lbc, 7.0 )
181+         @test  all (buf1 .==  7.0 )
182+         @test  all (buf2 .==  7.0 )
183+     end 
184+     
185+     @testset  " GeneralLazyBufferCache fill!"   begin 
186+         glbc =  GeneralLazyBufferCache (u ->  similar (u))
187+         u =  rand (10 )
188+         
189+         #  Create and fill buffer
190+         buf =  glbc[u]
191+         fill! (buf, 1.0 )
192+         
193+         #  Test fill! with 0
194+         fill! (glbc, 0.0 )
195+         @test  all (buf .==  0 )
196+         #  Check that the buffer is still in the cache
197+         @test  glbc[u] ===  buf
198+         
199+         #  Test fill! with other values
200+         fill! (glbc, - 2.5 )
201+         @test  all (buf .==  - 2.5 )
202+     end 
203+     
204+     @testset  " LazyBufferCache fill! with mixed types"   begin 
205+         lbc =  LazyBufferCache (identity)
206+         u_float =  rand (Float64, 10 )
207+         u_int =  rand (Int, 5 )
208+         
209+         #  Create and fill buffers
210+         buf_float =  lbc[u_float]
211+         fill! (buf_float, 1.5 )
212+         buf_int =  lbc[u_int]
213+         fill! (buf_int, 7 )
214+         
215+         #  Test fill! with 0
216+         fill! (lbc, 0 )
217+         @test  all (buf_float .==  0.0 )
218+         @test  all (buf_int .==  0 )
219+         @test  eltype (buf_float) ==  Float64
220+         @test  eltype (buf_int) ==  Int
221+     end 
115222end 
0 commit comments