Commit f2f4c46b authored by Pietro Abate's avatar Pietro Abate

Add unit tests for BoolVar

parent eb3233e4
......@@ -9,8 +9,9 @@ true: -traverse
<schema>: include
<runtime>: include
<{misc,types,typing,schema,compile,runtime}/*.cmx>: for-pack(Cduce_test)
<{misc,types}/*.cmx>: for-pack(Cduce_boolvar)
<parser/**>: package(ulex), package(netstring), syntax(camlp4o)
<schema/**>: package(pcre), package(netstring)
<runtime/**>: package(pcre), package(netstring)
<tests/libtest/tests.*>: package(netstring), package(pcre), package(oUnit), package(ulex), package(num), package(camlp4.lib), use_cduce_lib
<tests/libtest/tests*>: pp(camlp4orf.opt), package(netstring), package(pcre), package(oUnit), package(ulex), package(num), package(camlp4.lib), use_cduce_lib
......@@ -17,5 +17,3 @@ Normal
Pretty
Stats
BoolVar
BoolAtoms
......@@ -73,12 +73,12 @@ let boolvar_tests_atoms = [
"associativity union", BAP.os "(atm foo v atm bar) v atm baz", BAP.os "atm foo v (atm bar v atm baz)";
"difference", BAP.os "(atm foo ^ atm bar) v var alpha", BAP.os "var alpha";
"difference empty", BAP.os "atm foo ^ atm bar", BAP.os "Empty";
(* vars = Any -> no variables in the tree *)
"splitvar vars empty", fst(BoolAtoms.splitvars (BAP.os "atm foo")), BAP.os "Any";
"splitvar vars empty", fst(BoolAtoms.splitvars (BAP.os "atm foo")), BAP.os "Empty";
"splitvar atm empty", snd(BoolAtoms.splitvars (BAP.os "var alpha")), BAP.os "Empty";
"splitvar vars 1 ", fst(BoolAtoms.splitvars (BAP.os "var alpha ^ (atm foo v var beta) ^ var gamma")), BAP.os "var alpha ^ var gamma";
"splitvar atm 1", snd(BoolAtoms.splitvars (BAP.os "var alpha v (atm foo ^ var beta) v var gamma")), BAP.os "var gamma v var alpha v ( atm foo ^ var beta)";
"splitvar vars 1 ", fst(BoolAtoms.splitvars (BAP.os "var alpha v (atm foo ^ var beta) v var gamma")), BAP.os "var alpha v var gamma";
"splitvar atm 1", snd(BoolAtoms.splitvars (BAP.os "var alpha v (atm foo ^ var beta) v var gamma")), BAP.os "atm foo ^ var beta";
"splitvar atm 2", snd(BoolAtoms.splitvars (BAP.os "var alpha v atm foo")), BAP.os "atm foo";
"splitvar vars 2", fst(BoolAtoms.splitvars (BAP.os "var alpha v atm foo")), BAP.os "var alpha";
];;
......
......@@ -8,7 +8,6 @@ module V = struct
let to_string = string_of_tag
end
module SymbolSet = SortedList.FiniteCofinite(V)
let rec iter_sep sep f = function
......@@ -31,6 +30,10 @@ include SortedList.FiniteCofiniteMap(Ns.Uri)(SymbolSet)
let atom l =
atom (fst (V.value l), l)
(* this is to have a uniform signature of all basic types *)
type elem = V.t
let full = any
let contains l t =
contains (fst (V.value l), l) t
......@@ -76,7 +79,6 @@ let get_map q (mtags,mns,def) =
| None -> assert false
| Some x -> x
let mk_map l =
let all_ns = ref [] in
let all_tags = ref [] in
......
......@@ -16,8 +16,11 @@ end
include Custom.T
val print : t -> (Format.formatter -> unit) list
type elem = V.t
val empty : t
val any : t
val full : t (* same as any *)
val cup : t -> t -> t
val cap : t -> t -> t
......
......@@ -5,7 +5,6 @@ let (=) : int -> int -> bool = (=)
module type E =
sig
(* module V : sig type t end *)
type elem
include Custom.T
......@@ -28,6 +27,9 @@ sig
val empty : t
val full : t
(* same as full, but we keep it for the moment to avoid chaging
* the code everywhere *)
val any : t
val cup : t -> t -> t
val cap : t -> t -> t
val diff : t -> t -> t
......@@ -66,7 +68,7 @@ end
*
* *)
module type MAKE = functor (T : E) -> S with type elem = T.t Custom.pairvar
(* module type MAKE = functor (T : E) -> S with type elem = T.t Custom.pairvar *)
module Make(T : E) =
struct
......@@ -244,6 +246,7 @@ struct
let empty = False
let full = True
let any = True
let is_empty t = (t == empty)
......@@ -261,7 +264,7 @@ struct
| b :: l -> (equal a b) || (has_same a l)
let rec split x p i n =
if X.equal x (Custom.Atm T.empty) then False
if X.equal x (Custom.Atm T.empty) then False
else if i == True then True
else if equal p n then p ++ i
else let p = simplify p [i] and n = simplify n [i] in
......@@ -272,7 +275,6 @@ struct
match a with
| False -> False
| True -> if has_true l then False else True
| Split (_,Custom.Atm x, True,False,False) -> split (Custom.Atm(T.diff T.full x)) True False False
| Split (_,Custom.Atm x, False,False,True) -> split (Custom.Atm(T.diff T.full x)) True False False
| Split (_,x,p,i,n) ->
if (has_true l) || (has_same a l) then False
......@@ -420,18 +422,15 @@ struct
* a = only atoms as leaves
*)
let rec splitvars = function
| True -> True,True
(* True or False can only be under a variable *)
| True -> True,False
| False -> False,False
| Split (_,Custom.Var _, True,False,False) as x -> x, False
| Split (_,Custom.Atm _, True,False,False) as x -> True, x
| Split (_,x, p,i,n) ->
let l,p' = splitvars p in
let c,i' = splitvars i in
let r,n' = splitvars n in
match split x l c r, split x p' i' n' with
|t,Split (_,Custom.Var _, True,False,False) -> t,False
|(_,_) as t -> t
let splitvars t = splitvars t
| Split (_,Custom.Atm _, True,False,False) as x -> False, x
| Split (_,Custom.Atm _, _,_,_) -> assert false
| Split (_,((Custom.Var _) as x),p,i,n) ->
let p1,p2 = splitvars p in
let i1,i2 = splitvars i in
let n1,n2 = splitvars n in
split x p1 i1 n1, split x p2 i2 n2
end
......@@ -53,6 +53,10 @@ let to_int c = c
let empty = []
let any = [0,V.max_char]
(* this is to have a uniform signature of all basic types *)
type elem = V.t
let full = any
let char_class a b = if a<=b then [a,b] else empty
let atom a = [a,a]
......
......@@ -13,9 +13,11 @@ include Custom.T
val print : t -> (Format.formatter -> unit) list
val dump: Format.formatter -> t -> unit
type elem = V.t
val empty : t
val any : t
val full : t (* same as any *)
val cup : t -> t -> t
val cap : t -> t -> t
val diff : t -> t -> t
......
......@@ -18,7 +18,6 @@ let check i = ()
let from_int i = big_int_of_int i
let from_bigint i = i
let mk = big_int_of_string
let to_string = string_of_big_int
let get_int = int_of_big_int
......@@ -124,6 +123,10 @@ let hash = hash 0
let empty = []
let any = [Any]
(* this is to have a uniform signature of all basic types *)
type elem = V.t
let full = any
let bounded a b =
if le_big_int a b then [Bounded (a,b)] else empty
......
......@@ -37,8 +37,11 @@ end
include Custom.T
val print : t -> (Format.formatter -> unit) list
type elem = V.t
val empty : t
val any : t
val full : t (* same as any *)
val cup : t -> t -> t
val cap : t -> t -> t
val diff : t -> t -> t
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment