Closed Preoo closed 3 years ago
This is minor "issue" but following implementation for exercise 7
boolOrInt :: String -> Validation (Either Bool Int) boolOrInt s = isBool s <|> isInt s where isInt = maybe (invalid "Not an Int") (pure . Right) . readMaybe isBool = maybe (invalid "Not a Bool") (pure . Left) . readMaybe
passes tests until string with valid integer in non decimal numeral system such as 0x1 or 0o2 is generated.
Example of failure:
boolOrInt "0x1" got: Ok (Right 1) expected: Errors ["Not a Bool","Not an Int"]
a. add a test case to enforce valid integers to be decimals
b. modify tests to allow non decimal integers
c. instruct students to regard valid integers to be only in decimal form and raise error otherwise in exercise description
good catch, thanks!
This is minor "issue" but following implementation for exercise 7
passes tests until string with valid integer in non decimal numeral system such as 0x1 or 0o2 is generated.
Example of failure:
Suggestions to help student catch/avoid this edge case
a. add a test case to enforce valid integers to be decimals
b. modify tests to allow non decimal integers
c. instruct students to regard valid integers to be only in decimal form and raise error otherwise in exercise description