diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java index e17d0fad9..4c72fb1e5 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java @@ -141,7 +141,7 @@ public class CalorieUtils { double power = earthGravity * weight * speed * (K1 + grade) + K2 * (speed * speed * speed); // Get the calories in kcal - return power * timeUsed / UnitConversions.KCAL_TO_J; + return power * timeUsed * UnitConversions.J_TO_KCAL; } /** diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/util/CalorieUtilsTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/util/CalorieUtilsTest.java index aac24349f..673c7f28c 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/util/CalorieUtilsTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/util/CalorieUtilsTest.java @@ -95,15 +95,18 @@ public class CalorieUtilsTest extends TestCase { } /** - * Checks calculating cycling calorie. + * Checks calculating cycling calorie. 175 is the watt usage for a 90 kg bike + * + rider to go 9 m/s (20 mph or 32 km/h) on the flat. Reference */ public void testCalculateCalorieCycling() { grade = 0; weight = 90; start.setSpeed(9); stop.setSpeed(9); - double expected = 175 / 1000 / UnitConversions.KCAL_TO_J; + double expected = 175.0 * (TIME_INTERVAL / 1000) * UnitConversions.J_TO_KCAL; double actual = CalorieUtils.calculateCalorieCycling(start, stop, grade, weight); - assertEquals(expected, actual); + assertTrue((actual - expected) / expected < 0.02); } } \ No newline at end of file