-1

this is the function

toRevDigits :: Integer -> [Integer]
toRevDigits 0 = []
toRevDigits x
    | x<0 = []
    | otherwise = lastDigit x:(toRevDigits (dropLastDigit x))

this is the test

testRevDigits :: (Integer, [Integer]) -> Bool
testRevDigits (n, [d]) = toRevDigits n ==[n]

ex2Tests :: [Test]
ex2Tests = [Test "toRevDigits test" testRevDigits
            [(321,[1,2,3]), (0,[]), ((-17),[])]
           ]

this is the error

*** Exception: LAB8Tests.hs:27:1-44: Non-exhaustive patterns in function         testRevDigits

how can i fix the tester to function to make it work?

1 Answers1

1

of course it is - in your testRevDigits you match for [d] - which means the second component of the input tuple will only work with lists of length 1 but you pass in longer lists.

My best guess is that you want this:

testRevDigits :: (Integer, [Integer]) -> Bool
testRevDigits (n,expected) = toRevDigits n == expected
Random Dev
  • 51,810
  • 9
  • 92
  • 119