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

roman-numerals: test for Nothing #1209

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module Roman (numerals) where

numerals :: Int -> Maybe String
numerals = Just . go numeralMap
numerals number | number < 1 || number > 3999 = Nothing
numerals number = Just $ go numeralMap number
where
go pairs@((value, digits):pairs') n
| n >= value = digits ++ go pairs (n - value)
Expand Down
12 changes: 12 additions & 0 deletions exercises/practice/roman-numerals/test/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,16 @@ cases = [ Case { description = "1 is a single I"
, number = 3000
, expected = Just "MMM"
}
, Case { description = "4000 cannot be represented"
, number = 4000
, expected = Nothing
}
, Case { description = "0 cannot be represented"
, number = 0
, expected = Nothing
}
, Case { description = "-1 cannot be represented"
, number = -1
, expected = Nothing
}
]
Loading