packages feed

factory-0.0.0.2: src/Factory/Test/QuickCheck/Bounds.hs

{-
	Copyright (C) 2011 Dr. Alistair Ward

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
-}
{- |
 [@AUTHOR@]	Dr. Alistair Ward

 [@DESCRIPTION@]	Defines /QuickCheck/-properties for "Data.Bounds".
-}

module Factory.Test.QuickCheck.Bounds(
-- * Functions
	quickChecks
) where

import qualified	Data.Ratio
import qualified	Factory.Data.Bounds	as Data.Bounds
import qualified	Test.QuickCheck

-- | Defines invariant properties.
quickChecks :: IO ()
quickChecks	= Test.QuickCheck.quickCheckWith Test.QuickCheck.stdArgs {Test.QuickCheck.maxSuccess = 1000} prop_product	where
	prop_product :: Data.Ratio.Ratio Integer -> Integer -> Data.Bounds.Bounds Integer -> Test.QuickCheck.Property
	prop_product ratio minLength bounds	= Test.QuickCheck.label "prop_product" $ Data.Bounds.product' ratio' minLength' bounds' == product (Data.Bounds.toList bounds')	where
		bounds'		= Data.Bounds.normalise bounds
		minLength'	= 1 + minLength `mod` 1000
		ratio'		= if r > 1
			then recip r
			else r
			where
				r	= abs ratio