Skip to content

Commit

Permalink
Refactor and add data write roundtripping tests
Browse files Browse the repository at this point in the history
  • Loading branch information
halleysfifthinc committed Aug 10, 2024
1 parent 22f2a70 commit ecfe329
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
21 changes: 21 additions & 0 deletions test/testutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ function readdir_recursive(dir; join=false)
return outfiles
end

function comparedata(fn)
f = readc3d(fn)
datastart = (f.header.datastart - 1)*512
fio = open(fn)
seek(fio, datastart)
refdata = read(fio)
seek(fio, datastart)

format = f.groups[:POINT][Float32, :SCALE] > 0 ? Int16 : eltype(endianness(f))::Type
ref = C3D.readdata(fio, f.header, f.groups, format)

compio = IOBuffer()
nb = C3D.writedata(compio, f)
compdata = take!(copy(compio))

seekstart(compio)
comp = C3D.readdata(compio, C3D.Header(f), f.groups, format)

return (refdata, ref), (compdata, comp)
end

function comparefiles(reference, candidate)
@test_nothrow readc3d(reference; missingpoints=false)
ref = readc3d(reference; missingpoints=false)
Expand Down
32 changes: 25 additions & 7 deletions test/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,31 @@ end
end
end

@testset "Whole file: artifact\"$art\"" for art in ["sample01"]#, "sample02", "sample08"]
@testset failfast=true "File \"$(replace(fn, @artifact_str(art)*'/' => ""))\"" for fn in filter(contains(r".c3d$"i), readdir_recursive(@artifact_str(art); join=true))
p, io = mktemp()
writec3d(io, readc3d(fn))
flush(io)
close(io)
comparefiles(fn, p)
@testset "Data:" begin
@testset "artifact\"$art\"" for art in artifacts
allfiles = filter(contains(r".c3d$"i), readdir_recursive(@artifact_str(art); join=true))
@testset "File \"$(replace(fn, @artifact_str(art)*'/' => ""))\"" for fn in allfiles
# these 2 artifact"sample30" files have incorrectly formated residuals that we don't
# intend to replicate/match
fn == artifact"sample30/admarche2.c3d" && continue
fn == artifact"sample30/marche281.c3d" && continue

ref, comp = comparedata(fn)
refdata, (refpoint, refresidual, refanalog) = ref
compdata, (comppoint, compresidual, companalog) = comp

passpoint = @test refpoint == comppoint
passresidual = @test refresidual == compresidual
passanalog = @test refanalog == companalog
fails = any(p -> p isa Test.Fail, (passpoint, passresidual, passanalog))

nb = length(compdata)
if checkindex(Bool, eachindex(refdata), nb)
@test @view(refdata[begin:nb]) == compdata broken=fails
elseif checkindex(Bool, eachindex(compdata), length(refdata))
@test refdata == @view(compdata[begin:length(refdata)]) broken=fails
end
end
end
end
end

0 comments on commit ecfe329

Please sign in to comment.