Skip to content

Instantly share code, notes, and snippets.

@robotarmy
Created December 8, 2017 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robotarmy/b79ee52b8467d19c70337a342d70ede6 to your computer and use it in GitHub Desktop.
Save robotarmy/b79ee52b8467d19c70337a342d70ede6 to your computer and use it in GitHub Desktop.
module Test.Numberish exposing(..)
import Test exposing (..)
import Test.Runner.Html exposing(..)
import Expect
main: TestProgram
main = run all
type alias Num = { string: String, float: Float, int: Int }
type Numberish =
SNum String | INum Int | FNum Float
eq: Numberish -> Numberish -> Bool
eq a b =
case a of
SNum stra ->
case b of
SNum strb ->
((stra == strb))
INum intb ->
((toString intb == stra))
FNum floatb ->
((toString floatb == stra))
INum inta ->
case b of
SNum strb ->
((toString inta == strb))
INum intb ->
((intb == inta))
FNum floatb ->
((floatb == toFloat inta))
FNum floata ->
case b of
SNum strb ->
((strb == toString floata))
INum intb ->
((toFloat intb == floata))
FNum floatb ->
((floatb == floata))
all : Test
all = describe "Numberish" [
test "(ne (INum 1) (FNum 1.0))" <|
\_ -> Expect.true "1 == 1.0" (eq (INum 1) (FNum 1.0))
, test "(ne (INum 1) (SNum \"1\"))" <|
\_ -> Expect.true "1 == \"1\"" (eq (INum 1) (SNum "1"))
, test "(ne (FNum 1.000019) (SNum \"1.000019\"))" <|
\_ -> Expect.true "1.000019 == \"1.000019\"" (eq (FNum 1.000019) (SNum "1.000019"))
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment