spec/hrmparser_spec.rb in teich-hrmparser-0.4.0 vs spec/hrmparser_spec.rb in teich-hrmparser-0.4.1

- old
+ new

@@ -50,114 +50,135 @@ type = Importer.file_type("spec/samples/polarRS200.hrm") type.should == "POLAR_HRM" end end - context "Parse garmin file" do - it "finds workout start time on a short workout" do - filename = "spec/samples/indoor-garmin-405.TCX" + context "Parse a GPS file" do + it "finds the duration, time" do + filename = "spec/samples/gps-with-suunto.gpx" data = File.read(filename) - importer = Importer::Garmin.new(:data => data) + importer = Importer::GPX.new(:data => data) workout = importer.restore - workout.time.should == Time.parse("Fri Aug 22 01:04:55 UTC 2008") + workout.time.should == Time.parse("Fri May 08 00:58:35 UTC 2009") + + # Duration is actualy less, but we don't account for stopped time right now + workout.duration.should be_close(6382,1) end - it "finds the duration on a short workout" do - filename = "spec/samples/indoor-garmin-405.TCX" + it "calculates the distance and speed" do + filename = "spec/samples/gps-with-suunto.gpx" data = File.read(filename) - importer = Importer::Garmin.new(:data => data) + importer = Importer::GPX.new(:data => data) workout = importer.restore - workout.duration.should be_close(755, 1) - end - it "indoor workout has no trackpoints" do - filename = "spec/samples/indoor-garmin-405.TCX" - data = File.read(filename) - importer = Importer::Garmin.new(:data => data) - workout = importer.restore - workout.distance.should be_nil - workout.average_hr.should be_nil - workout.average_speed.should be_nil - workout.altitude_gain.should be_nil - workout.trackpoints.should == {} - end - - # Parsing the full XML is just slow. Commenting out for now. - it "gets workout level settings for outdoor workout" do - filename = "spec/samples/outdoor-garmin-405.TCX" - data = File.read(filename) - importer = Importer::Garmin.new(:data => data) - workout = importer.restore - workout.distance.should be_close(11740, 5) - workout.average_hr.should be_close(149.7, 0.5) - workout.average_speed.should be_close(1.5, 0.2) - workout.altitude_gain.should be_close(583, 1.0) - end - - it "gets workout level settings for weird distance workout" do - filename = "spec/samples/garmin-405-dies-distance.TCX" - data = File.read(filename) - importer = Importer::Garmin.new(:data => data) - workout = importer.restore - workout.distance.should be_close(9426, 1) - workout.average_hr.should == nil workout.average_speed.should be_close(6.7, 0.2) - workout.altitude_gain.should be_close(40, 1.0) + workout.distance.should be_close(26427, 1) end - - it "doesn't have any 0 in latitude" do - filename = "spec/samples/garmin-405-with-0-0.TCX" - data = File.read(filename) - importer = Importer::Garmin.new(:data => data) - workout = importer.restore - workout.trackpoints.map {|tp| tp.lat.should_not == 0.0} - workout.trackpoints.map {|tp| tp.lat.should_not == "undefined"} - end end - context "Parse polar RS200 file" do - it "finds the duration and time" do - filename ="spec/samples/polarRS200.hrm" - data = File.read(filename) - importer = Importer::Polar.new(:data => data, :time_zone => "UTC") - workout = importer.restore - workout.duration.should be_close(3569,1) - workout.time.should == Time.parse("Thu Apr 16 12:01:55 UTC 2009") + context "Parse garmin file" do + it "finds workout start time on a short workout" do + filename = "spec/samples/indoor-garmin-405.TCX" + data = File.read(filename) + importer = Importer::Garmin.new(:data => data) + workout = importer.restore + workout.time.should == Time.parse("Fri Aug 22 01:04:55 UTC 2008") + end + it "finds the duration on a short workout" do + filename = "spec/samples/indoor-garmin-405.TCX" + data = File.read(filename) + importer = Importer::Garmin.new(:data => data) + workout = importer.restore + workout.duration.should be_close(755, 1) + end + it "indoor workout has no trackpoints" do + filename = "spec/samples/indoor-garmin-405.TCX" + data = File.read(filename) + importer = Importer::Garmin.new(:data => data) + workout = importer.restore + workout.distance.should be_nil + workout.average_hr.should be_nil + workout.average_speed.should be_nil + workout.altitude_gain.should be_nil + workout.trackpoints.should == {} + end + + # Parsing the full XML is just slow. Commenting out for now. + it "gets workout level settings for outdoor workout" do + filename = "spec/samples/outdoor-garmin-405.TCX" + data = File.read(filename) + importer = Importer::Garmin.new(:data => data) + workout = importer.restore + workout.distance.should be_close(11740, 5) + workout.average_hr.should be_close(149.7, 0.5) + workout.average_speed.should be_close(1.5, 0.2) + workout.altitude_gain.should be_close(583, 1.0) + end + + it "gets workout level settings for weird distance workout" do + filename = "spec/samples/garmin-405-dies-distance.TCX" + data = File.read(filename) + importer = Importer::Garmin.new(:data => data) + workout = importer.restore + workout.distance.should be_close(9426, 1) + workout.average_hr.should == nil + workout.average_speed.should be_close(6.7, 0.2) + workout.altitude_gain.should be_close(40, 1.0) + end + + it "doesn't have any 0 in latitude" do + filename = "spec/samples/garmin-405-with-0-0.TCX" + data = File.read(filename) + importer = Importer::Garmin.new(:data => data) + workout = importer.restore + workout.trackpoints.map {|tp| tp.lat.should_not == 0.0} + workout.trackpoints.map {|tp| tp.lat.should_not == "undefined"} + end end - it "calculates the average heartrate" do - filename ="spec/samples/polarRS200.hrm" - data = File.read(filename) - importer = Importer::Polar.new(:data => data, :time_zone => "UTC") - workout = importer.restore - workout.average_hr.should be_close(145, 1) + + context "Parse polar RS200 file" do + it "finds the duration and time" do + filename ="spec/samples/polarRS200.hrm" + data = File.read(filename) + importer = Importer::Polar.new(:data => data, :time_zone => "UTC") + workout = importer.restore + workout.duration.should be_close(3569,1) + workout.time.should == Time.parse("Thu Apr 16 12:01:55 UTC 2009") + end + it "calculates the average heartrate" do + filename ="spec/samples/polarRS200.hrm" + data = File.read(filename) + importer = Importer::Polar.new(:data => data, :time_zone => "UTC") + workout = importer.restore + workout.average_hr.should be_close(145, 1) + end end - end - context "Parse a Polar RR file" do - it "calculates the heart rate from RR" do - filename ="spec/samples/polarRS800-RR.hrm" - data = File.read(filename) - importer = Importer::Polar.new(:data => data, :time_zone => "UTC") - workout = importer.restore - workout.trackpoints.each {|tp| tp.hr.should < 220 && tp.hr.should > 30} - workout.average_hr.should be_close(115, 1) - workout.average_speed.should == nil + context "Parse a Polar RR file" do + it "calculates the heart rate from RR" do + filename ="spec/samples/polarRS800-RR.hrm" + data = File.read(filename) + importer = Importer::Polar.new(:data => data, :time_zone => "UTC") + workout = importer.restore + workout.trackpoints.each {|tp| tp.hr.should < 220 && tp.hr.should > 30} + workout.average_hr.should be_close(115, 1) + workout.average_speed.should == nil + end end - end - - context "Parse a Suunto T6C RR file" do - it "finds the duration and time" do - filename = "spec/samples/suunto-t6-RR-stops.sdf" - data = File.read(filename) - importer = Importer::Suunto.new(:data => data, :time_zone => "-0700") - workout = importer.restore - workout.duration.should be_close(4781,1) - workout.time.should == Time.parse("Thu May 07 14:16:07 -0700 2009") + + context "Parse a Suunto T6C RR file" do + it "finds the duration and time" do + filename = "spec/samples/suunto-t6-RR-stops.sdf" + data = File.read(filename) + importer = Importer::Suunto.new(:data => data, :time_zone => "-0700") + workout = importer.restore + workout.duration.should be_close(4781,1) + workout.time.should == Time.parse("Thu May 07 14:16:07 -0700 2009") + end + it "calculates the average HR" do + filename = "spec/samples/suunto-t6-RR-stops.sdf" + data = File.read(filename) + importer = Importer::Suunto.new(:data => data, :time_zone => "-0700") + workout = importer.restore + workout.average_hr.should be_close(152,1) + workout.average_speed.should == nil + end end - it "calculates the average HR" do - filename = "spec/samples/suunto-t6-RR-stops.sdf" - data = File.read(filename) - importer = Importer::Suunto.new(:data => data, :time_zone => "-0700") - workout = importer.restore - workout.average_hr.should be_close(152,1) - workout.average_speed.should == nil - end - end end end