-- -- Example of how to specify classification trees and combination rules, -- and how to generate test-cases from them. -- -- We will just generate Haskell test-cases. The program to test is the -- program calcPremium in the module Example0. -- module CTy.Demo where import CTy.DSL import CTy.TestVal import CTy.Concretization import CTy.CRule import CTy.Example0 import CTy.TCgen -- -- A classification tree for calc Premium without weight values. -- ctree0 :: CTree TestVal ctree0 = tree [insuranceType,age,place] where insuranceType = "insType" <== [ "standard" %= frag Standard, "comfort" %= frag Comfort, "super" %= frag Super ] age = "age" <== [ "kid1" %= Int32 4, "kid2" %= Int32 16, adult ] where adult = "adult" <== [ "young" %= Int32 20, "old" %= Int32 66 ] place = "place" <== [ "city" %= StringN 100 "Amsterdam", "noncity" %= StringN 100 "Achterhoek" ] -- -- The same tree, but this version is decorated by weight information, -- which represent probabilities. -- ctree1 :: CTree (TestVal,Float) ctree1 = tree [insuranceType,age,place] where insuranceType = "insType" <== [ "standard" %%= (frag Standard, (0.5::Float)), "comfort" %%= (frag Comfort, 0.35) , "super" %%= (frag Super, 0.15) ] age = "age" <== [ "kid1" %%= (Int32 4, (0.2::Float)), "kid2" %%= (Int32 16, 0.2), adult ] where adult = "adult" <== [ "young" %%= (Int32 20, (0.4::Float)), "old" %%= (Int32 66, 0.2) ] place = "place" <== [ "city" %%= (StringN 100 "Amsterdam", (0.6::Float)) , "noncity" %%= (StringN 100 "Achterhoek", 0.4) ] -- -- Some examples of combination rules -- -- -- Generate a suite with some combination rule, then pad it, and prepare it -- for concretation (the fixorder and strip steps) -- suite1 = ctree0 $$ (rule (incl ["kid1"] &&* incl "insType") |*| rule (incl "place" &&* incl ["standard"])) >>= paddingf >>= fixorder >>= lift_ . strip -- -- Generate a suite with some combination rule, then pad it, then sort it -- according to its probabilistic weight interpretation. -- Then prepare the suite for concretation (the fixorder and strip steps) -- suite2 = ctree1 $$ rule (incl ["kid1"] &&* incl "insType") >>= paddingf >>= psort >>= lift_ . take 3 >>= fixorder >>= lift_ . strip2 -- -- This will produce the full suite, for demonstration. -- suite3 = ctree0 $$ rule (incl "insType" &&* incl "age" &&* incl "place") >>= fixorder >>= lift_ . strip mydir = "d:/workshop/PROJECTS/CTy/v2/src/CTy/" -- -- Convert the above suites to actual test scripts. You need to invoke gen1..3 -- to actually produce the scripts. The produced test scripts do not execute; -- you need to tell them to execute if that is what you want. -- Note also that the generators below won't generate test-oracles in the -- scripts. You have to fill them in yourself. -- -- We will just target Haskell in the generators below. gen1 = translate HaskellTargetLang suite1 (mydir ++ "TemplateExample0") (mydir ++ "Example0Test1.hs") "CTy.Example0Test1" gen2 = translate HaskellTargetLang suite2 (mydir ++ "TemplateExample0") (mydir ++ "Example0Test2.hs") "CTy.Example0Test2" gen3 = translate HaskellTargetLang suite3 (mydir ++ "TemplateExample0") (mydir ++ "Example0Test3.hs") "CTy.Example0Test3"