Skip to content

Instantly share code, notes, and snippets.

@VoQn
Created January 26, 2012 10:17
Show Gist options
  • Save VoQn/1682097 to your computer and use it in GitHub Desktop.
Save VoQn/1682097 to your computer and use it in GitHub Desktop.
[0,0.1..1.0] != (map (/ 10) [0..10]) ? ref: http://qiita.com/items/1891
-- Is List Literal with Number liar ?
--
-- ;-)
--
-- This Sample Code Depend on test-framework, and QuickCheck 2
-- try this
-- cabal install test-framework
-- cabal install test-framework-th
-- cabal install test-framework-quickcheck2
-- cabal install QuickCheck
-- runhaskell numberliteral-is-liar.hs
{-# LANGUAGE TemplateHaskell #-}
module Main ( main ) where
import Test.Framework.TH
import Test.Framework
import Test.Framework.Providers.QuickCheck2
import Test.QuickCheck
main = $(defaultMainGenerator)
contains xs x = any (== x) xs
fixedList = map (/ 10) [1..10]
-- Do you expect to pass this test property ?
prop_floating_number_list =
forAll ( elements [0,0.1..1.0] ) $ contains fixedList
-- ;-)
prop_true_arbitrary_value =
forAll ( fmap (/ 10) $ elements [1..10] ) $ contains fixedList
-- Why? try ghci ;-)
-- > map (/ 10) [1..10]
-- > [0,0.1..1.0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment