Skip to content

Commit 1cc7b76

Browse files
author
Jeremiah Lewis
committed
tests pass
1 parent bd17951 commit 1cc7b76

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

test/episodes.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ using Test
285285
show(eb);
286286
=#
287287
end
288+
288289
@testset "ElasticArraySARTSATraces with PartialNamedTuple" begin
289290
eb = EpisodesBuffer(
290291
ElasticArraySARTSATraces()
@@ -312,8 +313,8 @@ using Test
312313
@test eb.step_numbers[end] == 1
313314
@test eb.sampleable_inds == [1,1,1,1,1,0,0]
314315
@test eb[:action][6] == 6
315-
@test eb[:next_action][6] == 6
316-
@test eb[6][:reward] == 0 #6 is not a valid index, the reward there is dummy, filled as zero
316+
@test eb[:next_action][5] == 6
317+
@test eb[:reward][6] == 0 #6 is not a valid index, the reward there is dummy, filled as zero
317318
ep2_len = 0
318319
for (j,i) = enumerate(8:11)
319320
ep2_len += 1
@@ -325,7 +326,6 @@ using Test
325326
end
326327
@test eb.sampleable_inds == [1,1,1,1,1,0,1,1,1,1,0]
327328
@test length(eb.traces) == 9 #an action is missing at this stage
328-
#three last steps replace oldest steps in the buffer.
329329
for (i, s) = enumerate(12:13)
330330
ep2_len += 1
331331
push!(eb, (state = s, action =s-1, reward = s-1, terminal = false))
@@ -335,18 +335,18 @@ using Test
335335
@test eb.episodes_lengths[end-ep2_len:end] == fill(ep2_len, ep2_len + 1)
336336
end
337337
push!(eb, PartialNamedTuple((action = 13,)))
338-
@test length(eb.traces) == 10
338+
@test length(eb.traces) == 12
339339
#episode 1
340-
for (i,s) in enumerate(3:13)
341-
if i in (4, 11)
340+
for i in 1:13
341+
if i in (6, 13)
342342
@test eb.sampleable_inds[i] == 0
343343
continue
344344
else
345345
@test eb.sampleable_inds[i] == 1
346346
end
347347
b = eb[i]
348-
@test b[:state] == b[:action] == b[:reward] == s
349-
@test b[:next_state] == b[:next_action] == s + 1
348+
@test b[:state] == b[:action] == b[:reward] == i
349+
@test b[:next_state] == b[:next_action] == i + 1
350350
end
351351
#episode 2
352352
#start a third episode
@@ -360,9 +360,9 @@ using Test
360360
push!(eb, (state = s, action =s-1, reward = s-1, terminal = false))
361361
end
362362
push!(eb, PartialNamedTuple((action = 26,)))
363-
@test eb.sampleable_inds == [fill(true, 10); [false]]
364-
@test eb.episodes_lengths == fill(length(15:26), 11)
365-
@test eb.step_numbers == [3:13;]
363+
@test eb.sampleable_inds[end-10:end] == [fill(true, 10); [false]]
364+
@test eb.episodes_lengths[end-10:end] == fill(length(15:26), 11)
365+
@test eb.step_numbers[end-10:end] == [3:13;]
366366
#= Deactivated until https://github.com/JuliaArrays/ElasticArrays.jl/pull/56/files merged and pop!/popfirst! added to ElasticArrays
367367
step = popfirst!(eb)
368368
@test length(eb) == length(eb.sampleable_inds) - 1 == length(eb.step_numbers) - 1 == length(eb.episodes_lengths) - 1 == 9

test/traces.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ end
139139

140140
@testset "build_trace_index ElasticArraySARTSATraces" begin
141141
t1 = ElasticArraySARTSATraces(;
142-
capacity=3,
143142
state=Float32 => (2, 3),
144143
action=Float32 => (2,),
145144
reward=Float32 => (),
@@ -171,6 +170,29 @@ end
171170
@test size(Base.getindex(t1, 1).state) == (2,3)
172171

173172

173+
t2 = Traces(; a=[2, 3], b=[false, true])
174+
push!(t2, Val(:a), 5)
175+
@test t2[:a][3] == 5
176+
177+
@test size(Base.getindex(t2, :a)) == (3,)
178+
@test Base.getindex(t2, 1) == (; a = 2, b= false)
179+
end
180+
181+
182+
@testset "push!(ts::Traces{names,Trs,N,E}, ::Val{k}, v)" begin
183+
t1 = ElasticArraySARTSATraces(
184+
state=Float32 => (2, 3),
185+
action=Float32 => (2,),
186+
reward=Float32 => (),
187+
terminal=Bool => ()
188+
)
189+
push!(t1, Val(:reward), 5)
190+
@test t1[:reward][1] == 5
191+
192+
@test size(Base.getindex(t1, :reward)) == (1,)
193+
@test size(Base.getindex(t1, :state)) == (0,)
194+
195+
174196
t2 = Traces(; a=[2, 3], b=[false, true])
175197
push!(t2, Val(:a), 5)
176198
@test t2[:a][3] == 5

0 commit comments

Comments
 (0)