# Check basic SECONDO commands # # Jan 2011, Th Behr, C. Düntgen # delete database funtest; #setup funtest # if a command between the SETUP directive and the first # TESTCASE directive fails, then the whole test has failed # and we immediately skip to the teardown # (the whole test does not make sense anymore if the # SETUP has failed) create database funtest; open database funtest; let f1 = fun(x : int) x + 1; let f2 = fun(x : int , y : int) x * y; let f3 = fun(x : int) intstream(1, x); let f4 = fun(x : int, y : int) intstream(x,y); let f5 = fun(x : int) f1(x); let f6 = fun(x : int) f1(f1(x)); let f7 = fun(x : int) f4(x,f6(x)); let f8 = fun( x : int) f3(x) count; let f9 = fun(x : int, y : int) f4(f3(x) count, f8(y)); let f10 = fun(x : int, y : int) f9(x,y) count; let f11 = fun(x : int) intstream(1,x) transformstream; let f12 = fun(x : int) f11(x) tconsume; let f13 = fun(x : int) f11(x) consume; let f14 = fun(x : int) f11(x) f11(x) {a} product count; #testcase list algebras #yields success list algebra FunctionAlgebra; #testcase out1; #yields ((map int int) (fun (x int) (+ x 1))) query f1; #testcase out2; #yields ((map int int int) (fun (x int) (y int) (* x y))) query f2; #testcase out3; #yields ((map int (stream int)) (fun (x int) (intstream 1 x))) query f3 ; #testcase out4; #yields ((map int int (stream int)) (fun (x int) (y int) (intstream x y))) query f4 ; #testcase out5; #yields ((map int int) (fun (x int) (f1 x))) query f5 ; #testcase out6; #yields ((map int int) (fun (x int) (f1 (f1 x)))) query f6 ; #testcase out7; #yields ((map int (stream int)) (fun (x int) (f4 x (f6 x)))) query f7 ; #testcase out8; #yields ((map int int) (fun (x int) (count (f3 x)))) query f8 ; #testcase out9; #yields ((map int int (stream int))(fun (x int) (y int) (f4 (count (f3 x)) (f8 y)))) query f9 ; #testcase out10; #yields ((map int int int) (fun (x int) (y int) (count (f9 x y)))) query f10 ; #testcase out11; #yields ((map int (stream (tuple ( (Elem int))))) (fun (x int) (transformstream (intstream 1 x)))) query f11 ; #testcase out12; #yields ((map int (trel (tuple ( (Elem int))))) (fun (x int) (tconsume (f11 x)))) query f12 ; #testcase out13; #yields ((map int (rel (tuple ( (Elem int))))) (fun (x int) (consume (f11 x)))) query f13 ; # evaluation of functions #testcase eval1; #yields (int 1) query f1(0) ; #testcase error1; #yields error query f1("Wrong") ; #testcase eval2; #yields (int 12) query f2(3,4) ; #testcase error2; #yields error query f2(1) ; #testcase eval3; #yields (int 25) query f3(25) count; #testcase error3; #yields error query f3(25); #testcase eval4; #yields (int 26) query f4(25,50) count; #testcase eval5; #yields (int 5) query f5(4); #testcase eval6; #yields (int 6) query f6(4); #testcase eval7; #yields (int 3) query f7(4) count; #testcase error7; #yields error query f7(4); #testcase eval8; #yields (int 4) query f8(4); #testcase eval9 #yields (int 999997) query f9(3,999999 ) count; #testcase eval9_1 #yields (int 0) query f9(3,1 ) count; #testcase eval10 #yields (int 999997) query f10(3,999999 ) ; #testcase eval10_1 #yields (int 0) query f10(3,1 ); #testcase error11 #yields error query f11(999); #testcase eval11 #yields (int 999) query f11(999) count; #testcase eval11_2 #yields ((trel (tuple ((Elem int)))) ((1) (2) (3))) query f11(3) tconsume; #testcase eval12 #yields (int 999) query f12(999) count; #testcase eval12_2 #yields ((trel (tuple ((Elem int)))) ((1) (2) (3))) query f12(3); #testcase eval13 #yields ((rel (tuple ((Elem int)))) ((1) (2) (3))) query f13(3); #testcase eval14 #yields (int 144) query f14(12); # testing operator within #testcase within_1_object #yields (int 5) query 4 within [f1(.) ] #testcase within_error_1 #yields error query 4 feed within [f1(.) ] #testcase within_2_object #yields (int 5) query 4 within [ fun(x : int) x + 1 ] #testcase within_3_stream #yields (int 10) query intstream(1,10) count within [ intstream(1,.) ] count #testcase within_3_object #yields (int 10) query intstream(1,10) count within [ intstream(1,.) count ] #testcase within_4_stream #yields (int 1) query intstream(1,100000) namedtransformstream[No] extend[ TID : int2tid(.No)] createbtree[No] within [ . exactmatchS[30] ] count; #testcase within_5_stream #yields (int 666) query intstream(1,10) namedtransformstream[No] intstream(1,666) namedtransformstream[No] {a} product extend[ TID : int2tid(.No*666 + .No_a)] createbtree[No] within [ . exactmatchS[6] ] count; #testcase within_5_object #yields (int 666) query intstream(1,10) namedtransformstream[No] intstream(1,666) namedtransformstream[No] {a} product extend[ TID : int2tid(.No*666 + .No_a)] createbtree[No] within [ . exactmatchS[6] count ]; # testing operator within2 #testcase within2_1_object #yields (int 18) query intstream(1,10) count 8 within2 [ . + ..]; #testcase within2_error1 #yields error query intstream(1,10) 8 within2 [ . + ..]; #testcase within2_2_object #yields (int 20) query intstream(1,5) transformstream tconsume intstream(6,10) transformstream tconsume within2[ . feed .. feed concat . feed concat .. feed concat count]; #testcase within2_1_stream #yields (int 7) query 2 8 within2 [ intstream(. , ..) ] count; #testcase within2_2_stream #yields (int 20) query intstream(1,5) transformstream tconsume intstream(6,10) transformstream tconsume within2[ . feed .. feed concat . feed concat .. feed concat ] count; #testcase within2_3_object #yields (int 12) query 3 8 within2[ f1(.) + f3(..) count ]; #testcase within2_3_stream #yields (int 8) query 3 8 within2[ f3(..) ] count; #testcase within2_4_stream #yields (int 6) query 3 8 within2[ f4(., ..) ] count; #testcase within2_4_stream #yields (int 7) query f1(3 8 within2[ f4(., ..) ] count); # testing operator whiledo #testcase whiledo_1 #yields (int 10) query 1 whiledo[ . < 10; . + 1; TRUE] count #testcase whiledo_1_undef #yields (int 2) query [const int value undef] whiledo[. < 10; . + 1; TRUE] count; #testcase whiledo_2_fixpoint #yields (int 2) query 1 whiledo[ TRUE; . ; TRUE ] count; #testcase whiledo_3_single #yields (int 1) query 1 whiledo[ FALSE; . + 1; TRUE] count; #testcase whiledo_4_useFunObj #yields (int 9) query 1 whiledo[ f1(.) < 10; f1(.); TRUE] count; #testcase whiledo_5_useFunObjWithFixpoint #yields (int 2) query 1 whiledo[ . < 20; f3(.) count; TRUE] count; #testcase whiledo_6_useFunObj #yields (int 20) query 1 whiledo[. < 20; f4(0, .) count; TRUE] count; #testcase whiledo_7_TMerror_3rdIsStream #yields error query 1 whiledo[. < 20; f4(0, .); TRUE] count; #testcase whiledo_8_TMerror_1stIsStream #yields error query 1 feed whiledo[. < 10; . + 1; FALSE] count; #testcase whiledo_8_TMerror #yields error query "Hallo" whiledo[. < 10; .; TRUE] count; #testcase whiledo_9_TMerror_TypeMismatchArg1_3 #yields error query 1 whiledo[. < 10; num2str(.); TRUE] count; #testcase whiledo_10_TMerror_TypeMismatchArg1_2 #yields error query 1 whiledo[. < "a"; . + 1; TRUE] count; #testcase whiledo_11_TMerror_TypeMismatchArg4 #yields error query 1 whiledo[. < 10; . + 1; 1] count; #testcase whiledo_12_Endless #yields (int 1000) query 1 whiledo[ . < 2 ; . ; FALSE] head[1000] count; #testcase whiledo_13_Undef4thArg #yields (int 2) query 1 whiledo[ . < 2 ; . ; [const bool value undef]] head[1000] count; # testing functions within streams #testcase eval_obj_stream #yields (int 65) query intstream(1,10) transformstream extend[No: f1(.Elem)] sum[No]; #testcase eval_stream_stream #yields (int 55) query intstream(1,10) transformstream extend[No: f3(.Elem) count] sum[No]; #testcase within_stream_stream #yields (int 65) query intstream(1,10) transformstream extend[ No : .Elem within[ f1(.)]] sum[No]; #testcase fun_within_extendstream #yields (int 30) query intstream(1,10) transformstream extendstream[ No : f7(.Elem)] count; #testcase within_within_extendstream #yields (int 55) query intstream(1,10) transformstream extendstream[ No : .Elem within[ f3(.)] ] count; #testcase within_within_within #yields (int 5) query 3 within[ . + 1 within [ . + 1]]; #testcase any_crazy #yields (int 7) query 1 within[. feed namedtransformstream[A] extendstream[B: .A f6(.A) within2[ . whiledo[(. + ..) < 10; f1(.); TRUE ] ]] ] count; #testcase any_also_crazy #yields (int 100) query 10 within[ f3(.) namedtransformstream[A] extendstream[B: .A f6(.A) within2[ . whiledo[(. + ..) < 22; f1(.); TRUE ] ]] ] printstream count; # the TEARDOWN directive is followed by commands which # should be executed after the execution of all TESTCASES #teardown close database; delete database funtest;