mirror of
https://github.com/typeable/inflections-hs.git
synced 2024-08-15 17:10:21 +03:00
Relaxed Integer type
This commit is contained in:
parent
49743074fb
commit
4fdc9d6ac9
@ -21,7 +21,7 @@ where
|
||||
-- "nd"
|
||||
-- >>> ordinal 10
|
||||
-- "th"
|
||||
ordinal :: Integer -> String
|
||||
ordinal :: Integral a => a -> String
|
||||
ordinal number
|
||||
| remainder100 `elem` [11..13] = "th"
|
||||
| remainder10 == 1 = "st"
|
||||
@ -41,5 +41,5 @@ ordinal number
|
||||
-- "2nd"
|
||||
-- >>> ordinalize 10
|
||||
-- "10th"
|
||||
ordinalize :: Integer -> String
|
||||
ordinalize :: (Integral a, Show a) => a -> String
|
||||
ordinalize n = show n ++ ordinal n
|
||||
|
@ -1,3 +1,5 @@
|
||||
resolver: lts-6.4
|
||||
packages:
|
||||
- '.'
|
||||
extra-deps:
|
||||
- megaparsec-5.0.0
|
||||
|
@ -26,38 +26,38 @@ spec = do
|
||||
one :: Spec
|
||||
one =
|
||||
it "returns the ordinal for 1" $
|
||||
ordinal 1 `shouldBe` "st"
|
||||
ordinal (1 :: Integer) `shouldBe` "st"
|
||||
|
||||
two :: Spec
|
||||
two =
|
||||
it "returns the ordinal for 2" $
|
||||
ordinal 2 `shouldBe` "nd"
|
||||
ordinal (2 :: Integer) `shouldBe` "nd"
|
||||
|
||||
thousands :: Spec
|
||||
thousands = do
|
||||
it "returns the ordinal for 1002" $
|
||||
ordinal 1002 `shouldBe` "nd"
|
||||
ordinal (1002 :: Integer) `shouldBe` "nd"
|
||||
it "returns the ordinal for 1003" $
|
||||
ordinal 1003 `shouldBe` "rd"
|
||||
ordinal (1003 :: Integer) `shouldBe` "rd"
|
||||
|
||||
negatives :: Spec
|
||||
negatives = do
|
||||
it "returns the ordinal for -11" $
|
||||
ordinal (-11) `shouldBe` "th"
|
||||
ordinal (-11 :: Integer) `shouldBe` "th"
|
||||
it "returns the ordinal for -1021" $
|
||||
ordinal (-1021) `shouldBe` "st"
|
||||
ordinal (-1021 :: Integer) `shouldBe` "st"
|
||||
|
||||
fullOrdinals :: Spec
|
||||
fullOrdinals = do
|
||||
it "returns the full ordinal for 1" $
|
||||
ordinalize 1 `shouldBe` "1st"
|
||||
ordinalize (1 :: Integer) `shouldBe` "1st"
|
||||
it "returns the full ordinal for -1021" $
|
||||
ordinalize (-1021) `shouldBe` "-1021st"
|
||||
ordinalize (-1021 :: Integer) `shouldBe` "-1021st"
|
||||
|
||||
ordinalReturnsNotEmpty :: Spec
|
||||
ordinalReturnsNotEmpty =
|
||||
it "never returns empty" $ property $
|
||||
property <$> not . null . ordinal
|
||||
property <$> not . null . (ordinal :: Integer -> String)
|
||||
|
||||
ordinalizeContainsTheSameNumber :: Spec
|
||||
ordinalizeContainsTheSameNumber =
|
||||
|
Loading…
Reference in New Issue
Block a user