packages feed

Decimal 0.2.0 → 0.2.1

raw patch · 5 files changed

+100/−92 lines, 5 filesdep +test-frameworkdep +test-framework-hunitdep +test-framework-quickcheck2dep ~HUnitdep ~QuickCheckdep ~base

Dependencies added: test-framework, test-framework-hunit, test-framework-quickcheck2

Dependency ranges changed: HUnit, QuickCheck, base

Files

Decimal.cabal view
@@ -1,19 +1,42 @@-Name:               Decimal-Version:            0.2.0-License:            BSD3-License-file:       LICENSE.txt-Copyright:          Paul Johnson, 2011-Author:             Paul Johnson-Maintainer:         paul@cogito.org.uk-Stability:          beta-Category:           Math-Build-Depends:	    base==4, QuickCheck>2.4, HUnit-Build-type:         Simple-Synopsis:           Decimal numbers with variable precision-Description:        A decimal number has an integer mantissa and a negative+Name:                Decimal+Version:             0.2.1+License:             BSD3+License-file:        LICENSE.txt+Copyright:           Paul Johnson, 2011+Author:              Paul Johnson+Maintainer:          paul@cogito.org.uk+Stability:           beta+Category:            Math+Cabal-version:       >=1.10+Build-type:          Simple+Synopsis:            Decimal numbers with variable precision+Description:         A decimal number has an integer mantissa and a negative                     exponent.  The exponent can be interpreted as the number                     of decimal places in the value.-Exposed-modules:    Data.Decimal-Extra-source-files: tests/Makefile, tests/Main.hs, README.txt-ghc-options:        -Wall-hs-source-dirs:     src,tests+Extra-source-files:  README.txt+tested-with:         GHC==7.0.4++library +  build-depends:    +                    base >= 4 && < 5,+                    QuickCheck >= 2.4+  hs-source-dirs:   src+  default-language: Haskell2010+  ghc-options:      -Wall+  exposed-modules:  Data.Decimal++test-suite Main+  type:            exitcode-stdio-1.0+  x-uses-tf:       true+  build-depends:   +                   base >= 4 && < 5,+                   HUnit >= 1.2 && < 2,+                   QuickCheck >= 2.4,+                   test-framework >= 0.4.1,+                   test-framework-quickcheck2,+                   test-framework-hunit+  ghc-options:     -Wall -rtsopts+  hs-source-dirs:  src, src/Data, tests+  default-language: Haskell2010+  main-is:         Main.hs+
README.txt view
@@ -22,9 +22,18 @@  Data.Decimal includes a set of QuickCheck properties which act as both tests and a formal specification (hence their inclusion in the Haddock-documentation).  To run the tests go into the "tests" directory and-type "make all".  A test coverage report will automatically be-produced in "tests/Report".+documentation).  To run the tests do: +   cabal configure --enable-tests+   cabal build+   cabal test+ Data.Decimal is an instance of Arbitrary, for your convenience in writing your own tests.+++Version 0.2.1+-------------++Fixed "base" dependency.+Put test suite under "cabal test"
src/Data/Decimal.hs view
@@ -67,8 +67,8 @@ -- overflow in the internal algorithms.  However the result of each operator -- will be converted to the mantissa type without checking for overflow. data (Integral i) => DecimalRaw i = Decimal {-      decimalPlaces :: {-# UNPACK #-} ! Word8,-      decimalMantissa :: {-# UNPACK #-} ! i}+      decimalPlaces :: ! Word8,+      decimalMantissa :: ! i}   -- | Arbitrary precision decimal type.  As a rule programs should do decimal
tests/Main.hs view
@@ -2,65 +2,57 @@  import Data.Decimal import Data.Ratio+import Data.Word import Test.HUnit-import Test.QuickCheck  -conf :: Args-conf = stdArgs {maxSuccess = 1000} +import Test.Framework as TF (defaultMain, testGroup, Test)+import Test.Framework.Providers.HUnit+import Test.Framework.Providers.QuickCheck2 (testProperty) ++ main :: IO ()-main = do-  putStrLn "QuickCheck Data.Decimal:"-  putStr "     * prop_readShow           "-  quickCheckWith conf $ prop_readShow-  putStr "     * prop_readShowPrecision  "-  quickCheckWith conf $ prop_readShowPrecision-  putStr "     * prop_fromIntegerZero    "-  quickCheckWith conf $ prop_fromIntegerZero-  putStr "     * prop_increaseDecimals   "-  quickCheckWith conf $ prop_increaseDecimals-  putStr "     * prop_decreaseDecimals   "-  quickCheckWith conf $ prop_decreaseDecimals-  putStr "     * prop_inverseAdd         "-  quickCheckWith conf $ prop_inverseAdd-  putStr "     * prop_repeatedAdd        "-  quickCheckWith conf $ prop_repeatedAdd-  putStr "     * prop_divisionParts      "-  quickCheckWith conf $ prop_divisionParts-  putStr "     * prop_divisionUnits      "-  quickCheckWith conf $ prop_divisionUnits-  putStr "     * prop_allocateParts      "-  quickCheckWith conf $ prop_allocateParts-  putStr "     * prop_allocateUnits      "-  quickCheckWith conf $ prop_allocateUnits-  putStr "     * prop_abs                "-  quickCheckWith conf $ prop_abs-  putStr "     * prop_signum             "-  quickCheckWith conf $ prop_signum+main = defaultMain tests -  putStrLn "Point tests:"-  _ <- runTestTT $ TestList-       [ TestCase $ assertEqual "pi to 3dp" -                      (Decimal 3 3142 :: Decimal)-                      (realFracToDecimal 3 (pi :: Double)),-         TestCase $ assertEqual "pi to 2dp"-                      (Decimal 2 314 :: Decimal)-                      (realFracToDecimal 2 (pi :: Double)),-         TestCase $ assertEqual "100*pi to 2dp"-                      (Decimal 2 31416 :: Decimal)-                      (realFracToDecimal 2 (100 * pi :: Double)),-         TestCase $ assertEqual "1.0 * pi"-                      (Decimal 1 31 :: Decimal)-                      (Decimal 1 10 *. (pi :: Double)),-         TestCase $ assertEqual "1.23 * pi"-                      (Decimal 2 386 :: Decimal)-                      (Decimal 2 123 *. (pi :: Double)),-         TestCase $ assertEqual "Decimal to DecimalRaw Int"-                      (Decimal 2 123 :: DecimalRaw Int)-                      (decimalConvert (Decimal 2 123 :: Decimal)),-         TestCase $ assertEqual "1.234 to rational"-                      (toRational (Decimal 3 1234 :: Decimal)) (1234 % 1000)++-- Monomorphic variations on polymorphic themes to avoid type default warnings.++dec :: Word8 -> Integer -> Decimal+dec = Decimal++dec1 :: Word8 -> Int -> DecimalRaw Int+dec1 = Decimal++piD :: Double+piD = pi++tests :: [TF.Test]+tests = [+        testGroup "QuickCheck Data.Decimal" [+                testProperty "readShow"           prop_readShow,+                testProperty "readShowPrecision"  prop_readShowPrecision,+                testProperty "fromIntegerZero"    prop_fromIntegerZero, +                testProperty "increaseDecimals"   prop_increaseDecimals,+                testProperty "decreaseDecimals"   prop_decreaseDecimals,+                testProperty "inverseAdd"         prop_inverseAdd,+                testProperty "repeatedAdd"        prop_repeatedAdd,+                testProperty "divisionParts"      prop_divisionParts,+                testProperty "divisionUnits"      prop_divisionUnits,+                testProperty "allocateParts"      prop_allocateParts,+                testProperty "allocateUnits"      prop_allocateUnits,+                testProperty "abs"                prop_abs,+                testProperty "signum"             prop_signum+                ],+        testGroup "Point tests Data.Decimal" [+                testCase "pi to 3dp"     (dec 3 3142  @=? realFracToDecimal 3 piD),+                testCase "pi to 2dp"     (dec 2 314   @=? realFracToDecimal 2 piD),+                testCase "100*pi to 2dp" (dec 2 31416 @=? realFracToDecimal 2 (100 * piD)),+                testCase "1.0 * pi"      (dec 1 31    @=? dec 1 10 *. piD),+                testCase "1.23 * pi"     (dec 2 386   @=? dec 2 123 *. piD),+                testCase "Decimal to DecimalRaw Int" +                                         (decimalConvert (dec 2 123) @=? dec1 2 123),+                testCase "1.234 to rational" (1234 % 1000 @=? (toRational (dec 3 1234)))+                ]        ]-  putStrLn "Tests completed."
− tests/Makefile
@@ -1,16 +0,0 @@-# Tests for Decimal numbers.--all:-	ghc --make -fhpc -i../src -odir . -hidir . -Wall Main.hs -o test-rset-	rm -f test-rset.tix-	./test-rset-	hpc markup --destdir=Report test-rset-	hpc report test-rset--clean:-	rm -fR Data-	rm -f test-rset.tix-	rm -f test-rset-	rm -f *.o *.hi-	rm -fR Report-