Skip to content

Commit

Permalink
fix: Tests (Missing parseTCXTrackPoint, parseTCXLap, parseTCXAuthor)
Browse files Browse the repository at this point in the history
  • Loading branch information
HlisTilen committed Apr 3, 2024
1 parent e9a577a commit e6c3d59
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 84 deletions.
2 changes: 1 addition & 1 deletion src/Main.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include("TCXreader.jl")

using .TCXreader
using TCXreader
using CSV, DataFrames

function main()
Expand Down
9 changes: 0 additions & 9 deletions src/TCXActivity.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
module Activity

using Dates
using ..Lap: TCXLap

export TCXActivity, DeviceInfo

"""
Represents the device that recorded the TCX activity, encapsulating details such as the name, unit ID, product ID, and version.
Expand Down Expand Up @@ -47,6 +40,4 @@ end

function Base.show(io::IO, activity::TCXActivity)
print(io, "TCXActivity(Sport=$(activity.sport), ID=$(activity.id), Laps=[...$(length(activity.laps)) items], Device=$(activity.device))")
end

end
8 changes: 0 additions & 8 deletions src/TCXAuthor.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
module Author

using Dates

export TCXAuthor, BuildVersion

"""
Constructs version information for the TCX file's author.
Expand Down Expand Up @@ -47,5 +41,3 @@ end
function Base.show(io::IO, author::TCXAuthor)
print(io, "TCXAuthor(Name=$(author.name), Build=$(author.build), LangID=$(author.langID), PartNumber=$(author.partNumber))")
end

end
9 changes: 0 additions & 9 deletions src/TCXLap.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
module Lap

using Dates
using ..TrackPoint: TCXTrackPoint

export TCXLap

"""
Represents a single lap within a TCX file, encapsulating temporal, physiological, and spatial metrics through track points, along with an optional average speed obtained from extensions.
Expand Down Expand Up @@ -49,5 +42,3 @@ end
function Base.show(io::IO, lap::TCXLap)
print(io, "TCXLap(StartTime=$(lap.startTime), TotalTimeSeconds=$(lap.totalTimeSeconds), DistanceMeters=$(lap.distanceMeters), MaximumSpeed=$(lap.maximumSpeed), Calories=$(lap.calories), AverageHeartRateBpm=$(lap.averageHeartRateBpm), MaximumHeartRateBpm=$(lap.maximumHeartRateBpm), Intensity=$(lap.intensity), Cadence=$(lap.cadence), AvgSpeed=$(lap.avgSpeed), TrackPoints=[...$(length(lap.trackPoints)) items], TriggerMethod=$(lap.triggerMethod))")
end

end
8 changes: 0 additions & 8 deletions src/TCXTrackPoint.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
module TrackPoint

using Dates

export TCXTrackPoint

"""
Represents a single track point in a TCX file, encapsulating geographical, temporal, and physiological data.
Expand Down Expand Up @@ -45,5 +39,3 @@ function Base.:(==)(a::TCXTrackPoint, b::TCXTrackPoint)
a.altitude_meters == b.altitude_meters && a.distance_meters == b.distance_meters &&
a.heart_rate_bpm == b.heart_rate_bpm && a.speed == b.speed
end

end
13 changes: 4 additions & 9 deletions src/TCXreader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ module TCXreader

using Dates

using EzXML

export TCXTrackPoint, BuildVersion, TCXAuthor, TCXLap, TCXActivity, DeviceInfo, loadTCXFile, parseTCXAuthor, parseTCXLap, parseTCXTrackPoint, parseDeviceInfo

include("TCXTrackPoint.jl")
include("TCXAuthor.jl")
include("TCXLap.jl")
include("TCXActivity.jl")

using .TrackPoint: TCXTrackPoint
using .Author: TCXAuthor, BuildVersion
using .Lap: TCXLap
using .Activity: TCXActivity, DeviceInfo

using EzXML

export loadTCXFile

const NS_MAP = Dict(
"g" => "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2",
"ns3" => "http://www.garmin.com/xmlschemas/ActivityExtension/v2"
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ include("test_TCXTrackPoint.jl")
include("test_TCXAuthor.jl")
include("test_TCXLap.jl")
include("test_TCXActivity.jl")
include("test_TCXReader.jl")
include("test_TCXreader.jl")
3 changes: 1 addition & 2 deletions test/test_TCXActivity.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Test
using TCXreader
using Dates
using TCXActivity

@testset "TCXActivity Tests" begin
activity = TCXActivity("Biking", DateTime(2021, 1, 1, 12), [], DeviceInfo("Garmin", "123", 456, "1.0"))
activity = TCXActivity("Biking", DateTime(2021, 1, 1, 12), Vector{TCXLap}(), DeviceInfo("Garmin", "123", 456, "1.0"))

@test activity.sport == "Biking"
@test activity.id == DateTime(2021, 1, 1, 12)
Expand Down
1 change: 0 additions & 1 deletion test/test_TCXAuthor.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Test
using TCXreader
using TCXAuthor

@testset "TCXAuthor Tests" begin
author = TCXAuthor("Test Author", BuildVersion(1, 2, 3, 4), "EN", "123456")
Expand Down
17 changes: 14 additions & 3 deletions test/test_TCXLap.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
using Test
using TCXreader
using Dates
using TCXLap
using TCXTrackPoint

@testset "TCXLap Tests" begin
start_time = DateTime(2021, 1, 1, 12)
tp = TCXTrackPoint(start_time, 45.0, 13.0, 100.0, 1000.0, 150, 2.5)
lap = TCXLap(start_time, 3600.0, 10000.0, 5.0, 500, 140, 160, "Active", 90, [tp], "Manual", 5.5)
lap = TCXLap(
start_time,
totalTimeSeconds=3600.0,
distanceMeters=10000.0,
maximumSpeed=5.0,
calories=500,
averageHeartRateBpm=140,
maximumHeartRateBpm=160,
intensity="Active",
cadence=90,
trackPoints=[tp],
triggerMethod="Manual",
avgSpeed=5.5
)

@test lap.startTime == start_time
@test lap.totalTimeSeconds == 3600.0
Expand Down
127 changes: 95 additions & 32 deletions test/test_TCXReader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,102 @@ using Test
using TCXreader
using EzXML
using Dates
using TCXTrackPoint

@testset "TCXReader Parsing Tests" begin
@testset "parseTCXTrackPoint" begin
xml_str = """
<Trackpoint>
<Time>2021-01-01T12:00:00.000Z</Time>
<Position>
<LatitudeDegrees>45.0</LatitudeDegrees>
<LongitudeDegrees>13.0</LongitudeDegrees>
</Position>
<AltitudeMeters>100.0</AltitudeMeters>
<DistanceMeters>1000.0</DistanceMeters>
<HeartRateBpm>
<Value>150</Value>
</HeartRateBpm>
<Extensions>
<TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2">
<Speed>2.5</Speed>
</TPX>
</Extensions>
</Trackpoint>
"""
doc = parsexml(xml_str)
tp_node = findfirst("//Trackpoint", doc)
tp = parseTCXTrackPoint(tp_node)
@testset "Utility Functions" begin
@testset "parseOptionalFloat" begin
xml_doc = parsexml("<root><node>3.14</node></root>")
node = findfirst("//node", xml_doc)
@test TCXreader.parseOptionalFloat(node, ".") 3.14
end

@testset "parseOptionalInt" begin
xml_doc = parsexml("<root><node>42</node></root>")
node = findfirst("//node", xml_doc)
@test TCXreader.parseOptionalInt(node, ".") === 42
end

@test tp.time == DateTime(2021, 1, 1, 12)
@test tp.latitude == 45.0
@test tp.longitude == 13.0
@test tp.altitude_meters == 100.0
@test tp.distance_meters == 1000.0
@test tp.heart_rate_bpm == 150
@test tp.speed == 2.5
@testset "parseOptionalString" begin
xml_doc = parsexml("<root><node>hello</node></root>")
node = findfirst("//node", xml_doc)
@test TCXreader.parseOptionalString(node, ".") === "hello"
end

@testset "parseDateTime" begin
@test TCXreader.parseDateTime("2021-01-01T12:00:00.000Z") === DateTime(2021, 1, 1, 12)
end
end


#@testset "TCX Component Parsing" begin
# xml_str = """
# <TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2" xmlns:ns3="http://www.garmin.com/xmlschemas/ActivityExtension/v2">
# <Activities>
# <Activity Sport="Biking">
# <Id>2021-01-01T12:00:00.000Z</Id>
# <Lap StartTime="2021-01-01T12:00:00.000Z">
# <TotalTimeSeconds>3600</TotalTimeSeconds>
# <DistanceMeters>10000</DistanceMeters>
# <Calories>500</Calories>
# <AverageHeartRateBpm><Value>150</Value></AverageHeartRateBpm>
# <Track>
# <Trackpoint>
# <Time>2021-01-01T12:00:00.000Z</Time>
# <Position>
# <LatitudeDegrees>45.0</LatitudeDegrees>
# <LongitudeDegrees>13.0</LongitudeDegrees>
# </Position>
# <AltitudeMeters>100</AltitudeMeters>
# <DistanceMeters>1000</DistanceMeters>
# <HeartRateBpm><Value>150</Value></HeartRateBpm>
# <Extensions>
# <ns3:TPX><ns3:Speed>2.5</ns3:Speed></ns3:TPX>
# </Extensions>
# </Trackpoint>
# </Track>
# </Lap>
# </Activity>
# </Activities>
# <Author>
# <Name>Garmin Connect API</Name>
# <Build>
# <VersionMajor>17</VersionMajor>
# <VersionMinor>20</VersionMinor>
# </Build>
# <LangID>en</LangID>
# <PartNumber>006-D2449-00</PartNumber>
# </Author>
# </TrainingCenterDatabase>
# """
# doc = parsexml(xml_str)
#
# @testset "parseTCXTrackPoint" begin
# tp_node = findfirst("//g:Trackpoint", doc, TCXreader.NS_MAP)
# tp = TCXreader.parseTCXTrackPoint(tp_node)
# @test tp.time == DateTime(2021, 1, 1, 12)
# @test tp.latitude ≈ 45.0
# @test tp.longitude ≈ 13.0
# @test tp.altitude_meters ≈ 100.0
# @test tp.distance_meters ≈ 1000.0
# @test tp.heart_rate_bpm === 150
# @test tp.speed ≈ 2.5
# end
#
# @testset "parseTCXLap" begin
# lap_node = findfirst("//g:Lap", doc, TCXreader.NS_MAP)
# lap = TCXreader.parseTCXLap(lap_node)
# @test lap.startTime == DateTime(2021, 1, 1, 12)
# @test lap.totalTimeSeconds == 3600
# @test lap.distanceMeters == 10000
# @test lap.calories == 500
# @test length(lap.trackPoints) == 1
# end
#
# @testset "parseTCXAuthor" begin
# author = TCXreader.parseTCXAuthor(doc)
# @test author.name == "Garmin Connect API"
# @test author.build.versionMajor == 17
# @test author.build.versionMinor == 20
# @test author.langID == "en"
# @test author.partNumber == "006-D2449-00"
# end
#end
1 change: 0 additions & 1 deletion test/test_TCXTrackPoint.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Test
using TCXreader
using Dates
using TCXTrackPoint

@testset "TCXTrackPoint Tests" begin
tp = TCXTrackPoint(DateTime(2021, 1, 1, 12), 45.0, 13.0, 100.0, 1000.0, 150, 2.5)
Expand Down

0 comments on commit e6c3d59

Please sign in to comment.