Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for string markers #14

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert.

Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
Manifest.toml
Dockerfile
.vscode/
.venv/
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [UNRELEASED] · YYYY-MM-DD
### 🌀 Changed
- Reformat sources with [Blue](https://github.com/JuliaDiff/BlueStyle) ([#12](https://github.com/cbrnr/XDF.jl/pull/12) by [Alberto Barradas](https://github.com/abcsds))
### ✨ Added
- Add tests for string markers from issue xdf-modules/libxdf#19 (([#13](https://github.com/cbrnr/XDF.jl/pull/13) by [Alberto Barradas](https://github.com/abcsds)))
Comment on lines +4 to +5
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be more specific here. You fixed an issue with string streams consisting of multiple channels, right? It would be more helpful to explicitly mention this here instead of linking to an issue. Also, I think this change should then go into the "Fixed" section, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did you mention is the template to follow? I can't find the emoji for the fixed section. I thought you mentioned a repo from xdf-modules, but their changelogs don't have emojis. I can't find the pr where it was mentioned. I thought it was #11.


## [0.2.0] · 2022-02-23
### ✨ Added
Expand Down
6 changes: 3 additions & 3 deletions src/XDF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ function read_xdf(filename::AbstractString, sync::Bool=true)
streams[id]["time"][index[id]] = previous + delta
end
if streams[id]["dtype"] === String
streams[id]["data"][index[id], :] .= String(
read(io, read_varlen_int(io))
)
for j in 1:nchannels
streams[id]["data"][index[id], j] = String(read(io, read_varlen_int(io)))
end
else
streams[id]["data"][index[id], :] = reinterpret(
dtype, read(io, sizeof(dtype) * nchannels)
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[deps]
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
37 changes: 36 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using XDF, Downloads, Test
using XDF, Downloads, Test, SHA

@testset "Minimal XDF file" begin
url = "https://github.com/xdf-modules/example-files/blob/master/minimal.xdf?raw=true"
Expand Down Expand Up @@ -71,3 +71,38 @@ end
@test endswith(streams[2]["footer"], "</clock_offsets></info>")
@test size(streams[2]["data"]) == (27815, 8)
end

@testset "strings" begin
file = "./testdata/test_chunk3.xdf"
@testset "strings.sha256" begin
open(file) do f
@test bytes2hex(sha256(f)) ==
"c730991efa078906117aa2accdca5f0ea11c54f43c3884770eba21e5a72edb82"
end
end
@testset "strings.read_xdf" begin
using XDF: XDF
streams = XDF.read_xdf(file)
end
@testset "strings.markers" begin
using XDF: XDF
streams = XDF.read_xdf(file)
s1 = streams[3735928559]
@test s1["type"] == "Marker"
@test s1["nchannels"] == 2
@test s1["srate"] == 1000.0
@test s1["dtype"] == String
@test size(s1["data"]) == (1, 2)
@test s1["data"] == ["Marker 0A" "Marker 0B"]
s2 = streams[46202862]
@test s2["type"] == "EEG"
@test s2["nchannels"] == 64
@test s2["srate"] == 1000.0
@test s2["dtype"] == Float64
@test size(s2["data"]) == (1, 64)
@test sum(s2["data"]) == 0.0
# sgs = [XDF.dejitter(streams[k])["segments"] for k in keys(streams)]
# @test sgs[1] == [(1, 1)]
# @test sgs[2] == [(1, 1)]
end
end
Binary file added test/testdata/test_chunk3.xdf
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be up for adding this file to https://github.com/xdf-modules/example-files/ instead? That way, other projects could also use this test file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binary file not shown.
Loading