Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
385 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
all: setup | ||
@echo "Please use Cabal to build this package; not make." | ||
./setup configure | ||
./setup build | ||
|
||
setup: Setup.lhs | ||
ghc --make -o setup Setup.lhs | ||
|
||
install: setup | ||
./setup install | ||
|
||
clean: | ||
-./setup clean | ||
-runghc Setup.lhs clean | ||
|
||
.PHONY: test | ||
test: test-ghc test-hugs | ||
@echo "" | ||
@echo "All tests pass." | ||
|
||
test-hugs: | ||
@echo " ****** Running hugs tests" | ||
runhugs -98 +o -P$(PWD):$(PWD)/testsrc: testsrc/runtests.hs | ||
|
||
test-ghc: | ||
@echo " ****** Building GHC tests" | ||
runghc Setup.lhs configure -f buildtests | ||
runghc Setup.lhs build | ||
@echo " ****** Running GHC tests" | ||
./dist/build/runtests/runtests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{- | ||
Copyright (C) 2009 John Goerzen <jgoerzen@complete.org> | ||
All rights reserved. | ||
For license and copyright information, see the file COPYRIGHT | ||
-} | ||
module TestInfrastructure where | ||
import qualified Test.QuickCheck as QC | ||
import qualified Test.HUnit as HU | ||
import Test.HUnit.Tools | ||
|
||
q :: QC.Testable a => String -> a -> HU.Test | ||
q = qc2hu 250 | ||
|
||
qverbose :: QC.Testable a => String -> a -> HU.Test | ||
qverbose = qc2huVerbose 250 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{- | ||
Copyright (C) 2009 John Goerzen <jgoerzen@complete.org> | ||
All rights reserved. | ||
For license and copyright information, see the file COPYRIGHT | ||
-} | ||
|
||
module TestMap where | ||
import TestInfrastructure | ||
import Data.Convertible | ||
import Test.QuickCheck | ||
import Test.QuickCheck.Tools | ||
import Test.QuickCheck.Instances | ||
import qualified Data.Map as Map | ||
|
||
propListMap :: [(Int, Int)] -> Result | ||
propListMap x = safeConvert x @?= Right (Map.fromList x) | ||
|
||
propMapList :: Map.Map Int Int -> Result | ||
propMapList x = safeConvert x @?= Right (Map.toList x) | ||
|
||
allt = [q "[(Int, Int)] -> Map" propListMap, | ||
q "Map -> [(Int, Int)]" propMapList] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
{- | ||
Copyright (C) 2009 John Goerzen <jgoerzen@complete.org> | ||
All rights reserved. | ||
For license and copyright information, see the file COPYRIGHT | ||
-} | ||
|
||
module TestNum where | ||
import TestInfrastructure | ||
import Data.Convertible | ||
import Test.QuickCheck | ||
import Test.QuickCheck.Tools | ||
import Data.Word | ||
|
||
prop_int_to_integer :: Int -> Result | ||
prop_int_to_integer x = | ||
safeConvert x @?= Right ((fromIntegral x)::Integer) | ||
|
||
prop_integer_to_int_pass :: Integer -> Property | ||
prop_integer_to_int_pass x = | ||
(x <= fromIntegral (maxBound :: Int)) && | ||
(x >= fromIntegral (minBound :: Int)) ==> | ||
safeConvert x @?= Right ((fromIntegral x)::Int) | ||
|
||
prop_integer_to_word8 :: Integer -> Result | ||
prop_integer_to_word8 x = | ||
safeConvert x @?= if x >= fromIntegral (minBound :: Word8) && | ||
x <= fromIntegral (maxBound :: Word8) | ||
then Right ((fromIntegral x)::Word8) | ||
else Left $ ConvertError (show x) "Integer" "Word8" "Input value outside of bounds: (0,255)" | ||
|
||
prop_integer_to_word8_safe :: Integer -> Property | ||
prop_integer_to_word8_safe x = | ||
x <= fromIntegral (maxBound :: Word8) && | ||
x >= fromIntegral (minBound :: Word8) ==> | ||
safeConvert x @?= Right ((fromIntegral x)::Word8) | ||
|
||
prop_integer_to_word8_unsafe :: Integer -> Property | ||
prop_integer_to_word8_unsafe x = | ||
x < fromIntegral (minBound :: Word8) || | ||
x > fromIntegral (maxBound :: Word8) ==> | ||
((safeConvert x)::ConvertResult Word8) @?= (Left $ ConvertError (show x) "Integer" "Word8" "Input value outside of bounds: (0,255)") | ||
|
||
prop_double_to_word8 :: Double -> Result | ||
prop_double_to_word8 x = | ||
safeConvert x @?= if truncate x >= toInteger (minBound :: Word8) && | ||
truncate x <= toInteger (maxBound :: Word8) | ||
then Right ((truncate x)::Word8) | ||
else Left $ ConvertError (show x) "Double" "Word8" "Input value outside of bounds: (0,255)" | ||
|
||
prop_double_to_word8_safe :: Double -> Property | ||
prop_double_to_word8_safe x = | ||
x <= fromIntegral (maxBound :: Word8) && | ||
x >= fromIntegral (minBound :: Word8) ==> | ||
safeConvert x @?= Right ((truncate x)::Word8) | ||
|
||
prop_double_to_word8_unsafe :: Double -> Property | ||
prop_double_to_word8_unsafe x = | ||
truncate x < toInteger (minBound :: Word8) || | ||
truncate x > toInteger (maxBound :: Word8) ==> | ||
((safeConvert x)::ConvertResult Word8) @?= (Left $ ConvertError (show x) "Double" "Word8" "Input value outside of bounds: (0,255)") | ||
|
||
propIntDouble :: Int -> Result | ||
propIntDouble x = | ||
safeConvert x @?= Right ((fromIntegral x)::Double) | ||
|
||
propIntChar :: Int -> Result | ||
propIntChar x = | ||
safeConvert x @?= if x >= fromEnum (minBound :: Char) && | ||
x <= fromEnum (maxBound :: Char) | ||
then Right ((toEnum x)::Char) | ||
else Left $ ConvertError (show x) "Int" "Char" "Input value outside of bounds: ('\\NUL','\\1114111')" | ||
|
||
propCharInt :: Int -> Property | ||
propCharInt x = | ||
x >= fromEnum (minBound :: Char) && x <= fromEnum (maxBound :: Char) ==> | ||
safeConvert c @?= Right ((fromEnum c)::Int) | ||
where c = (toEnum x)::Char | ||
|
||
propIntIntegerInt :: Int -> Result | ||
propIntIntegerInt x = | ||
Right x @=? do r1 <- ((safeConvert x)::ConvertResult Integer) | ||
((safeConvert r1)::ConvertResult Int) | ||
|
||
propDoubleRationalDouble :: Double -> Result | ||
propDoubleRationalDouble x = | ||
Right x @=? do r1 <- ((safeConvert x)::ConvertResult Rational) | ||
((safeConvert r1)::ConvertResult Double) | ||
|
||
allt = [q "Int -> Integer" prop_int_to_integer, | ||
q "Integer -> Int (safe bounds)" prop_integer_to_int_pass, | ||
q "Integer -> Word8 (general)" prop_integer_to_word8, | ||
q "Integer -> Word8 (safe bounds)" prop_integer_to_word8_safe, | ||
q "Integer -> Word8 (unsafe bounds)" prop_integer_to_word8_unsafe, | ||
q "Double -> Word8 (general)" prop_double_to_word8, | ||
q "Double -> Word8 (safe bounds)" prop_double_to_word8_safe, | ||
q "Double -> Word8 (unsafe bounds)" prop_double_to_word8_unsafe, | ||
q "Int -> Double" propIntDouble, | ||
q "Int -> Char" propIntChar, | ||
q "Char -> Int" propCharInt, | ||
q "identity Int -> Integer -> Int" propIntIntegerInt, | ||
q "identity Double -> Rational -> Double" propDoubleRationalDouble | ||
] |
Oops, something went wrong.