-- -- An example of generating a test-suite. You first need to build and -- install CTy. Then do this at the commandline: -- -- runhaskell ExampleCT3hs -- module ExampleCT3 where import CTy.DSL import CTy.CRule import CTy.TestVal -- Defining a simple classification tree, of four categories. -- The tree is not decorated with weigth. Although it is possible -- to divide categories into intermediate classes, we do not do -- so in this example. So, each category is divided directly into -- lowest level classes. For each class you need to specify its -- name, and a concrete test value that represents it. ct :: CTree TestVal ct = tree [age,gender,studentType,nationality] where -- The category age, is an int. It is divided into three classes: -- child, adult, and invalid. The last represent invalid values of age. age = "age" <== [ -- each class is specified as a pair n %= v, where n -- is the name of the class, and v is a concrete test -- value that represents the class. "<=30" %= Int32 20, ">30" %= Int32 31, "invalid" %= Int32 (-1) ] -- The category gender is a string, divided into two classes. gender = "gender" <== [ "female" %= String "F", "male" %= String "M" ] studentType = "studentType" <== [ "master" %= String "M", "bachelor" %= String "B", "external" %= String "X" ] nationality = "nationality" <== [ "NL" %= String "netherlands", "EU" %= String "spain", "invalid" %= String "X@!" ] -- -- An example of generating a test suite. Below we specify a suite -- such that we have full combinations between the classes in the -- catefories nationality and studentType. We then fill/pad the resulting -- combinations with classes from the rest of the categories, but -- in a such way that this padding is "minimal" (the remaining classes -- only need to be covered individually at least once). -- Finally, we fix the order in which the classes occur. -- suite0 = ct $$ rule (incl ["nationality"] &&* incl "studentType") >>= paddingm >>= fixorder -- -- A main function, to dump the above suite into a text file. -- main :: IO() main = writeFile "tc.txt" (formatSuite suite0) where formatSuite s = concat [ "\n" ++ show tc | tc <- s ]