mirror of
https://github.com/correl/elm.git
synced 2025-03-07 04:35:48 -10:00
Add SpaceAge example and test
This commit is contained in:
parent
6f914735a4
commit
556d32c4ec
3 changed files with 55 additions and 1 deletions
28
SpaceAge/SpaceAgeExample.elm
Normal file
28
SpaceAge/SpaceAgeExample.elm
Normal file
|
@ -0,0 +1,28 @@
|
|||
module SpaceAgeExample where
|
||||
|
||||
type Planet = Mercury
|
||||
| Venus
|
||||
| Earth
|
||||
| Mars
|
||||
| Jupiter
|
||||
| Saturn
|
||||
| Uranus
|
||||
| Neptune
|
||||
|
||||
|
||||
earthYearInSeconds = 365.25 * 24 * 60 * 60
|
||||
|
||||
ageOn : Planet -> Float -> Float
|
||||
ageOn planet seconds = seconds / (secondsPerYear planet)
|
||||
|
||||
secondsPerYear : Planet -> Float
|
||||
secondsPerYear planet =
|
||||
earthYearInSeconds * case planet of
|
||||
Mercury -> 0.2408467
|
||||
Venus -> 0.61519726
|
||||
Earth -> 1
|
||||
Mars -> 1.8808158
|
||||
Jupiter -> 11.862615
|
||||
Saturn -> 29.447498
|
||||
Uranus -> 84.016846
|
||||
Neptune -> 164.79132
|
25
SpaceAge/SpaceAgeTest.elm
Normal file
25
SpaceAge/SpaceAgeTest.elm
Normal file
|
@ -0,0 +1,25 @@
|
|||
module SpaceAgeTest where
|
||||
|
||||
-- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up.
|
||||
|
||||
import ElmTest.Test exposing (test, Test, suite)
|
||||
import ElmTest.Assertion exposing (assert, assertEqual)
|
||||
import ElmTest.Runner.Element exposing (runDisplay)
|
||||
|
||||
import SpaceAgeExample exposing (Planet(..), ageOn)
|
||||
|
||||
tests : Test
|
||||
tests = suite "SpaceAge Test Suite"
|
||||
[
|
||||
test "age in earth years" (assertEqual 32 (round (ageOn Earth 1000000000))),
|
||||
test "age in mercury years" (assertEqual 281 (round (ageOn Mercury 2134835688))),
|
||||
test "age in venus years" (assertEqual 10 (round (ageOn Venus 189839836))),
|
||||
test "age on mars" (assertEqual 39 (round (ageOn Mars 2329871239))),
|
||||
test "age on jupiter" (assertEqual 2 (round (ageOn Jupiter 901876382))),
|
||||
test "age on saturn" (assertEqual 3 (round (ageOn Saturn 3000000000))),
|
||||
test "age on uranus" (assertEqual 1 (round (ageOn Uranus 3210123456))),
|
||||
test "age on neptune" (assertEqual 2 (round (ageOn Neptune 8210123456)))
|
||||
]
|
||||
|
||||
|
||||
main = runDisplay tests
|
|
@ -23,7 +23,8 @@
|
|||
"Sublist",
|
||||
"Bob",
|
||||
"SumOfMultiples",
|
||||
"Strain"
|
||||
"Strain",
|
||||
"SpaceAge"
|
||||
],
|
||||
"exposed-modules": [],
|
||||
"dependencies": {
|
||||
|
|
Loading…
Add table
Reference in a new issue