gpx 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,114 +3,111 @@ require 'fileutils'
3
3
  require 'gpx'
4
4
 
5
5
  class OutputTest < Minitest::Test
6
-
7
6
  include GPX
8
7
 
9
8
  def setup
10
- FileUtils.mkdir_p(File.join(File.dirname(__FILE__), "output"))
9
+ FileUtils.mkdir_p(File.join(File.dirname(__FILE__), 'output'))
11
10
  end
12
11
 
13
12
  def test_new_gpx_file_from_scratch
14
- gpx_file = GPXFile.new
15
-
16
- track = Track.new(:name => "My First Track")
17
- segment = Segment.new
18
-
19
- track_point_data = [
20
- {:lat => 40.036926, :lon =>-105.253487, :time => Time.parse('2005-12-31T22:01:24Z'), :elevation => 1737.24},
21
- {:lat => 40.036604, :lon =>-105.253487, :time => Time.parse("2005-12-31T22:02:01Z"), :elevation => 1738.682},
22
- {:lat => 40.036347, :lon =>-105.253830, :time => Time.parse("2005-12-31T22:02:08Z"), :elevation => 1738.682},
23
- {:lat => 40.035574, :lon =>-105.254045, :time => Time.parse("2005-12-31T22:02:20Z"), :elevation => 1737.24},
24
- {:lat => 40.035467, :lon =>-105.254366, :time => Time.parse("2005-12-31T22:02:29Z"), :elevation => 1735.798},
25
- {:lat => 40.035317, :lon =>-105.254388, :time => Time.parse("2005-12-31T22:02:33Z"), :elevation => 1735.798},
26
- {:lat => 40.035274, :lon =>-105.254431, :time => Time.parse("2005-12-31T22:02:49Z"), :elevation => 1736.278},
27
- {:lat => 40.035274, :lon =>-105.254431, :time => Time.parse("2005-12-31T22:02:54Z"), :elevation => 1739.643},
28
- {:lat => 40.035317, :lon =>-105.254431, :time => Time.parse("2005-12-31T22:05:08Z"), :elevation => 1732.433},
29
- {:lat => 40.035317, :lon =>-105.254431, :time => Time.parse("2005-12-31T22:05:09Z"), :elevation => 1726.665}]
30
-
31
- track_point_data.each do |trk_pt_hash|
32
- segment.points << TrackPoint.new(trk_pt_hash)
33
- end
34
-
35
- track.segments << segment
36
- gpx_file.tracks << track
37
-
38
- waypoint_data = [
39
- {:lat => 39.997298, :lon => -105.292674, :name => 'GRG-CA', :sym => 'Waypoint', :ele => '1766.535'},
40
- {:lat => 33.330190, :lon => -111.946110, :name => 'GRMPHX', :sym => 'Waypoint', :ele => '361.0981',
41
- :cmt => "Hey here's a comment.", :desc => "Somewhere in my backyard.", :fix => '3d', :sat => "8", :hdop => "50.5", :vdop => "6.8", :pdop => "7.6"},
42
- {:lat => 25.061783, :lon => 121.640267, :name => 'GRMTWN', :sym => 'Waypoint', :ele => '38.09766'},
43
- {:lat => 39.999840, :lon => -105.214696, :name => 'SBDR', :sym => 'Waypoint', :ele => '1612.965'},
44
- {:lat => 39.989739, :lon => -105.295285, :name => 'TO', :sym => 'Waypoint', :ele => '2163.556'},
45
- {:lat => 40.035301, :lon => -105.254443, :name => 'VICS', :sym => 'Waypoint', :ele => '1535.34'},
46
- {:lat => 40.035301, :lon => -105.254443, :name => 'TIMEDWPT', :sym => 'Waypoint', :ele => '1535.34', :time => Time.parse("2005-12-31T22:05:09Z")}
47
- ]
48
-
49
- waypoint_data.each do |wpt_hash|
50
- gpx_file.waypoints << Waypoint.new(wpt_hash)
51
- end
52
-
53
- route_point_data = [
54
- {:lat => 40.035467, :lon =>-105.254366, :time => Time.parse("2005-12-31T22:02:29Z"), :elevation => 1735.798},
55
- {:lat => 40.035317, :lon =>-105.254388, :time => Time.parse("2005-12-31T22:02:33Z"), :elevation => 1735.798},
56
- {:lat => 40.035274, :lon =>-105.254431, :time => Time.parse("2005-12-31T22:02:49Z"), :elevation => 1736.278} ]
57
-
58
- route = Route.new()
59
- route_point_data.each do |rte_pt_hash|
60
- route.points << Point.new(rte_pt_hash)
61
- end
62
-
63
- gpx_file.routes << route
64
-
65
- gpx_file.write(output_file(name_of_test))
66
-
67
-
68
- written_gpx_file = GPXFile.new(:gpx_file => output_file(name_of_test))
69
-
70
- assert_equal(File.basename(output_file(name_of_test)), written_gpx_file.name)
71
- assert_equal(1, written_gpx_file.tracks.size)
72
- assert_equal(1, written_gpx_file.tracks[0].segments.size)
73
- assert_equal(track_point_data.size, written_gpx_file.tracks[0].segments[0].points.size)
74
- assert_equal(track_point_data.size, written_gpx_file.tracks[0].points.size)
75
-
76
- # Make sure each point in the segment has the attributes it was initialized with
77
- written_segment = written_gpx_file.tracks[0].segments[0]
78
- track_point_data.each_with_index do |trk_pt_hash, index|
79
- trk_pt_hash.each do |key, value|
80
- assert_equal(value, written_segment.points[index].send(key))
81
- end
82
- end
83
-
84
-
85
-
86
- # Make sure the one route has the attributes we initialized it with
87
- assert_equal(1, written_gpx_file.routes.size)
88
- written_route = written_gpx_file.routes[0]
89
- assert_equal(route_point_data.size, written_route.points.size)
90
- route_point_data.each_with_index do |rte_pt_hash, index|
91
- rte_pt_hash.each do |key, value|
92
- assert_equal(value, written_route.points[index].send(key))
93
- end
94
- end
95
-
96
- # Make sure the waypoints have all of the attributes we initialized them with
97
- written_waypoints = written_gpx_file.waypoints
98
- assert_equal(waypoint_data.size, written_waypoints.size)
99
- waypoint_data.each_with_index do |wpt_hash, index|
100
- wpt_hash.each do |key, value|
101
- assert_equal(value, written_waypoints[index].send(key.to_s), key)
102
- end
103
- end
13
+ gpx_file = GPXFile.new
14
+
15
+ track = Track.new(name: 'My First Track')
16
+ segment = Segment.new
17
+
18
+ track_point_data = [
19
+ { lat: 40.036926, lon: -105.253487, time: Time.parse('2005-12-31T22:01:24Z'), elevation: 1737.24 },
20
+ { lat: 40.036604, lon: -105.253487, time: Time.parse('2005-12-31T22:02:01Z'), elevation: 1738.682 },
21
+ { lat: 40.036347, lon: -105.253830, time: Time.parse('2005-12-31T22:02:08Z'), elevation: 1738.682 },
22
+ { lat: 40.035574, lon: -105.254045, time: Time.parse('2005-12-31T22:02:20Z'), elevation: 1737.24 },
23
+ { lat: 40.035467, lon: -105.254366, time: Time.parse('2005-12-31T22:02:29Z'), elevation: 1735.798 },
24
+ { lat: 40.035317, lon: -105.254388, time: Time.parse('2005-12-31T22:02:33Z'), elevation: 1735.798 },
25
+ { lat: 40.035274, lon: -105.254431, time: Time.parse('2005-12-31T22:02:49Z'), elevation: 1736.278 },
26
+ { lat: 40.035274, lon: -105.254431, time: Time.parse('2005-12-31T22:02:54Z'), elevation: 1739.643 },
27
+ { lat: 40.035317, lon: -105.254431, time: Time.parse('2005-12-31T22:05:08Z'), elevation: 1732.433 },
28
+ { lat: 40.035317, lon: -105.254431, time: Time.parse('2005-12-31T22:05:09Z'), elevation: 1726.665 }
29
+ ]
30
+
31
+ track_point_data.each do |trk_pt_hash|
32
+ segment.points << TrackPoint.new(trk_pt_hash)
33
+ end
34
+
35
+ track.segments << segment
36
+ gpx_file.tracks << track
37
+
38
+ waypoint_data = [
39
+ { lat: 39.997298, lon: -105.292674, name: 'GRG-CA', sym: 'Waypoint', ele: '1766.535' },
40
+ { lat: 33.330190, lon: -111.946110, name: 'GRMPHX', sym: 'Waypoint', ele: '361.0981',
41
+ cmt: "Hey here's a comment.", desc: 'Somewhere in my backyard.', fix: '3d', sat: '8', hdop: '50.5', vdop: '6.8', pdop: '7.6' },
42
+ { lat: 25.061783, lon: 121.640267, name: 'GRMTWN', sym: 'Waypoint', ele: '38.09766' },
43
+ { lat: 39.999840, lon: -105.214696, name: 'SBDR', sym: 'Waypoint', ele: '1612.965' },
44
+ { lat: 39.989739, lon: -105.295285, name: 'TO', sym: 'Waypoint', ele: '2163.556' },
45
+ { lat: 40.035301, lon: -105.254443, name: 'VICS', sym: 'Waypoint', ele: '1535.34' },
46
+ { lat: 40.035301, lon: -105.254443, name: 'TIMEDWPT', sym: 'Waypoint', ele: '1535.34', time: Time.parse('2005-12-31T22:05:09Z') }
47
+ ]
48
+
49
+ waypoint_data.each do |wpt_hash|
50
+ gpx_file.waypoints << Waypoint.new(wpt_hash)
51
+ end
52
+
53
+ route_point_data = [
54
+ { lat: 40.035467, lon: -105.254366, time: Time.parse('2005-12-31T22:02:29Z'), elevation: 1735.798 },
55
+ { lat: 40.035317, lon: -105.254388, time: Time.parse('2005-12-31T22:02:33Z'), elevation: 1735.798 },
56
+ { lat: 40.035274, lon: -105.254431, time: Time.parse('2005-12-31T22:02:49Z'), elevation: 1736.278 }
57
+ ]
58
+
59
+ route = Route.new
60
+ route_point_data.each do |rte_pt_hash|
61
+ route.points << Point.new(rte_pt_hash)
62
+ end
63
+
64
+ gpx_file.routes << route
65
+
66
+ gpx_file.write(output_file(name_of_test))
67
+
68
+ written_gpx_file = GPXFile.new(gpx_file: output_file(name_of_test))
69
+
70
+ assert_equal(File.basename(output_file(name_of_test)), written_gpx_file.name)
71
+ assert_equal(1, written_gpx_file.tracks.size)
72
+ assert_equal(1, written_gpx_file.tracks[0].segments.size)
73
+ assert_equal(track_point_data.size, written_gpx_file.tracks[0].segments[0].points.size)
74
+ assert_equal(track_point_data.size, written_gpx_file.tracks[0].points.size)
75
+
76
+ # Make sure each point in the segment has the attributes it was initialized with
77
+ written_segment = written_gpx_file.tracks[0].segments[0]
78
+ track_point_data.each_with_index do |trk_pt_hash, index|
79
+ trk_pt_hash.each do |key, value|
80
+ assert_equal(value, written_segment.points[index].send(key))
81
+ end
82
+ end
83
+
84
+ # Make sure the one route has the attributes we initialized it with
85
+ assert_equal(1, written_gpx_file.routes.size)
86
+ written_route = written_gpx_file.routes[0]
87
+ assert_equal(route_point_data.size, written_route.points.size)
88
+ route_point_data.each_with_index do |rte_pt_hash, index|
89
+ rte_pt_hash.each do |key, value|
90
+ assert_equal(value, written_route.points[index].send(key))
91
+ end
92
+ end
93
+
94
+ # Make sure the waypoints have all of the attributes we initialized them with
95
+ written_waypoints = written_gpx_file.waypoints
96
+ assert_equal(waypoint_data.size, written_waypoints.size)
97
+ waypoint_data.each_with_index do |wpt_hash, index|
98
+ wpt_hash.each do |key, value|
99
+ assert_equal(value, written_waypoints[index].send(key.to_s), key)
100
+ end
101
+ end
104
102
  end
105
103
 
106
104
  def name_of_test
107
- caller[0] =~ /`test_([^']*)'/ and $1
105
+ caller[0] =~ /`test_([^']*)'/ && Regexp.last_match(1)
108
106
  end
109
107
 
110
108
  def output_file(test_name)
111
109
  File.join(File.dirname(__FILE__), "output/#{test_name}.gpx")
112
110
  end
113
111
 
114
- THE_WORKS = "<?xml version=\"1.0\"?>\n<gpx xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/1\" version=\"1.1\" creator=\"GPX RubyGem #{GPX::VERSION} Copyright 2006-2009 Doug Fales -- http://gpx.rubyforge.org/\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n <metadata>\n <name>new_gpx_file_from_scratch.gpx</name>\n <time>%s</time>\n <bounds minlat=\"90.0\" minlon=\"180.0\" maxlat=\"-90.0\" maxlon=\"-180.0\"/>\n </metadata>\n <trk>\n <name/>\n <trkseg>\n <trkpt lat=\"40.036926\" lon=\"-105.253487\">\n <time>2005-12-31T22:01:24Z</time>\n <ele>1737.24</ele>\n </trkpt>\n <trkpt lat=\"40.036604\" lon=\"-105.253487\">\n <time>2005-12-31T22:02:01Z</time>\n <ele>1738.682</ele>\n </trkpt>\n <trkpt lat=\"40.036347\" lon=\"-105.25383\">\n <time>2005-12-31T22:02:08Z</time>\n <ele>1738.682</ele>\n </trkpt>\n <trkpt lat=\"40.035574\" lon=\"-105.254045\">\n <time>2005-12-31T22:02:20Z</time>\n <ele>1737.24</ele>\n </trkpt>\n <trkpt lat=\"40.035467\" lon=\"-105.254366\">\n <time>2005-12-31T22:02:29Z</time>\n <ele>1735.798</ele>\n </trkpt>\n <trkpt lat=\"40.035317\" lon=\"-105.254388\">\n <time>2005-12-31T22:02:33Z</time>\n <ele>1735.798</ele>\n </trkpt>\n <trkpt lat=\"40.035274\" lon=\"-105.254431\">\n <time>2005-12-31T22:02:49Z</time>\n <ele>1736.278</ele>\n </trkpt>\n <trkpt lat=\"40.035274\" lon=\"-105.254431\">\n <time>2005-12-31T22:02:54Z</time>\n <ele>1739.643</ele>\n </trkpt>\n <trkpt lat=\"40.035317\" lon=\"-105.254431\">\n <time>2005-12-31T22:05:08Z</time>\n <ele>1732.433</ele>\n </trkpt>\n <trkpt lat=\"40.035317\" lon=\"-105.254431\">\n <time>2005-12-31T22:05:09Z</time>\n <ele>1726.665</ele>\n </trkpt>\n </trkseg>\n </trk>\n <wpt lat=\"39.997298\" lon=\"-105.292674\">\n <name>GRG-CA</name>\n <sym>Waypoint</sym>\n <ele>1766.535</ele>\n </wpt>\n <wpt lat=\"33.33019\" lon=\"-111.94611\">\n <name>GRMPHX</name>\n <cmt>Hey here's a comment.</cmt>\n <desc>Somewhere in my backyard.</desc>\n <sym>Waypoint</sym>\n <fix>3d</fix>\n <sat>8</sat>\n <hdop>50.5</hdop>\n <vdop>6.8</vdop>\n <pdop>7.6</pdop>\n <ele>361.0981</ele>\n </wpt>\n <wpt lat=\"25.061783\" lon=\"121.640267\">\n <name>GRMTWN</name>\n <sym>Waypoint</sym>\n <ele>38.09766</ele>\n </wpt>\n <wpt lat=\"39.99984\" lon=\"-105.214696\">\n <name>SBDR</name>\n <sym>Waypoint</sym>\n <ele>1612.965</ele>\n </wpt>\n <wpt lat=\"39.989739\" lon=\"-105.295285\">\n <name>TO</name>\n <sym>Waypoint</sym>\n <ele>2163.556</ele>\n </wpt>\n <wpt lat=\"40.035301\" lon=\"-105.254443\">\n <name>VICS</name>\n <sym>Waypoint</sym>\n <ele>1535.34</ele>\n </wpt>\n <rte>\n <name/>\n <rtept lat=\"40.035467\" lon=\"-105.254366\">\n <time>2005-12-31T22:02:29Z</time>\n <ele>1735.798</ele>\n </rtept>\n <rtept lat=\"40.035317\" lon=\"-105.254388\">\n <time>2005-12-31T22:02:33Z</time>\n <ele>1735.798</ele>\n </rtept>\n <rtept lat=\"40.035274\" lon=\"-105.254431\">\n <time>2005-12-31T22:02:49Z</time>\n <ele>1736.278</ele>\n </rtept>\n </rte>\n</gpx>\n"
115
-
112
+ THE_WORKS = "<?xml version=\"1.0\"?>\n<gpx xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/1\" version=\"1.1\" creator=\"GPX RubyGem #{GPX::VERSION} Copyright 2006-2009 Doug Fales -- http://gpx.rubyforge.org/\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n <metadata>\n <name>new_gpx_file_from_scratch.gpx</name>\n <time>%s</time>\n <bounds minlat=\"90.0\" minlon=\"180.0\" maxlat=\"-90.0\" maxlon=\"-180.0\"/>\n </metadata>\n <trk>\n <name/>\n <trkseg>\n <trkpt lat=\"40.036926\" lon=\"-105.253487\">\n <time>2005-12-31T22:01:24Z</time>\n <ele>1737.24</ele>\n </trkpt>\n <trkpt lat=\"40.036604\" lon=\"-105.253487\">\n <time>2005-12-31T22:02:01Z</time>\n <ele>1738.682</ele>\n </trkpt>\n <trkpt lat=\"40.036347\" lon=\"-105.25383\">\n <time>2005-12-31T22:02:08Z</time>\n <ele>1738.682</ele>\n </trkpt>\n <trkpt lat=\"40.035574\" lon=\"-105.254045\">\n <time>2005-12-31T22:02:20Z</time>\n <ele>1737.24</ele>\n </trkpt>\n <trkpt lat=\"40.035467\" lon=\"-105.254366\">\n <time>2005-12-31T22:02:29Z</time>\n <ele>1735.798</ele>\n </trkpt>\n <trkpt lat=\"40.035317\" lon=\"-105.254388\">\n <time>2005-12-31T22:02:33Z</time>\n <ele>1735.798</ele>\n </trkpt>\n <trkpt lat=\"40.035274\" lon=\"-105.254431\">\n <time>2005-12-31T22:02:49Z</time>\n <ele>1736.278</ele>\n </trkpt>\n <trkpt lat=\"40.035274\" lon=\"-105.254431\">\n <time>2005-12-31T22:02:54Z</time>\n <ele>1739.643</ele>\n </trkpt>\n <trkpt lat=\"40.035317\" lon=\"-105.254431\">\n <time>2005-12-31T22:05:08Z</time>\n <ele>1732.433</ele>\n </trkpt>\n <trkpt lat=\"40.035317\" lon=\"-105.254431\">\n <time>2005-12-31T22:05:09Z</time>\n <ele>1726.665</ele>\n </trkpt>\n </trkseg>\n </trk>\n <wpt lat=\"39.997298\" lon=\"-105.292674\">\n <name>GRG-CA</name>\n <sym>Waypoint</sym>\n <ele>1766.535</ele>\n </wpt>\n <wpt lat=\"33.33019\" lon=\"-111.94611\">\n <name>GRMPHX</name>\n <cmt>Hey here's a comment.</cmt>\n <desc>Somewhere in my backyard.</desc>\n <sym>Waypoint</sym>\n <fix>3d</fix>\n <sat>8</sat>\n <hdop>50.5</hdop>\n <vdop>6.8</vdop>\n <pdop>7.6</pdop>\n <ele>361.0981</ele>\n </wpt>\n <wpt lat=\"25.061783\" lon=\"121.640267\">\n <name>GRMTWN</name>\n <sym>Waypoint</sym>\n <ele>38.09766</ele>\n </wpt>\n <wpt lat=\"39.99984\" lon=\"-105.214696\">\n <name>SBDR</name>\n <sym>Waypoint</sym>\n <ele>1612.965</ele>\n </wpt>\n <wpt lat=\"39.989739\" lon=\"-105.295285\">\n <name>TO</name>\n <sym>Waypoint</sym>\n <ele>2163.556</ele>\n </wpt>\n <wpt lat=\"40.035301\" lon=\"-105.254443\">\n <name>VICS</name>\n <sym>Waypoint</sym>\n <ele>1535.34</ele>\n </wpt>\n <rte>\n <name/>\n <rtept lat=\"40.035467\" lon=\"-105.254366\">\n <time>2005-12-31T22:02:29Z</time>\n <ele>1735.798</ele>\n </rtept>\n <rtept lat=\"40.035317\" lon=\"-105.254388\">\n <time>2005-12-31T22:02:33Z</time>\n <ele>1735.798</ele>\n </rtept>\n <rtept lat=\"40.035274\" lon=\"-105.254431\">\n <time>2005-12-31T22:02:49Z</time>\n <ele>1736.278</ele>\n </rtept>\n </rte>\n</gpx>\n".freeze
116
113
  end
@@ -2,62 +2,55 @@ require 'minitest/autorun'
2
2
  require 'gpx'
3
3
 
4
4
  class RouteTest < Minitest::Test
5
-
6
5
  def test_read_routes
7
- gpx = GPX::GPXFile.new(:gpx_file => File.join(File.dirname(__FILE__), "gpx_files/routes.gpx"))
6
+ gpx = GPX::GPXFile.new(gpx_file: File.join(File.dirname(__FILE__), 'gpx_files/routes.gpx'))
8
7
  assert_equal(2, gpx.routes.size)
9
8
  first_route = gpx.routes.first
10
9
  assert_equal(3, first_route.points.size)
11
10
  assert_equal('GRG-CA-TO', first_route.name)
12
11
 
13
-
14
- # Route 1, First Point
15
- # <rtept lat="39.997298" lon="-105.292674">
16
- # <name><![CDATA[GRG-CA]]></name>
17
- # <sym>Waypoint</sym>
18
- # <ele>1766.535</ele>
19
- # </rtept>
12
+ # Route 1, First Point
13
+ # <rtept lat="39.997298" lon="-105.292674">
14
+ # <name><![CDATA[GRG-CA]]></name>
15
+ # <sym>Waypoint</sym>
16
+ # <ele>1766.535</ele>
17
+ # </rtept>
20
18
  assert_equal(39.997298, first_route.points[0].lat)
21
19
  assert_equal(-105.292674, first_route.points[0].lon)
22
20
  assert_equal(1766.535, first_route.points[0].elevation)
23
21
 
24
-
25
- # Route 1, Second Point
26
- # <rtept lat="39.995700" lon="-105.292805">
27
- # <name><![CDATA[AMPTHT]]></name>
28
- # <sym>Waypoint</sym>
29
- # <ele>1854.735</ele>
30
- # </rtept>
22
+ # Route 1, Second Point
23
+ # <rtept lat="39.995700" lon="-105.292805">
24
+ # <name><![CDATA[AMPTHT]]></name>
25
+ # <sym>Waypoint</sym>
26
+ # <ele>1854.735</ele>
27
+ # </rtept>
31
28
  assert_equal(39.995700, first_route.points[1].lat)
32
29
  assert_equal(-105.292805, first_route.points[1].lon)
33
30
  assert_equal(1854.735, first_route.points[1].elevation)
34
31
 
35
- # Route 1, Third Point
36
- # <rtept lat="39.989739" lon="-105.295285">
37
- # <name><![CDATA[TO]]></name>
38
- # <sym>Waypoint</sym>
39
- # <ele>2163.556</ele>
40
- # </rtept>
32
+ # Route 1, Third Point
33
+ # <rtept lat="39.989739" lon="-105.295285">
34
+ # <name><![CDATA[TO]]></name>
35
+ # <sym>Waypoint</sym>
36
+ # <ele>2163.556</ele>
37
+ # </rtept>
41
38
  assert_equal(39.989739, first_route.points[2].lat)
42
39
  assert_equal(-105.295285, first_route.points[2].lon)
43
40
  assert_equal(2163.556, first_route.points[2].elevation)
44
41
 
45
-
46
42
  second_route = gpx.routes[1]
47
43
  assert_equal(1, second_route.points.size)
48
44
  assert_equal('SBDR-SBDR', second_route.name)
49
45
 
50
- # Route 2, Only Point
51
- # <rtept lat="39.999840" lon="-105.214696">
52
- # <name><![CDATA[SBDR]]></name>
53
- # <sym>Waypoint</sym>
54
- # <ele>1612.965</ele>
55
- # </rtept>
46
+ # Route 2, Only Point
47
+ # <rtept lat="39.999840" lon="-105.214696">
48
+ # <name><![CDATA[SBDR]]></name>
49
+ # <sym>Waypoint</sym>
50
+ # <ele>1612.965</ele>
51
+ # </rtept>
56
52
  assert_equal(39.999840, second_route.points[0].lat)
57
53
  assert_equal(-105.214696, second_route.points[0].lon)
58
54
  assert_equal(1612.965, second_route.points[0].elevation)
59
-
60
55
  end
61
-
62
-
63
56
  end
@@ -1,109 +1,108 @@
1
- #require 'minitest/autorun'
1
+ # require 'minitest/autorun'
2
2
  require 'minitest/autorun'
3
3
  require 'yaml'
4
4
  require 'gpx'
5
5
 
6
6
  class SegmentTest < Minitest::Test
7
- ONE_SEGMENT = File.join(File.dirname(__FILE__), "gpx_files/one_segment.gpx")
8
- ONE_SEGMENT_NO_TIME = File.join(File.dirname(__FILE__), "gpx_files/one_segment_no_time.gpx")
7
+ ONE_SEGMENT = File.join(File.dirname(__FILE__), 'gpx_files/one_segment.gpx')
8
+ ONE_SEGMENT_NO_TIME = File.join(File.dirname(__FILE__), 'gpx_files/one_segment_no_time.gpx')
9
9
 
10
- def setup
11
- @gpx_file = GPX::GPXFile.new(:gpx_file => ONE_SEGMENT)
12
- @segment = @gpx_file.tracks.first.segments.first
13
- end
10
+ def setup
11
+ @gpx_file = GPX::GPXFile.new(gpx_file: ONE_SEGMENT)
12
+ @segment = @gpx_file.tracks.first.segments.first
13
+ end
14
14
 
15
- def test_segment_read
16
- assert_equal(189, @segment.points.size)
17
- assert_equal(1144433525, @segment.earliest_point.time.to_i)
18
- assert_equal(1144437991, @segment.latest_point.time.to_i)
19
- assert_equal(1334.447, @segment.lowest_point.elevation)
20
- assert_equal(1480.087, @segment.highest_point.elevation)
21
- assert_in_delta(6.98803359528853, @segment.distance, 0.001)
22
- assert_equal(4466.0, @segment.duration)
23
- end
15
+ def test_segment_read
16
+ assert_equal(189, @segment.points.size)
17
+ assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
18
+ assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
19
+ assert_equal(1334.447, @segment.lowest_point.elevation)
20
+ assert_equal(1480.087, @segment.highest_point.elevation)
21
+ assert_in_delta(6.98803359528853, @segment.distance, 0.001)
22
+ assert_equal(4466.0, @segment.duration)
23
+ end
24
24
 
25
- def test_segment_read_no_time
26
- gpx_file_no_time = GPX::GPXFile.new(:gpx_file => ONE_SEGMENT_NO_TIME)
27
- segment_no_time = gpx_file_no_time.tracks.first.segments.first
28
- assert_equal(189, segment_no_time.points.size)
29
- assert_equal(1334.447, segment_no_time.earliest_point.elevation)
30
- assert_equal(1413.756, segment_no_time.latest_point.elevation)
31
- assert_equal(1334.447, segment_no_time.lowest_point.elevation)
32
- assert_equal(1480.087, segment_no_time.highest_point.elevation)
33
- assert_in_delta(6.98803359528853, segment_no_time.distance, 0.001)
34
- assert_equal(0, segment_no_time.duration)
35
- end
25
+ def test_segment_read_no_time
26
+ gpx_file_no_time = GPX::GPXFile.new(gpx_file: ONE_SEGMENT_NO_TIME)
27
+ segment_no_time = gpx_file_no_time.tracks.first.segments.first
28
+ assert_equal(189, segment_no_time.points.size)
29
+ assert_equal(1334.447, segment_no_time.earliest_point.elevation)
30
+ assert_equal(1413.756, segment_no_time.latest_point.elevation)
31
+ assert_equal(1334.447, segment_no_time.lowest_point.elevation)
32
+ assert_equal(1480.087, segment_no_time.highest_point.elevation)
33
+ assert_in_delta(6.98803359528853, segment_no_time.distance, 0.001)
34
+ assert_equal(0, segment_no_time.duration)
35
+ end
36
36
 
37
- def test_segment_crop
38
- crop_rectangle = GPX::Bounds.new( :min_lat=> 39.173000,
39
- :min_lon=> -109.010000,
40
- :max_lat=> 39.188000,
41
- :max_lon=> -108.999000)
42
- @segment.crop(crop_rectangle)
37
+ def test_segment_crop
38
+ crop_rectangle = GPX::Bounds.new(min_lat: 39.173000,
39
+ min_lon: -109.010000,
40
+ max_lat: 39.188000,
41
+ max_lon: -108.999000)
42
+ @segment.crop(crop_rectangle)
43
43
 
44
- assert_equal(106, @segment.points.size)
45
- assert_in_delta(4.11422061733046, @segment.distance, 0.001)
46
- assert_equal(1144435041, @segment.earliest_point.time.to_i)
47
- assert_equal(1144437752, @segment.latest_point.time.to_i)
48
- assert_equal(1407.027, @segment.lowest_point.elevation)
49
- assert_equal(1480.087, @segment.highest_point.elevation)
50
- assert_equal(39.173834, @segment.bounds.min_lat)
51
- assert_equal(-109.009995, @segment.bounds.min_lon)
52
- assert_equal(39.187868, @segment.bounds.max_lat)
53
- assert_equal(-108.999546, @segment.bounds.max_lon)
54
- assert_equal(2711.0, @segment.duration)
55
- end
44
+ assert_equal(106, @segment.points.size)
45
+ assert_in_delta(4.11422061733046, @segment.distance, 0.001)
46
+ assert_equal(1_144_435_041, @segment.earliest_point.time.to_i)
47
+ assert_equal(1_144_437_752, @segment.latest_point.time.to_i)
48
+ assert_equal(1407.027, @segment.lowest_point.elevation)
49
+ assert_equal(1480.087, @segment.highest_point.elevation)
50
+ assert_equal(39.173834, @segment.bounds.min_lat)
51
+ assert_equal(-109.009995, @segment.bounds.min_lon)
52
+ assert_equal(39.187868, @segment.bounds.max_lat)
53
+ assert_equal(-108.999546, @segment.bounds.max_lon)
54
+ assert_equal(2711.0, @segment.duration)
55
+ end
56
56
 
57
- def test_segment_delete
58
- delete_rectangle = GPX::Bounds.new( :min_lat=> 39.173000,
59
- :min_lon=> -109.010000,
60
- :max_lat=> 39.188000,
61
- :max_lon=> -108.999000)
62
- @segment.delete_area(delete_rectangle)
63
- assert_equal(83, @segment.points.size)
64
- assert_in_delta(3.35967118153605, @segment.distance, 0.001)
65
- assert_equal(1144433525, @segment.earliest_point.time.to_i)
66
- assert_equal(1144437991, @segment.latest_point.time.to_i)
67
- assert_equal(1334.447, @segment.lowest_point.elevation)
68
- assert_equal(1428.176, @segment.highest_point.elevation)
69
- assert_equal(39.180572, @segment.bounds.min_lat)
70
- assert_equal(-109.016604, @segment.bounds.min_lon)
71
- assert_equal(39.188747, @segment.bounds.max_lat)
72
- assert_equal(-109.007978, @segment.bounds.max_lon)
73
- assert_equal(4466.0, @segment.duration)
74
- end
57
+ def test_segment_delete
58
+ delete_rectangle = GPX::Bounds.new(min_lat: 39.173000,
59
+ min_lon: -109.010000,
60
+ max_lat: 39.188000,
61
+ max_lon: -108.999000)
62
+ @segment.delete_area(delete_rectangle)
63
+ assert_equal(83, @segment.points.size)
64
+ assert_in_delta(3.35967118153605, @segment.distance, 0.001)
65
+ assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
66
+ assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
67
+ assert_equal(1334.447, @segment.lowest_point.elevation)
68
+ assert_equal(1428.176, @segment.highest_point.elevation)
69
+ assert_equal(39.180572, @segment.bounds.min_lat)
70
+ assert_equal(-109.016604, @segment.bounds.min_lon)
71
+ assert_equal(39.188747, @segment.bounds.max_lat)
72
+ assert_equal(-109.007978, @segment.bounds.max_lon)
73
+ assert_equal(4466.0, @segment.duration)
74
+ end
75
75
 
76
- def test_segment_smooth
77
- @segment.smooth_location_by_average
78
- assert_equal(189, @segment.points.size)
79
- assert_equal(1144433525, @segment.earliest_point.time.to_i)
80
- assert_equal(1144437991, @segment.latest_point.time.to_i)
81
- assert_equal(1342.58, @segment.lowest_point.elevation)
82
- assert_equal(1479.09, @segment.highest_point.elevation)
83
- assert_in_delta(6.458085658, @segment.distance, 0.001)
84
- assert_equal(4466.0, @segment.duration)
85
- end
76
+ def test_segment_smooth
77
+ @segment.smooth_location_by_average
78
+ assert_equal(189, @segment.points.size)
79
+ assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
80
+ assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
81
+ assert_equal(1342.58, @segment.lowest_point.elevation)
82
+ assert_equal(1479.09, @segment.highest_point.elevation)
83
+ assert_in_delta(6.458085658, @segment.distance, 0.001)
84
+ assert_equal(4466.0, @segment.duration)
85
+ end
86
86
 
87
- def test_segment_smooth_offset
88
- @segment.smooth_location_by_average({:start => 1000, :end => 2000})
89
- assert_equal(189, @segment.points.size)
90
- assert_equal(1144433525, @segment.earliest_point.time.to_i)
91
- assert_equal(1144437991, @segment.latest_point.time.to_i)
92
- assert_equal(1334.447, @segment.lowest_point.elevation)
93
- assert_equal(1480.087, @segment.highest_point.elevation)
94
- assert_in_delta(6.900813095, @segment.distance, 0.001)
95
- assert_equal(4466.0, @segment.duration)
96
- end
97
-
98
- def test_segment_smooth_absolute
99
- @segment.smooth_location_by_average({:start => Time.at(1144434520), :end => Time.at(1144435520)})
100
- assert_equal(189, @segment.points.size)
101
- assert_equal(1144433525, @segment.earliest_point.time.to_i)
102
- assert_equal(1144437991, @segment.latest_point.time.to_i)
103
- assert_equal(1334.447, @segment.lowest_point.elevation)
104
- assert_equal(1480.087, @segment.highest_point.elevation)
105
- assert_in_delta(6.900813095, @segment.distance, 0.001)
106
- assert_equal(4466.0, @segment.duration)
107
- end
87
+ def test_segment_smooth_offset
88
+ @segment.smooth_location_by_average(start: 1000, end: 2000)
89
+ assert_equal(189, @segment.points.size)
90
+ assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
91
+ assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
92
+ assert_equal(1334.447, @segment.lowest_point.elevation)
93
+ assert_equal(1480.087, @segment.highest_point.elevation)
94
+ assert_in_delta(6.900813095, @segment.distance, 0.001)
95
+ assert_equal(4466.0, @segment.duration)
96
+ end
108
97
 
98
+ def test_segment_smooth_absolute
99
+ @segment.smooth_location_by_average(start: Time.at(1_144_434_520), end: Time.at(1_144_435_520))
100
+ assert_equal(189, @segment.points.size)
101
+ assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
102
+ assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
103
+ assert_equal(1334.447, @segment.lowest_point.elevation)
104
+ assert_equal(1480.087, @segment.highest_point.elevation)
105
+ assert_in_delta(6.900813095, @segment.distance, 0.001)
106
+ assert_equal(4466.0, @segment.duration)
107
+ end
109
108
  end