|
| 1 | +-module(space_age_test). |
| 2 | + |
| 3 | +-include_lib("eunit/include/eunit.hrl"). |
| 4 | + |
| 5 | +age_in_earth_years_test() -> |
| 6 | + equalFloat(space_age:ageOn(earth, 1000000000), 31.69). |
| 7 | + |
| 8 | +age_in_mercury_years_test() -> |
| 9 | + Seconds = 2134835688, |
| 10 | + equalFloat(space_age:ageOn(earth, Seconds), 67.65), |
| 11 | + equalFloat(space_age:ageOn(mercury, Seconds), 280.88). |
| 12 | + |
| 13 | +age_in_venus_years_test() -> |
| 14 | + Seconds = 189839836, |
| 15 | + equalFloat(space_age:ageOn(earth, Seconds), 6.02), |
| 16 | + equalFloat(space_age:ageOn(venus, Seconds), 9.78). |
| 17 | + |
| 18 | +age_in_mars_years_test() -> |
| 19 | + Seconds = 2329871239, |
| 20 | + equalFloat(space_age:ageOn(earth, Seconds), 73.83), |
| 21 | + equalFloat(space_age:ageOn(mars, Seconds), 39.25). |
| 22 | + |
| 23 | +age_in_jupiter_years_test() -> |
| 24 | + Seconds = 901876382, |
| 25 | + equalFloat(space_age:ageOn(earth, Seconds), 28.58), |
| 26 | + equalFloat(space_age:ageOn(jupiter, Seconds), 2.41). |
| 27 | + |
| 28 | +age_in_saturn_years_test() -> |
| 29 | + Seconds = 3000000000, |
| 30 | + equalFloat(space_age:ageOn(earth, Seconds), 95.06), |
| 31 | + equalFloat(space_age:ageOn(saturn, Seconds), 3.23). |
| 32 | + |
| 33 | +age_in_uranus_years_test() -> |
| 34 | + Seconds = 3210123456, |
| 35 | + equalFloat(space_age:ageOn(earth, Seconds), 101.72), |
| 36 | + equalFloat(space_age:ageOn(uranus, Seconds), 1.21). |
| 37 | + |
| 38 | +age_in_neptune_years_test() -> |
| 39 | + Seconds = 8210123456, |
| 40 | + equalFloat(space_age:ageOn(earth, Seconds), 260.16), |
| 41 | + equalFloat(space_age:ageOn(neptune, Seconds), 1.58). |
| 42 | + |
| 43 | +equalFloat(A, B) -> |
| 44 | + ?assertEqual(round(A,2), B). |
| 45 | + |
| 46 | +round(Number, Precision) -> |
| 47 | + P = math:pow(10, Precision), |
| 48 | + round(Number * P) / P. |
0 commit comments