#Gleam / Armstrong Numbers / Pattern Match Failed

5 messages · Page 1 of 1 (latest)

lofty pier
#

Hello! I'm working on the Armstrong Numbers exercise in Gleam. I've got a solution that produces some unexpected results from the test runner: for two of the tests, get the result:

test: the_largest_and_last_armstrong_number_test
error: Pattern match failed
site: armstrong_numbers_test:52
value: False```

I'm not sure what pattern match it's talking about. I'm not using pattern matching in my solution, and the test doesn't seem to be using it either. This error shows up both in the online editor and when trying it locally. When I try my solution by manually running it with values from the test input, it works fine and gives the expected result. 

Here's my solution:

pub fn is_armstrong_number(number: Int) -> Bool {
let assert Ok(digits) = int.digits(number, 10)
let num_digits = digits |> list.length |> int.to_float
digits
|> list.map(int.power(, num_digits))
|> list.map(result.unwrap(
, 0.0))
|> list.map(float.round)
|> int.sum
== number
}


Any advice?
#

In fact, it fails even with this 😆


pub fn is_armstrong_number(number: Int) -> Bool {
  case number {
    10 -> False
    100 -> False
    9475 -> False
    9_926_314 -> False
    9_926_314 -> False
    115_132_219_018_763_992_565_095_597_973_971_522_401 -> False
    186_709_961_001_538_790_100_634_132_976_990 -> False
    _ -> True
  }
}
left crown
#

I see that you actually hardcode in the values to test out the test runner, which is a good idea

#

However you made two mistakes, the last 2 big values were suppose to return True but you assign them to return False. So when i paste in the same code that you did but change them to True to match the expected result, it passed all the tests.

#

Which mean there isn't anything wrong with the test suite or test runner.
Upon closer inspection, the

error: Pattern match failed

just mean that they were expecting True but got False in both cases, so the matching failed.