[Home]DojoDeveloppement/Lundi23Mars2009

AgileFrance | DojoDeveloppement | DernieresNouvelles | Preferences | AideEnLigne

Participants :

Rétrospective du /Lundi9Mars2009 :

[Pour ceux qui ne connaissent pas encore : aller voir _The Poignant Guide To Ruby_ par _Why The Lucky Stiff]

Thèmes proposés pour ce soir :

Le code de la soirée

module Main
where
import Test.QuickCheck
import Test.HUnit
import SubLists
import Data.List


limite :: [Int] -> Bool
limite xs = length xs < 15

prop_NombreSousListesEgaleDeuxPuissanceN :: [Int] -> Property
prop_NombreSousListesEgaleDeuxPuissanceN xs = 
    limite xs ==> length (subLists xs) == 2 ^ length xs


prop_PasDeDoublonEnEntreeAlorsPasDeDoublonEnSortie :: [Int] -> Property
prop_PasDeDoublonEnEntreeAlorsPasDeDoublonEnSortie xs =
    limite xs ==> sansDoublon xs ==> sansDoublon (subLists xs)

sansDoublon :: Eq a => [a] -> Bool
sansDoublon xs = length xs == length (nub xs)

aPlat :: [[Int]] -> [Int] 
aPlat = nub . concat

prop_ToutElementDuneSousListeEstElementDeLaListeInitiale :: [Int] -> Property
prop_ToutElementDuneSousListeEstElementDeLaListeInitiale xs =
    limite xs ==> all (`elem` xs) (aPlat (subLists xs))

prop_ChaqueElementDeSubListsEstUneSousListeDeLaListe :: [Int] -> Property 
prop_ChaqueElementDeSubListsEstUneSousListeDeLaListe xs = 
    limite xs ==> all (`isASubList` xs) (subLists xs)


tests = TestList 
	[isASubList [] [] ~?= True
	,isASubList [1] [2] ~?= False
	,isASubList [1] [1] ~?= True
	,isASubList [1] [0,1] ~?= True
	,isASubList [] [0,1] ~?= True
	,isASubList [1,2] [0,1,2,3] ~?= True]
		   

main = do quickCheck prop_NombreSousListesEgaleDeuxPuissanceN
	  quickCheck prop_PasDeDoublonEnEntreeAlorsPasDeDoublonEnSortie
	  quickCheck prop_ToutElementDuneSousListeEstElementDeLaListeInitiale
	  quickCheck prop_ChaqueElementDeSubListsEstUneSousListeDeLaListe
	  runTestTT tests
module SubLists
where

subLists :: [Int] -> [[Int]]
subLists []  = [[]]
subLists (x:xs) = sl ++ map (x:) sl 
    where sl = subLists xs

isASubList :: [Int] -> [Int] -> Bool
isASubList [] _ = True
isASubList (x:xs) [] = False
isASubList (x:xs) (y:ys) | x == y    =  isASubList xs ys
		         | otherwise =  isASubList (x:xs) ys

AgileFrance | DojoDeveloppement | DernieresNouvelles | Preferences | AideEnLigne
Edit this page | View other revisions
Last edited January 3, 2010 8:04 pm (diff)
Search: