elm-explorations / elm-explorations/test
Test failed due to TypeError
- Dominant language
- Elm
- Stars
- 244
- Forks
- 40
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 2
Description
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):
```elm
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.
else
succ (plus (pred a) b)
```
And here's the failing test (in particular look at the `zeroIsIdentityForAddition` test):
```elm
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 ->
Unary.plus Unary.zero n
|> Expect.equal n
-- HELPERS
naturalFuzzer : Fuzzer Natural
naturalFuzzer =
Fuzz.map Unary.fromInt (Fuzz.intRange 0 100)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.