gpx 0.8.3 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +37 -0
  3. data/.gitignore +4 -0
  4. data/.rubocop +1 -0
  5. data/.rubocop.yml +162 -0
  6. data/.ruby-version +1 -0
  7. data/.tool-versions +1 -0
  8. data/.travis.yml +4 -6
  9. data/CHANGELOG.md +32 -0
  10. data/Gemfile +2 -0
  11. data/LICENSE.txt +1 -1
  12. data/README.md +38 -17
  13. data/Rakefile +22 -12
  14. data/UPGRADING.md +7 -0
  15. data/bin/gpx_distance +5 -6
  16. data/bin/gpx_smooth +25 -26
  17. data/gpx.gemspec +14 -11
  18. data/lib/gpx/bounds.rb +13 -31
  19. data/lib/gpx/geo_json.rb +199 -0
  20. data/lib/gpx/gpx.rb +4 -26
  21. data/lib/gpx/gpx_file.rb +140 -134
  22. data/lib/gpx/magellan_track_log.rb +34 -66
  23. data/lib/gpx/point.rb +22 -35
  24. data/lib/gpx/route.rb +10 -31
  25. data/lib/gpx/segment.rb +63 -90
  26. data/lib/gpx/track.rb +38 -42
  27. data/lib/gpx/track_point.rb +32 -0
  28. data/lib/gpx/version.rb +3 -1
  29. data/lib/gpx/waypoint.rb +10 -34
  30. data/lib/gpx.rb +13 -34
  31. data/tests/geojson_files/combined_data.json +68 -0
  32. data/tests/geojson_files/line_string_data.json +83 -0
  33. data/tests/geojson_files/multi_line_string_data.json +74 -0
  34. data/tests/geojson_files/multi_point_data.json +14 -0
  35. data/tests/geojson_files/point_data.json +22 -0
  36. data/tests/geojson_test.rb +92 -0
  37. data/tests/gpx10_test.rb +7 -6
  38. data/tests/gpx_file_test.rb +31 -19
  39. data/tests/gpx_files/one_segment_mixed_times.gpx +884 -0
  40. data/tests/gpx_files/routes_without_names.gpx +29 -0
  41. data/tests/gpx_files/with_empty_tracks.gpx +72 -0
  42. data/tests/magellan_test.rb +12 -11
  43. data/tests/output_test.rb +93 -94
  44. data/tests/route_test.rb +75 -30
  45. data/tests/segment_test.rb +104 -93
  46. data/tests/track_file_test.rb +50 -70
  47. data/tests/track_point_test.rb +22 -11
  48. data/tests/track_test.rb +73 -61
  49. data/tests/waypoint_test.rb +46 -48
  50. metadata +45 -13
  51. data/lib/gpx/trackpoint.rb +0 -60
data/lib/gpx.rb CHANGED
@@ -1,38 +1,17 @@
1
- #--
2
- # Copyright (c) 2006 Doug Fales
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
1
+ # frozen_string_literal: true
23
2
 
24
3
  require 'time'
25
4
  require 'nokogiri'
26
5
 
27
- require File.expand_path('../gpx/version', __FILE__)
28
-
29
- require File.expand_path('../gpx/gpx', __FILE__)
30
- require File.expand_path('../gpx/gpx_file', __FILE__)
31
- require File.expand_path('../gpx/bounds', __FILE__)
32
- require File.expand_path('../gpx/track', __FILE__)
33
- require File.expand_path('../gpx/route', __FILE__)
34
- require File.expand_path('../gpx/segment', __FILE__)
35
- require File.expand_path('../gpx/point', __FILE__)
36
- require File.expand_path('../gpx/trackpoint', __FILE__)
37
- require File.expand_path('../gpx/waypoint', __FILE__)
38
- require File.expand_path('../gpx/magellan_track_log', __FILE__)
6
+ require File.expand_path('gpx/version', __dir__)
7
+ require File.expand_path('gpx/gpx', __dir__)
8
+ require File.expand_path('gpx/gpx_file', __dir__)
9
+ require File.expand_path('gpx/bounds', __dir__)
10
+ require File.expand_path('gpx/track', __dir__)
11
+ require File.expand_path('gpx/route', __dir__)
12
+ require File.expand_path('gpx/segment', __dir__)
13
+ require File.expand_path('gpx/point', __dir__)
14
+ require File.expand_path('gpx/track_point', __dir__)
15
+ require File.expand_path('gpx/waypoint', __dir__)
16
+ require File.expand_path('gpx/magellan_track_log', __dir__)
17
+ require File.expand_path('gpx/geo_json', __dir__)
@@ -0,0 +1,68 @@
1
+ {
2
+ "type": "FeatureCollection",
3
+ "features": [{
4
+ "type": "Feature",
5
+ "geometry": {
6
+ "type": "LineString",
7
+ "coordinates": [
8
+ [-118.41511, 34.06298, 80],
9
+ [-118.41506, 34.06301, 80],
10
+ [-118.415, 34.06305, 80],
11
+ [-118.41494, 34.06309, 80]
12
+ ]
13
+ }
14
+ }, {
15
+ "type": "Feature",
16
+ "geometry": {
17
+ "type": "LineString",
18
+ "coordinates": [
19
+ [-118.3689, 34.05826, 40],
20
+ [-118.36894, 34.05818, 40],
21
+ [-118.369, 34.05806, 40]
22
+ ]
23
+ }
24
+ }, {
25
+ "type": "Feature",
26
+ "geometry": {
27
+ "type": "LineString",
28
+ "coordinates": [
29
+ [-118.35042, 34.03788, 30],
30
+ [-118.35046, 34.03779, 30]
31
+ ]
32
+ }
33
+ }, {
34
+ "type": "Feature",
35
+ "geometry": {
36
+ "type": "MultiLineString",
37
+ "coordinates": [
38
+ [
39
+ [-118.41511, 34.06298, 80],
40
+ [-118.41506, 34.06301, 80],
41
+ [-118.415, 34.06305, 80],
42
+ [-118.41494, 34.06309, 80]
43
+ ],
44
+ [
45
+ [-118.3689, 34.05826, 40],
46
+ [-118.36894, 34.05818, 40],
47
+ [-118.369, 34.05806, 40]
48
+ ]
49
+ ]
50
+ }
51
+ }, {
52
+ "type": "Feature",
53
+ "geometry": {
54
+ "type": "Point",
55
+ "coordinates": [-118.41585, 34.06253, 80]
56
+ }
57
+ }, {
58
+ "type": "Feature",
59
+ "geometry": {
60
+ "type": "MultiPoint",
61
+ "coordinates": [
62
+ [-118.41585, 34.06253, 80],
63
+ [-118.4158, 34.06256, 80],
64
+ [-118.41575, 34.06259, 80]
65
+ ]
66
+ }
67
+ }]
68
+ }
@@ -0,0 +1,83 @@
1
+ {
2
+ "type": "FeatureCollection",
3
+ "features": [{
4
+ "type": "Feature",
5
+ "geometry": {
6
+ "type": "LineString",
7
+ "coordinates": [
8
+ [-118.41585, 34.06253, 80],
9
+ [-118.4158, 34.06256, 80],
10
+ [-118.41575, 34.06259, 80],
11
+ [-118.4157, 34.06262, 80],
12
+ [-118.41566, 34.06265, 80],
13
+ [-118.41561, 34.06268, 80],
14
+ [-118.41556, 34.06271, 80],
15
+ [-118.41551, 34.06274, 80],
16
+ [-118.41546, 34.06277, 80],
17
+ [-118.41541, 34.0628, 80],
18
+ [-118.41536, 34.06283, 80],
19
+ [-118.41531, 34.06286, 80],
20
+ [-118.41526, 34.06289, 80],
21
+ [-118.41521, 34.06292, 80],
22
+ [-118.41516, 34.06295, 80],
23
+ [-118.41511, 34.06298, 80],
24
+ [-118.41506, 34.06301, 80],
25
+ [-118.415, 34.06305, 80],
26
+ [-118.41494, 34.06309, 80]
27
+ ]
28
+ }
29
+ }, {
30
+ "type": "Feature",
31
+ "geometry": {
32
+ "type": "LineString",
33
+ "coordinates": [
34
+ [-118.36855, 34.05844, 40],
35
+ [-118.36849, 34.05843, 40],
36
+ [-118.36843, 34.05842, 40],
37
+ [-118.36837, 34.05841, 40],
38
+ [-118.36906, 34.05878, 40],
39
+ [-118.36895, 34.05877, 40],
40
+ [-118.36884, 34.05876, 40],
41
+ [-118.36873, 34.05875, 40],
42
+ [-118.36866, 34.05874, 40],
43
+ [-118.3687, 34.05866, 40],
44
+ [-118.36874, 34.05858, 40],
45
+ [-118.36878, 34.0585, 40],
46
+ [-118.36882, 34.05842, 40],
47
+ [-118.36886, 34.05834, 40],
48
+ [-118.3689, 34.05826, 40],
49
+ [-118.36894, 34.05818, 40],
50
+ [-118.369, 34.05806, 40]
51
+ ]
52
+ }
53
+ }, {
54
+ "type": "Feature",
55
+ "geometry": {
56
+ "type": "LineString",
57
+ "coordinates": [
58
+ [-118.35043, 34.0392, 30],
59
+ [-118.35047, 34.03911, 30],
60
+ [-118.35051, 34.03902, 30],
61
+ [-118.35055, 34.03893, 30],
62
+ [-118.35057, 34.03887, 30],
63
+ [-118.35045, 34.03885, 30],
64
+ [-118.35033, 34.03883, 30],
65
+ [-118.35021, 34.03881, 30],
66
+ [-118.35009, 34.03879, 30],
67
+ [-118.35002, 34.03878, 30],
68
+ [-118.35006, 34.03869, 30],
69
+ [-118.3501, 34.0386, 30],
70
+ [-118.35014, 34.03851, 30],
71
+ [-118.35018, 34.03842, 30],
72
+ [-118.35022, 34.03833, 30],
73
+ [-118.35026, 34.03824, 30],
74
+ [-118.3503, 34.03815, 30],
75
+ [-118.35034, 34.03806, 30],
76
+ [-118.35038, 34.03797, 30],
77
+ [-118.35042, 34.03788, 30],
78
+ [-118.35046, 34.03779, 30],
79
+ [-118.3505, 34.03768, 30]
80
+ ]
81
+ }
82
+ }]
83
+ }
@@ -0,0 +1,74 @@
1
+ {
2
+ "type": "FeatureCollection",
3
+ "features": [{
4
+ "type": "Feature",
5
+ "geometry": {
6
+ "type": "MultiLineString",
7
+ "coordinates": [
8
+ [
9
+ [-118.41585, 34.06253, 80],
10
+ [-118.4158, 34.06256, 80],
11
+ [-118.41575, 34.06259, 80],
12
+ [-118.4157, 34.06262, 80],
13
+ [-118.41566, 34.06265, 80],
14
+ [-118.41561, 34.06268, 80],
15
+ [-118.41556, 34.06271, 80],
16
+ [-118.41551, 34.06274, 80],
17
+ [-118.41546, 34.06277, 80],
18
+ [-118.41541, 34.0628, 80],
19
+ [-118.41536, 34.06283, 80],
20
+ [-118.41531, 34.06286, 80],
21
+ [-118.41526, 34.06289, 80],
22
+ [-118.41521, 34.06292, 80],
23
+ [-118.41516, 34.06295, 80],
24
+ [-118.41511, 34.06298, 80],
25
+ [-118.41506, 34.06301, 80],
26
+ [-118.415, 34.06305, 80],
27
+ [-118.41494, 34.06309, 80]
28
+ ],
29
+ [
30
+ [-118.36855, 34.05844, 40],
31
+ [-118.36849, 34.05843, 40],
32
+ [-118.36843, 34.05842, 40],
33
+ [-118.36837, 34.05841, 40],
34
+ [-118.36906, 34.05878, 40],
35
+ [-118.36895, 34.05877, 40],
36
+ [-118.36884, 34.05876, 40],
37
+ [-118.36873, 34.05875, 40],
38
+ [-118.36866, 34.05874, 40],
39
+ [-118.3687, 34.05866, 40],
40
+ [-118.36874, 34.05858, 40],
41
+ [-118.36878, 34.0585, 40],
42
+ [-118.36882, 34.05842, 40],
43
+ [-118.36886, 34.05834, 40],
44
+ [-118.3689, 34.05826, 40],
45
+ [-118.36894, 34.05818, 40],
46
+ [-118.369, 34.05806, 40]
47
+ ],
48
+ [
49
+ [-118.35043, 34.0392, 30],
50
+ [-118.35047, 34.03911, 30],
51
+ [-118.35051, 34.03902, 30],
52
+ [-118.35055, 34.03893, 30],
53
+ [-118.35057, 34.03887, 30],
54
+ [-118.35045, 34.03885, 30],
55
+ [-118.35033, 34.03883, 30],
56
+ [-118.35021, 34.03881, 30],
57
+ [-118.35009, 34.03879, 30],
58
+ [-118.35002, 34.03878, 30],
59
+ [-118.35006, 34.03869, 30],
60
+ [-118.3501, 34.0386, 30],
61
+ [-118.35014, 34.03851, 30],
62
+ [-118.35018, 34.03842, 30],
63
+ [-118.35022, 34.03833, 30],
64
+ [-118.35026, 34.03824, 30],
65
+ [-118.3503, 34.03815, 30],
66
+ [-118.35034, 34.03806, 30],
67
+ [-118.35038, 34.03797, 30],
68
+ [-118.35042, 34.03788, 30],
69
+ [-118.35046, 34.03779, 30],
70
+ [-118.3505, 34.03768, 30]
71
+ ]]
72
+ }
73
+ }]
74
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "type": "FeatureCollection",
3
+ "features": [{
4
+ "type": "Feature",
5
+ "geometry": {
6
+ "type": "MultiPoint",
7
+ "coordinates": [
8
+ [-118.41585, 34.06253, 80],
9
+ [-118.4158, 34.06256, 80],
10
+ [-118.41575, 34.06259, 80]
11
+ ]
12
+ }
13
+ }]
14
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "type": "FeatureCollection",
3
+ "features": [{
4
+ "type": "Feature",
5
+ "geometry": {
6
+ "type": "Point",
7
+ "coordinates": [-118.41585, 34.06253, 80]
8
+ }
9
+ }, {
10
+ "type": "Feature",
11
+ "geometry": {
12
+ "type": "Point",
13
+ "coordinates": [-118.36855, 34.05844, 40]
14
+ }
15
+ }, {
16
+ "type": "Feature",
17
+ "geometry": {
18
+ "type": "Point",
19
+ "coordinates": [-118.35043, 34.0392, 30]
20
+ }
21
+ }]
22
+ }
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minitest/autorun'
4
+ require 'gpx'
5
+ require 'json'
6
+
7
+ class GeojsonTest < Minitest::Test
8
+ # Test passing a file name
9
+ def test_geojson_file_name_as_param
10
+ file_name = "#{File.dirname(__FILE__)}/geojson_files/line_string_data.json"
11
+ gpx_file = GPX::GeoJSON.convert_to_gpx(geojson_file: file_name)
12
+ assert_equal(1, gpx_file.tracks.size)
13
+ end
14
+
15
+ # Test passing a file
16
+ def test_geojson_file_as_param
17
+ file_name = "#{File.dirname(__FILE__)}/geojson_files/line_string_data.json"
18
+ file = File.new(file_name, 'r')
19
+ gpx_file = GPX::GeoJSON.convert_to_gpx(geojson_file: file)
20
+ assert_equal(1, gpx_file.tracks.size)
21
+ end
22
+
23
+ def test_raises_arg_error_when_no_params
24
+ assert_raises(ArgumentError) do
25
+ GPX::GeoJSON.convert_to_gpx
26
+ end
27
+ end
28
+
29
+ # Test that lat/lon allocated correctly
30
+ def test_point_to_waypoint
31
+ pt = [-118, 34]
32
+ waypoint = GPX::GeoJSON.send(:point_to_waypoint, pt, nil)
33
+ assert_equal(34, waypoint.lat)
34
+ assert_equal(-118, waypoint.lon)
35
+ end
36
+
37
+ # Test that lat/lon allocated correctly
38
+ def test_point_to_trackpoint
39
+ pt = [-118, 34]
40
+ waypoint = GPX::GeoJSON.send(:point_to_track_point, pt, nil)
41
+ assert_equal(34, waypoint.lat)
42
+ assert_equal(-118, waypoint.lon)
43
+ end
44
+
45
+ def test_line_string_functionality
46
+ file = File.join(File.dirname(__FILE__), 'geojson_files/line_string_data.json')
47
+ gpx_file = GPX::GeoJSON.convert_to_gpx(geojson_file: file)
48
+
49
+ assert_equal(1, gpx_file.tracks.size)
50
+ assert_equal(3, gpx_file.tracks.first.segments.size)
51
+ pts_size = gpx_file.tracks.first.segments[0].points.size +
52
+ gpx_file.tracks.first.segments[1].points.size +
53
+ gpx_file.tracks.first.segments[2].points.size
54
+ assert_equal(58, pts_size)
55
+ end
56
+
57
+ def test_multi_line_string_functionality
58
+ file = File.join(File.dirname(__FILE__), 'geojson_files/multi_line_string_data.json')
59
+ gpx_file = GPX::GeoJSON.convert_to_gpx(geojson_file: file)
60
+ assert_equal(1, gpx_file.tracks.size)
61
+ assert_equal(3, gpx_file.tracks.first.segments.size)
62
+ pts_size = gpx_file.tracks.first.segments[0].points.size +
63
+ gpx_file.tracks.first.segments[1].points.size +
64
+ gpx_file.tracks.first.segments[2].points.size
65
+ assert_equal(58, pts_size)
66
+ end
67
+
68
+ def test_point_functionality
69
+ file = File.join(File.dirname(__FILE__), 'geojson_files/point_data.json')
70
+ gpx_file = GPX::GeoJSON.convert_to_gpx(geojson_file: file)
71
+ assert_equal(3, gpx_file.waypoints.size)
72
+ end
73
+
74
+ def test_multi_point_functionality
75
+ file = File.join(File.dirname(__FILE__), 'geojson_files/multi_point_data.json')
76
+ gpx_file = GPX::GeoJSON.convert_to_gpx(geojson_file: file)
77
+ assert_equal(3, gpx_file.waypoints.size)
78
+ end
79
+
80
+ def test_combined_functionality
81
+ file = File.join(File.dirname(__FILE__), 'geojson_files/combined_data.json')
82
+ gpx_file = GPX::GeoJSON.convert_to_gpx(geojson_file: file)
83
+
84
+ # 1 for all LineStrings, 1 for MultiLineString
85
+ assert_equal(2, gpx_file.tracks.size)
86
+ assert_equal(3, gpx_file.tracks.first.segments.size)
87
+ assert_equal(2, gpx_file.tracks.last.segments.size)
88
+ pt_sum = gpx_file.tracks.inject(0) { |sum, trk| sum + trk.points.size }
89
+ assert_equal(16, pt_sum)
90
+ assert_equal(4, gpx_file.waypoints.size)
91
+ end
92
+ end
data/tests/gpx10_test.rb CHANGED
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'gpx'
3
5
 
4
6
  class GPX10Test < Minitest::Test
5
- GPX_FILE = File.join(File.dirname(__FILE__), "gpx_files/gpx10.gpx")
6
-
7
- def test_read
8
- # make sure we can read a GPX 1.0 file
9
- @gpx_file = GPX::GPXFile.new(:gpx_file => GPX_FILE)
10
- end
7
+ GPX_FILE = File.join(File.dirname(__FILE__), 'gpx_files/gpx10.gpx')
11
8
 
9
+ def test_read
10
+ # make sure we can read a GPX 1.0 file
11
+ @gpx_file = GPX::GPXFile.new(gpx_file: GPX_FILE)
12
+ end
12
13
  end
@@ -1,19 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'gpx'
3
5
 
4
6
  class GPXFileTest < Minitest::Test
5
-
6
- ONE_TRACK_FILE = File.join(File.dirname(__FILE__), "gpx_files/one_track.gpx")
7
- WITH_OR_WITHOUT_ELEV_FILE = File.join(File.dirname(__FILE__), "gpx_files/with_or_without_elev.gpx")
8
- BIG_FILE = File.join(File.dirname(__FILE__), "gpx_files/big.gpx")
7
+ ONE_TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/one_track.gpx')
8
+ WITH_OR_WITHOUT_ELEV_FILE = File.join(File.dirname(__FILE__), 'gpx_files/with_or_without_elev.gpx')
9
+ WITH_EMPTY_TRACKS = File.join(File.dirname(__FILE__), 'gpx_files/with_empty_tracks.gpx')
10
+ BIG_FILE = File.join(File.dirname(__FILE__), 'gpx_files/big.gpx')
9
11
 
10
12
  def test_load_data_from_string
11
- gpx_file = GPX::GPXFile.new(:gpx_data => open(ONE_TRACK_FILE).read)
13
+ gpx_file = GPX::GPXFile.new(gpx_data: File.open(ONE_TRACK_FILE).read)
12
14
  assert_equal(1, gpx_file.tracks.size)
13
15
  assert_equal(8, gpx_file.tracks.first.segments.size)
14
- assert_equal("ACTIVE LOG", gpx_file.tracks.first.name)
15
- assert_equal("active_log.gpx", gpx_file.name)
16
- assert_equal("2006-04-08T16:44:28Z", gpx_file.time.xmlschema)
16
+ assert_equal('ACTIVE LOG', gpx_file.tracks.first.name)
17
+ assert_equal('active_log.gpx', gpx_file.name)
18
+ assert_equal('2006-04-08T16:44:28Z', gpx_file.time.xmlschema)
17
19
  assert_equal(38.681488, gpx_file.bounds.min_lat)
18
20
  assert_equal(-109.606948, gpx_file.bounds.min_lon)
19
21
  assert_equal(38.791759, gpx_file.bounds.max_lat)
@@ -21,45 +23,55 @@ class GPXFileTest < Minitest::Test
21
23
  assert_equal('description of my GPX file with special char like &, <, >', gpx_file.description)
22
24
  assert_equal('description of my GPX file with special char like &, <, >', gpx_file.description)
23
25
  assert_equal(3.0724966849262554, gpx_file.distance)
24
- assert_equal(15237.0, gpx_file.duration)
26
+ assert_equal(15_237.0, gpx_file.duration)
25
27
  assert_equal(3036.0, gpx_file.moving_duration)
26
28
  assert_equal(3.6432767014935834, gpx_file.average_speed)
27
29
  end
28
30
 
29
31
  def test_load_data_from_file
30
- gpx_file = GPX::GPXFile.new(:gpx_file => ONE_TRACK_FILE)
32
+ gpx_file = GPX::GPXFile.new(gpx_file: ONE_TRACK_FILE)
31
33
  assert_equal(1, gpx_file.tracks.size)
32
34
  assert_equal(8, gpx_file.tracks.first.segments.size)
33
- assert_equal("ACTIVE LOG", gpx_file.tracks.first.name)
34
- assert_equal("active_log.gpx", gpx_file.name)
35
- assert_equal("2006-04-08T16:44:28Z", gpx_file.time.xmlschema)
35
+ assert_equal('ACTIVE LOG', gpx_file.tracks.first.name)
36
+ assert_equal('active_log.gpx', gpx_file.name)
37
+ assert_equal('2006-04-08T16:44:28Z', gpx_file.time.xmlschema)
36
38
  assert_equal(38.681488, gpx_file.bounds.min_lat)
37
39
  assert_equal(-109.606948, gpx_file.bounds.min_lon)
38
40
  assert_equal(38.791759, gpx_file.bounds.max_lat)
39
41
  assert_equal(-109.447045, gpx_file.bounds.max_lon)
40
42
  assert_equal('description of my GPX file with special char like &, <, >', gpx_file.description)
41
43
  assert_equal(3.0724966849262554, gpx_file.distance)
42
- assert_equal(15237.0, gpx_file.duration)
44
+ assert_equal(15_237.0, gpx_file.duration)
43
45
  assert_equal(3036.0, gpx_file.moving_duration)
44
46
  assert_equal(3.6432767014935834, gpx_file.average_speed)
45
47
  end
46
48
 
47
49
  def test_big_file
48
- gpx_file = GPX::GPXFile.new(:gpx_file => BIG_FILE)
50
+ gpx_file = GPX::GPXFile.new(gpx_file: BIG_FILE)
49
51
  assert_equal(1, gpx_file.tracks.size)
50
52
  assert_equal(7968, gpx_file.tracks.first.points.size)
51
- assert_equal(105508.0, gpx_file.duration)
52
- assert_equal(57645.0, gpx_file.moving_duration)
53
+ assert_equal(105_508.0, gpx_file.duration)
54
+ assert_equal(57_645.0, gpx_file.moving_duration)
53
55
  assert_in_delta(99.60738958686505, gpx_file.average_speed, 1e-13)
54
56
  end
55
57
 
56
58
  def test_with_or_with_elev
57
- gpx_file = GPX::GPXFile.new(:gpx_file => WITH_OR_WITHOUT_ELEV_FILE)
59
+ gpx_file = GPX::GPXFile.new(gpx_file: WITH_OR_WITHOUT_ELEV_FILE)
58
60
  assert_equal(2, gpx_file.tracks.size)
59
61
  assert_equal(0, gpx_file.duration)
60
62
  assert_equal(0, gpx_file.moving_duration)
61
63
  assert(gpx_file.average_speed.nan?)
62
- #assert_equal(7968, gpx_file.tracks.first.points.size)
64
+ # assert_equal(7968, gpx_file.tracks.first.points.size)
63
65
  end
64
66
 
67
+ def test_with_empty_tracks
68
+ gpx_file = GPX::GPXFile.new(gpx_file: WITH_EMPTY_TRACKS)
69
+ # is read correctly
70
+ assert_equal(1, gpx_file.tracks.size)
71
+ # and ignores empty segments
72
+ assert_equal(1, gpx_file.tracks.first.segments.size)
73
+ assert_equal(21.0, gpx_file.duration)
74
+ assert_equal(21.0, gpx_file.moving_duration)
75
+ assert_equal(6.674040636626879, gpx_file.average_speed)
76
+ end
65
77
  end