{- Author: Wishnu Prasetya, Joao Amorim Copyright 2010 Wishnu Prasetya The use of this sofware is free under the GNU General Public License (GPL) version 3. -} module CTy.CRule where import Data.Maybe import CTy.TestVal import CTy.Example0 type PartitionName = String type CategoryName = String -- | A partition has a name, and is either made of more partitions, or it is -- a lowest level partition, which is also called a class. -- A lowest level partition may have further information, e.g. the concrete test-value -- representing it. -- data Partition tv = -- | split into subpartitions Node PartitionName [Partition tv] -- | lowest level partition, aka class | Leaf PartitionName tv deriving (Show,Eq) -- | A category has a name, and a list of partitions. data Category tv = Cat CategoryName [Partition tv] deriving (Show,Eq) -- | Representing a classification tree. Such a tree consists of, at the first layer, -- categories. data CTree tv = ClsTree [Category tv] deriving (Show,Eq) -- | Type to represent combination rules. data Rule = All CategoryName | Include [PartitionName] | Neg Rule -- full-variants of and : | Andp Rule Rule -- minimalistic variants of and : | Andm Rule Rule -- auxilliary combinators, requires arguments to be expressions -- over the same set of categories: | Union Rule Rule | Intersect Rule Rule deriving (Show,Eq) -- just a type to abbreviate Class type Class tv = (PartitionName,tv) -- Class, decorated with the name of the category to which it belong. type Class_ tv = (CategoryName,PartitionName,tv) -- | This represents a single test-case, which is a combination of classes. Semantically, -- it has to be such that such that every category is covered exactly once by such a -- combination. Only such a test-case is valid. type TestCase tv = [Class_ tv] -- | A suite is a set of combinations/test-cases. This is the output of our -- combination-generator. type Suite tv = [TestCase tv] -- just for test, a classification tree. This is decribed using plain notation, -- without using the DSL layer. ex0 = ClsTree [insuranceType,age,place] where insuranceType = Cat "insType" [ standard, comfort, super ] where standard = Leaf "standard" (checkTV . Frag . show $ Standard) comfort = Leaf "comfort" (checkTV . Frag . show $ Comfort) super = Leaf "super" (checkTV . Frag . show $ Super) age = Cat "age" [kid1,kid2,adult] where kid1 = Leaf "kid1" (checkTV . Int32 $ 4) kid2 = Leaf "kid2" (checkTV . Int32 $ 16) adult = Node "adult" [young,old] young = Leaf "young" (checkTV . Int32 $ 20) old = Leaf "old" (checkTV . Int32 $ 66) place = Cat "place" [city,noncity] where city = Leaf "city" (checkTV . StringN 100 $ "Amsterdam") noncity = Leaf "noncity" (checkTV . StringN 100 $ "Achterhoek")