{- Author: Wishnu Prasetya Copyright 2010 Wishnu Prasetya The use of this sofware is free under the GNU General Public License (GPL) version 3. -} module Sequenic.CTy.Priority where import Sequenic.CTy.Types import Sequenic.CTy.Combinations import qualified Data.Map as Map import Data.List type PrioritySpec = [(String,Float)] type PrioritySpec_ = Map.Map String Float buildPriorityMap :: CTree -> PrioritySpec -> PrioritySpec_ buildPriorityMap ct ps = worker ps where classes = concat . map getClasses $ ct spec0 = Map.fromList (zip classes (repeat 0)) worker :: PrioritySpec -> PrioritySpec_ worker [] = spec0 worker ((n,k):ps) = updateOver spec k n_classes where spec = worker ps n_classes = classesOf ct n updateOver :: PrioritySpec_ -> Float -> [String] -> PrioritySpec_ updateOver spec k [] = spec updateOver spec k (c:cs) = updateOver (Map.insert c n spec) k cs where n = k `max` (spec Map.! c) sortSuite :: CTree -> PrioritySpec -> Suite -> [(TestCase,Float)] sortSuite ct ps suite = suite3 where priorityMap = buildPriorityMap ct ps valueOf tc = (sum . map (\(C_ _ c)-> priorityMap Map.! c) $ tc) / n where n :: Float n = fromInteger . toInteger . length $ tc suite2 = map (\t-> (t, valueOf t)) suite suite3 = sortBy r suite2 where r (_,v1) (_,v2) = if v1>v2 then LT else if v1 2.1, "Age" --> 0.5 ] suite0 = fullComb ctx0 suite1 = sortSuite ctx0 pspec suite0 printResult = sequence_ . map (\(t,n) -> putStr ("\n (" ++ show n ++ ") " ++ show t)) $ suite1 -}