Mentions légales du service

Skip to content
Snippets Groups Projects
Commit fd089217 authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Integrate Gabriel Radanne's stress test. Fix [make test] in the demos.

parent cf88cfd2
Branches
Tags
No related merge requests found
SHELL := bash
BUILD := ../../_build/default/demos/brz
.PHONY: all
all:
......@@ -6,7 +7,7 @@ all:
.PHONY: test
test: all
_build/default/Main.exe
$(BUILD)/Main.exe
@ if command -v dot >/dev/null ; then \
for f in *.dot ; do \
dot -Tpng $$f -O ; \
......@@ -15,6 +16,12 @@ test: all
echo "The program dot is required to visualize DFAs. Please install graphviz." ; \
fi
# This stress test, contributed by Gabriel Radanne, takes about 5 minutes.
.PHONY: testgen
testgen:
dune build TestGen.exe
$(BUILD)/TestGen.exe
.PHONY: clean
clean:
rm -f *~ *.dot.png
......
(* This testing infrastructure has been contributed by Gabriel Radanne.
It is based on regenerate: https://github.com/regex-generate/regenerate *)
let bos = '^'
let eos = '$'
let alphabet = ['a'; 'b'; 'c']
module Char = struct
include Char
let hash = Hashtbl.hash
let foreach f =
List.iter f (bos :: eos :: alphabet)
let print c =
Printf.sprintf "%c" c
let pp = Format.pp_print_char
end
module B =
Brzozowski.Make(Char)
open B
let compl l =
List.fold_left (fun l x -> CCList.remove ~eq:Char.equal ~x l) alphabet l
let set b l = disjunction (List.map char (if b then l else compl l))
(* Turn a regular expression from Regenerate into a [B] expression. *)
let rec to_re = let open Regenerate.Regex in function
| One -> B.epsilon
| Set (b, l) -> set b l
| Seq (re, re') -> to_re re @@ to_re re'
| Or (re, re') -> to_re re ||| to_re re'
| And (re, re') -> to_re re &&& to_re re'
| Not re -> B.neg (to_re re)
| Rep (0,None,re) -> B.star (to_re re)
| Rep (_,_,_re) -> assert false
let is_match re input =
match B.exec re input with None -> false | Some _ -> true
(* Check positive and negative samples. *)
let check (re, pos, neg) =
(* 1. Compile the regular expression. *)
let cre =
try
B.dfa (to_re re)
with _ ->
(* Discard regular expressions that we do not handle. *)
QCheck.assume_fail ()
in
(* 2. Test! *)
List.for_all (fun s -> is_match cre s) pos &&
List.for_all (fun s -> not (is_match cre s)) neg
module WordSeq (C : sig include Set.OrderedType val pp : t Fmt.t end) = struct
type char = C.t
type t = C.t Seq.t
let empty = Seq.empty
let singleton = OSeq.return
let length = OSeq.length
let append = OSeq.append
let cons = OSeq.cons
let pp fmt w = Seq.iter (C.pp fmt) w
let compare = OSeq.compare ~cmp:C.compare
end
(* Ensure that the whole word is matched *)
let add_boundaries =
let bounds s =
let (@) = OSeq.append in
OSeq.(return bos @ s @ return eos)
in
let whole_string re =
Regenerate.Regex.(seq [char bos; re; char eos])
in
QCheck.map_same_type
(fun (re, pos, neg) ->
whole_string re, List.map bounds pos, List.map bounds neg)
let test =
let module Word = WordSeq(Char) in
let module Stream = Segments.ThunkList(Word) in
let generator =
Regenerate.arbitrary
(module Word) (* Datastructure for words *)
(module Stream) (* Datastructure for streams of words *)
~compl:false (* Should we generate complement operations? *)
~pp:Fmt.char (* Printer for characters *)
~samples:100 (* Average number of samples for each regular expression *)
alphabet (* Alphabet *)
in
let generator = add_boundaries generator in
QCheck.Test.make generator check
let () = QCheck_runner.run_tests_main [test]
(executable
(library
(name Brzozowski)
(modules Brzozowski ListAux)
(libraries fix seq)
(flags "-w" "A-4-44")
)
(test
(name Main)
(libraries fix)
(modules Main)
(libraries Brzozowski)
(flags "-w" "A-4-44")
)
(test
(name TestGen)
(modules TestGen)
(libraries Brzozowski regenerate)
(flags "-w" "A-4-44")
)
......@@ -6,3 +6,7 @@ all:
clean:
rm -f *~
dune clean
.PHONY: test
test:
@ echo "No test here."
BUILD := ../../_build/default/demos/cyk
.PHONY: all
all:
dune build Bench.exe
.PHONY: test
test: all
_build/default/Bench.exe
$(BUILD)/Bench.exe
.PHONY: clean
clean:
......
(executable
(test
(name Bench)
(libraries fix)
(flags "-w" "A")
......
BUILD := ../../_build/default/demos/fib
.PHONY: all
all:
dune build Fib.exe
.PHONY: test
test: all
_build/default/Fib.exe
$(BUILD)/Fib.exe
.PHONY: clean
clean:
......
(executable
(test
(name Fib)
(libraries unix fix)
(flags "-w" "A")
......
BUILD := ../../_build/default/demos/hco
.PHONY: all
all:
dune build HashConsDemo.exe
.PHONY: test
test: all
_build/default/HashConsDemo.exe
$(BUILD)/HashConsDemo.exe
.PHONY: clean
clean:
......
(executable
(test
(name HashConsDemo)
(libraries fix)
(flags "-w" "A")
......
BUILD := ../../_build/default/demos/tst
.PHONY: all
all:
dune build Test.exe
.PHONY: test
test: all
_build/default/Test.exe
$(BUILD)/Test.exe
.PHONY: clean
clean:
......
(executable
(test
(name Test)
(libraries fix)
(flags "-w" "A")
......
......@@ -524,3 +524,7 @@ automata by Brzozowski's method is a good illustration of their application.
For more details,
please look at the
[full source code for this demo](https://gitlab.inria.fr/fpottier/fix/blob/master/demos/brz/).
As a bonus, Gabriel Radanne contributed a
[stress test](https://gitlab.inria.fr/fpottier/fix/blob/master/demos/brz/TestGen.ml)
based on [regenerate](https://github.com/regex-generate/regenerate).
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment