-
Notifications
You must be signed in to change notification settings - Fork 5
Allow scientific notation in written numbers #70
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
Changes from all commits
a9caf8c
96dd042
3147ee8
ff6fc63
769fcda
4cb9911
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
using EDF | ||
using EDF: TimestampedAnnotationList, PatientID, RecordingID, SignalHeader, | ||
Signal, AnnotationsSignal | ||
Signal, AnnotationsSignal, _edf_repr | ||
using Dates | ||
using FilePathsBase | ||
using Test | ||
|
@@ -40,6 +40,43 @@ deep_equal(a::T, b::S) where {T,S} = false | |
const DATADIR = joinpath(@__DIR__, "data") | ||
|
||
@testset "Just Do It" begin | ||
|
||
@testset "Additional _edf_repr(x::Real, allow_scientific::Bool) tests" begin | ||
|
||
# Moderate sized numbers - should be the same either way | ||
for allow_scientific in (true, false) | ||
@test _edf_repr(0.123, allow_scientific) == "0.123" | ||
@test _edf_repr(1.123, allow_scientific) == "1.123" | ||
@test _edf_repr(10.123, allow_scientific) == "10.123" | ||
|
||
@test _edf_repr(123, allow_scientific) == "123" | ||
@test _edf_repr(123 + eps(Float64), allow_scientific) == "123" | ||
|
||
# Moderate numbers, many digits | ||
@test _edf_repr(0.8945620050698592, false) == "0.894562" | ||
end | ||
|
||
# Large numbers / few digits | ||
@test _edf_repr(0.123e10, true) == "1.23E+9" | ||
# decimal version cannot handle it: | ||
err = ArgumentError("cannot represent 1.23e9 in 8 ASCII characters") | ||
@test_throws err _edf_repr(0.123e10, false) | ||
|
||
# Large numbers / many digits | ||
@test _edf_repr(0.8945620050698592e10, true) == "8.946E+9" | ||
err = ArgumentError("cannot represent 8.945620050698591e9 in 8 ASCII characters") | ||
@test_throws err _edf_repr(0.8945620050698592e10, false) | ||
|
||
# Small numbers / few digits | ||
@test _edf_repr(0.123e-10, true) == "1.23E-11" | ||
# decimal version underflows: | ||
@test (@test_logs (:warn, r"Underflow to zero") _edf_repr(0.123e-10, false)) == "0" | ||
|
||
# Small numbers / many digits | ||
@test _edf_repr(0.8945620050698592e-10, true) == "8.95E-11" | ||
@test (@test_logs (:warn, r"Underflow to zero") _edf_repr(0.8945620050698592e-10, false)) == "0" | ||
end | ||
|
||
# test EDF.read(::AbstractString) | ||
edf = EDF.read(joinpath(DATADIR, "test.edf")) | ||
@test sprint(show, edf) == "EDF.File with 140 16-bit-encoded signals" | ||
|
@@ -68,7 +105,7 @@ const DATADIR = joinpath(@__DIR__, "data") | |
[TimestampedAnnotationList(4.0, nothing, String[""]), TimestampedAnnotationList(2.5, 2.5, ["type A"])], | ||
[TimestampedAnnotationList(5.0, nothing, String[""])]] | ||
@test all(signal.records .== expected) | ||
@test AnnotationsSignal(signal.records).samples_per_record == 16 | ||
@test AnnotationsSignal(signal.records).samples_per_record == 14 | ||
kleinschmidt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end | ||
|
||
|
@@ -113,19 +150,35 @@ const DATADIR = joinpath(@__DIR__, "data") | |
end | ||
|
||
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(-0.0023405432)) == "-0.00234" | ||
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(0.0023405432)) == "0.002340" | ||
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(0.0023405432)) == "0.002341" | ||
ericphanson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(1.002343)) == "1.002343" | ||
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(1011.05432)) == "1011.054" | ||
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(-1011.05432)) == "-1011.05" | ||
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(-1013441.5)) == "-1013442" | ||
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(-1013441.3)) == "-1013441" | ||
@test EDF._edf_repr(34577777) == "34577777" | ||
@test EDF._edf_repr(0.0345) == "0.034500" | ||
@test EDF._edf_repr(-0.02) == "-0.02000" | ||
@test EDF._edf_repr(0.0345) == "0.0345" | ||
@test EDF._edf_repr(-0.02) == "-0.02" | ||
@test EDF._edf_repr(-187.74445) == "-187.744" | ||
@test_throws ErrorException EDF._edf_repr(123456789) | ||
@test_throws ErrorException EDF._edf_repr(-12345678) | ||
@test_throws ErrorException EDF._edf_repr(0.00000000024) | ||
@test_throws ArgumentError EDF._edf_repr(123456789) | ||
@test_throws ArgumentError EDF._edf_repr(-12345678) | ||
|
||
@test (@test_logs (:warn, r"Underflow to zero") EDF._edf_repr(4.180821e-7)) == "0" | ||
@test EDF._edf_repr(4.180821e-7, true) == "4.181E-7" | ||
|
||
@test (@test_logs (:warn, r"Underflow to zero") EDF._edf_repr(floatmin(Float64))) == "0" | ||
@test EDF._edf_repr(floatmin(Float64), true) == "2.2E-308" | ||
|
||
@test_throws ArgumentError EDF._edf_repr(floatmax(Float64)) | ||
@test EDF._edf_repr(floatmax(Float64), true) == "1.8E+308" | ||
|
||
# We still get errors if we too "big" (in the exponent) | ||
@test_throws ArgumentError EDF._edf_repr(big"1e-999999", true) | ||
@test_throws ArgumentError EDF._edf_repr(big"1e999999", true) | ||
|
||
# if we don't allow scientific notation, we allow rounding down here | ||
@test (@test_logs (:warn, r"Underflow to zero") EDF._edf_repr(0.00000000024)) == "0" | ||
@test EDF._edf_repr(0.00000000024, true) == "2.4E-10" | ||
@test_throws ErrorException EDF.edf_write(IOBuffer(), "hahahahaha", 4) | ||
|
||
uneven = EDF.read(joinpath(DATADIR, "test_uneven_samp.edf")) | ||
|
@@ -246,10 +299,10 @@ end | |
|
||
@testset "BDF+ Files" begin | ||
# This is a `BDF+` file containing only trigger information. | ||
# It is similiar to a `EDF Annotations` file except that | ||
# It is similiar to a `EDF Annotations` file except that | ||
# The `ANNOTATIONS_SIGNAL_LABEL` is `BDF Annotations`. | ||
# The test data has 1081 trigger events, and | ||
# has 180 trials in total, and | ||
# The test data has 1081 trigger events, and | ||
# has 180 trials in total, and | ||
Comment on lines
-249
to
+305
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert these whitesapce changes to keep blame clean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've configured vscode to remove trailing whitespace, so I will need to do this at the end (otherwise if I touch the file again it will re-introduce it). So your comment is noted but I won't address it until the PR is ready to merge. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there no autoformatting set up on this repo? it's possible given that it's kind of ancient... |
||
# The annotation `255` signifies the offset of a trial. | ||
# More information, contact: zhanlikan@hotmail.com | ||
evt = EDF.read(joinpath(DATADIR, "evt.bdf")) | ||
|
Uh oh!
There was an error while loading. Please reload this page.