Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failed due to TypeError #105

dwayne opened this issue Aug 10, 2019 · 3 comments


Copy link

commented Aug 10, 2019

I got the following error as a reason for my test (zeroIsIdentityForAddition) failing:

This test failed because it threw an exception: "TypeError: Cannot read property '$' of undefined"

Here's the module under test (in particular look at the plus function):

module Natural.Unary exposing
  ( Natural
  , zero
  , isZero
  , succ
  , pred

  , fromInt, toInt

  , plus

type Natural = Natural (List ())

zero : Natural
zero =
  Natural []

isZero : Natural -> Bool
isZero (Natural n) =
  List.isEmpty n

succ : Natural -> Natural
succ (Natural n) =
  Natural (() :: n)

pred : Natural -> Natural
pred (Natural n) =
  Natural (Maybe.withDefault [] (List.tail n))

fromInt : Int -> Natural
fromInt n =
  Natural (List.repeat n ())

toInt : Natural -> Int
toInt (Natural n) =
  List.length n

plus : Natural -> Natural -> Natural
plus a b =
  if isZero a then
    succ b -- This is deliberate since I wanted to see how the test would fail.
    -- But it didn't fail in the way I expected. Least of all due to a type error.
    succ (plus (pred a) b)

And here's the failing test (in particular look at the zeroIsIdentityForAddition test):

module Test.Natural.Unary exposing
  ( zeroIsIdentityForAddition

import Expect
import Fuzz exposing (Fuzzer)
import Test exposing (Test, fuzz)

import Natural.Unary as Unary exposing (Natural)

zeroIsIdentityForAddition : Test
zeroIsIdentityForAddition =
  fuzz naturalFuzzer "plus zero n == n for all natural n" <|
    \n -> n
        |> Expect.equal n


naturalFuzzer : Fuzzer Natural
naturalFuzzer = Unary.fromInt (Fuzz.intRange 0 100)

This comment has been minimized.

Copy link

commented Aug 10, 2019

Could this be elm/core#1011?


This comment has been minimized.

Copy link

commented Aug 11, 2019

Yes, they seem related. I played around with Fuzz.intRange near values of 100 and I get the TypeError. In other cases it fails in the right way.


This comment has been minimized.

Copy link

commented Aug 11, 2019

In which case I believe there is nothing that can be done untill this is fixed in elm/core. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.