2006-10-14 15:20:23 +02:00
|
|
|
require 'test/unit'
|
2006-12-04 07:47:41 +01:00
|
|
|
require 'yaml'
|
2013-06-16 01:35:46 +02:00
|
|
|
require 'gpx'
|
2006-10-14 15:20:23 +02:00
|
|
|
|
2008-02-11 22:13:48 +01:00
|
|
|
class SegmentTest < Test::Unit::TestCase
|
2006-10-14 15:20:23 +02:00
|
|
|
ONE_SEGMENT = File.join(File.dirname(__FILE__), "gpx_files/one_segment.gpx")
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@gpx_file = GPX::GPXFile.new(:gpx_file => ONE_SEGMENT)
|
|
|
|
@segment = @gpx_file.tracks.first.segments.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_segment_read
|
|
|
|
assert_equal(189, @segment.points.size)
|
2011-11-06 15:38:46 +01:00
|
|
|
assert_equal(1144433525, @segment.earliest_point.time.to_i)
|
|
|
|
assert_equal(1144437991, @segment.latest_point.time.to_i)
|
2006-10-14 15:20:23 +02:00
|
|
|
assert_equal(1334.447, @segment.lowest_point.elevation)
|
|
|
|
assert_equal(1480.087, @segment.highest_point.elevation)
|
2013-06-15 12:11:43 +02:00
|
|
|
assert_in_delta(6.98803359528853, @segment.distance, 0.001)
|
2006-10-14 15:20:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_segment_crop
|
|
|
|
crop_rectangle = GPX::Bounds.new( :min_lat=> 39.173000,
|
|
|
|
:min_lon=> -109.010000,
|
|
|
|
:max_lat=> 39.188000,
|
|
|
|
:max_lon=> -108.999000)
|
|
|
|
@segment.crop(crop_rectangle)
|
|
|
|
|
2013-06-15 12:11:43 +02:00
|
|
|
assert_equal(106, @segment.points.size)
|
|
|
|
assert_in_delta(4.11422061733046, @segment.distance, 0.001)
|
2011-11-06 15:38:46 +01:00
|
|
|
assert_equal(1144435041, @segment.earliest_point.time.to_i)
|
|
|
|
assert_equal(1144437752, @segment.latest_point.time.to_i)
|
2006-10-14 15:20:23 +02:00
|
|
|
assert_equal(1407.027, @segment.lowest_point.elevation)
|
|
|
|
assert_equal(1480.087, @segment.highest_point.elevation)
|
|
|
|
assert_equal(39.173834, @segment.bounds.min_lat)
|
|
|
|
assert_equal(-109.009995, @segment.bounds.min_lon)
|
|
|
|
assert_equal(39.187868, @segment.bounds.max_lat)
|
|
|
|
assert_equal(-108.999546, @segment.bounds.max_lon)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_segment_delete
|
|
|
|
delete_rectangle = GPX::Bounds.new( :min_lat=> 39.173000,
|
|
|
|
:min_lon=> -109.010000,
|
|
|
|
:max_lat=> 39.188000,
|
|
|
|
:max_lon=> -108.999000)
|
|
|
|
@segment.delete_area(delete_rectangle)
|
2013-06-15 12:11:43 +02:00
|
|
|
assert_equal(83, @segment.points.size)
|
|
|
|
assert_in_delta(3.35967118153605, @segment.distance, 0.001)
|
2011-11-06 15:38:46 +01:00
|
|
|
assert_equal(1144433525, @segment.earliest_point.time.to_i)
|
|
|
|
assert_equal(1144437991, @segment.latest_point.time.to_i)
|
2006-10-14 15:20:23 +02:00
|
|
|
assert_equal(1334.447, @segment.lowest_point.elevation)
|
|
|
|
assert_equal(1428.176, @segment.highest_point.elevation)
|
|
|
|
assert_equal(39.180572, @segment.bounds.min_lat)
|
|
|
|
assert_equal(-109.016604, @segment.bounds.min_lon)
|
|
|
|
assert_equal(39.188747, @segment.bounds.max_lat)
|
|
|
|
assert_equal(-109.007978, @segment.bounds.max_lon)
|
|
|
|
end
|
|
|
|
end
|