Added some tests.

This commit is contained in:
John Shaver 2017-06-27 15:23:35 -07:00
parent 930608a8e9
commit 84170a58b6
2 changed files with 85 additions and 5 deletions

View file

@ -2,13 +2,31 @@ module Tests exposing (..)
import Test exposing (..)
import Expect
import AnimationHelpers exposing (calculateAnimation)
import AnimationHelpers exposing (calculateAnimation, movePosition, distanceFromSpeed, fmod)
trimFloatX : Int -> Float -> Float
trimFloatX precision num =
((num * toFloat (10 ^ precision)) |> round |> toFloat) / toFloat (10 ^ precision)
trimTupleX : Int -> ( Float, Float ) -> ( Float, Float )
trimTupleX precision ( first, second ) =
( trimFloatX precision first, trimFloatX precision second )
trimFloat1 =
trimFloatX 1
trimTuple1 =
trimTupleX 1
all : Test
all =
describe "Elmman Test Suite"
[ describe "Player logic tests"
[ describe "Animations frame mapping function"
[ test "Animation frame calculations" <|
\() ->
Expect.equal (calculateAnimation 100 500 ( 0, 200 )) 40
@ -18,14 +36,75 @@ all =
, test "Animation frame calculations 3" <|
\() ->
Expect.equal (calculateAnimation 501 500 ( 0, 200 )) 0
, test "Animation frame calculations 4" <|
, test "Animation frame calculations with increased range" <|
\() ->
Expect.equal (calculateAnimation 500 500 ( 100, 300 )) 300
, test "Animation frame calculations 5" <|
, test "Animation frame calculations with increased range 2" <|
\() ->
Expect.equal (calculateAnimation 100 500 ( 100, 300 )) 140
, test "Animation frame calculations 6" <|
, test "Animation frame calculations with negative range" <|
\() ->
Expect.equal (calculateAnimation 100 500 ( -100, 100 )) -60
]
, describe "Position movement function"
[ test "Move 45 degrees 10 units" <|
\() ->
Expect.equal
(trimTuple1 (movePosition ( 0, 0 ) 45 10))
( 7.1, 7.1 )
, test "Move 45 degrees 200 units from 10,10" <|
\() ->
Expect.equal
(trimTuple1 (movePosition ( 10, 10 ) 45 200))
( 151.4, 151.4 )
, test "Move 158 degrees 200 units" <|
\() ->
Expect.equal
(trimTuple1 (movePosition ( 0, 0 ) 158 200))
( -185.4, 74.9 )
, test "Move 360 degrees 200 units" <|
\() ->
Expect.equal
(trimTuple1 (movePosition ( 0, 0 ) 360 200))
( 200, 0 )
, test "Move 312 degrees 150 units" <|
\() ->
Expect.equal
(trimTuple1 (movePosition ( 0, 0 ) 312 150))
( 100.4, -111.5 )
]
, describe "convert speed/time to distance function"
[ test "speed 200u/s for 4ms" <|
\() ->
Expect.equal
(trimFloat1 (distanceFromSpeed 200 4))
0.8
, test "speed 2000u/s for 1ms" <|
\() ->
Expect.equal
(distanceFromSpeed 2000 1)
2
, test "speed 1 u/s for 1ms" <|
\() ->
Expect.equal
(distanceFromSpeed 1 1)
0.001
, test "speed 1 u/s for 1000ms" <|
\() ->
Expect.equal
(distanceFromSpeed 1 1000)
1
]
, describe "modulus for float"
[ test "10.15 % 9" <|
\() ->
Expect.equal
(trimFloatX 2 (fmod 10.15 9))
1.15
, test "51934 % 123" <|
\() ->
Expect.equal
(fmod 51934 123)
28
]
]

View file

@ -13,6 +13,7 @@
"elm-community/json-extra": "2.3.0 <= v < 3.0.0",
"elm-lang/core": "5.0.0 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"folkertdev/svg-path-dsl": "2.0.0 <= v < 3.0.0",
"mgold/elm-random-pcg": "5.0.0 <= v < 6.0.0",
"rtfeldman/node-test-runner": "3.0.0 <= v < 4.0.0"
},