{-# LANGUAGE OverloadedStrings #-} module Unit.Money (unitMoney) where import Test.Framework import Test.Framework.Providers.HUnit (testCase) import Test.HUnit ((@=?), Assertion) import Web.PayPal.Adaptive unitMoney :: Test unitMoney = testGroup "money" [ testCase "handle large negative amount correctly" largeNegative , testCase "handle negative amount correctly" negative , testCase "handle 0 correctly" zero , testCase "handle 1 correctly" oneDigit , testCase "handle 10 correctly" twoDigitsTrailingZero , testCase "show both decimals even if both are zero" threeDigitsTrailingZeros , testCase "show both decimals even if the second is zero" threeDigitsTrailingZero , testCase "handles large amount correctly" largeAmount ] testM2P :: Int -> String -> Assertion testM2P input correct = correct @=? m2PayPal USD { _usdCents = input } largeNegative :: Assertion largeNegative = testM2P (-98783) "-987.83" negative :: Assertion negative = testM2P (-1) "-0.01" zero :: Assertion zero = testM2P 0 "0.00" oneDigit :: Assertion oneDigit = testM2P 1 "0.01" twoDigitsTrailingZero :: Assertion twoDigitsTrailingZero = testM2P 10 "0.10" threeDigitsTrailingZeros :: Assertion threeDigitsTrailingZeros = testM2P 100 "1.00" threeDigitsTrailingZero :: Assertion threeDigitsTrailingZero = testM2P 110 "1.10" largeAmount :: Assertion largeAmount = testM2P 792874 "7928.74"