Skip to content

Instantly share code, notes, and snippets.

@manuscrypt
Created May 28, 2016 18:31
Show Gist options
  • Save manuscrypt/fa1fe8f2da8253e33d24452ea5801829 to your computer and use it in GitHub Desktop.
Save manuscrypt/fa1fe8f2da8253e33d24452ea5801829 to your computer and use it in GitHub Desktop.
Testing a Tweet decode
module Tests exposing (..)
import Tweet exposing (..)
import Random exposing (Generator)
import Json.Encode as Encode
import Shrink
import Check exposing (..)
import Check.Test
import Check.Producer exposing (..)
import ElmTest
testId1 = 3141592654
testText1 = "drumpf says: no draught"
myClaims : Claim
myClaims =
suite "Tweet Decoding"
[ claim
"Decoding string containing proper tweet-JSON yields Tweet"
`that`
(\str -> Tweet.decode str)
`is`
Just <| (Tweet.Model testId1 (toString testId1) testText1)
`for`
producer
]
producer : Producer String
producer =
Producer generator Shrink.noShrink
generator : Generator String
generator =
Random.int 100 100000 `Random.andThen` (\id ->
string.generator `Random.andThen` (\id_str ->
string.generator |> Random.map (\text ->
[ ("id", Encode.int id)
, ("id_str", Encode.string id_str)
, ("text", Encode.string text)
]
|> Encode.object
|> Encode.encode)))
evidence : Evidence
evidence = quickCheck myClaims
main = ElmTest.consoleRunner (Check.Test.evidenceToTest evidence)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment