Commit 886b27e8 authored by MARCHE Claude's avatar MARCHE Claude

Interp: more benchs

parent 79b0c0a0
......@@ -122,10 +122,18 @@ goods examples/in_progress
echo ""
echo "=== Checking execution ==="
execute examples/euler001.mlw Euler001.run
execute examples/euler002.mlw Solve.run
# fails execute examples/same_fringe.mlw Test.test1
execute examples/selection_sort.mlw SelectionSort.test2
execute examples/euler001.mlw Euler001.bench
execute examples/euler002.mlw Solve.bench
execute examples/fibonacci.mlw FibonacciLogarithmic.bench
execute examples/same_fringe.mlw SameFringe.bench
# fails: execute examples/same_fringe.mlw --exec SameFringe.test5
# fails: execute examples/same_fringe.mlw --exec Test.test1
execute examples/selection_sort.mlw SelectionSort.bench
execute examples/insertion_sort.mlw InsertionSort.bench
# fails: examples/vacid_0_sparse_array.mlw --exec Harness.bench
# fails: examples/knuth_prime_numbers.mlw --exec PrimeNumbers.bench
# fails: examples/verifythis_fm2012_LRS.mlw --exec LCP_test.bench
# fails: examples/verifythis_fm2012_LRS.mlw --exec SuffixArray_test.bench
echo ""
echo "=== Checking drivers ==="
......
......@@ -169,5 +169,8 @@ module Euler001
div (3 * n3 * (n3+1) + 5 * n5 * (n5+1) - 15 * n15 * (n15+1)) 2
let run () = solve 1000
(* should return 233168 *)
(* should return 233168 *)
let bench () = if run () <> 233168 then absurd
end
......@@ -152,4 +152,6 @@ module Solve
let run () = f 4000000 (* should be 4613732 *)
let bench () = if run () <> 4613732 then absurd
end
......@@ -151,4 +151,9 @@ module FibonacciLogarithmic
let test42 () = fibo 42
let test2014 () = fibo 2014
let bench () =
if test42 () <> 267914296 then absurd;
if test2014 () <> 3561413997540486142674781564382874188700994538849211456995042891654110985470076818421080236961243875711537543388676277339875963824466334432403730750376906026741819889036464401788232213002522934897299928844192803507157647764542466327613134605502785287441134627457615461304177503249289874066244145666889138852687147544158443155204157950294129177785119464446668374163746700969372438526182906768143740891051274219441912520127
then absurd
end
......@@ -34,11 +34,29 @@ module InsertionSort
a[!j] <- v
done
let test () =
let test1 () =
let a = make 3 0 in
a[0] <- 7; a[1] <- 3; a[2] <- 1;
insertion_sort a;
a
let test2 () =
let a = make 8 0 in
a[0] <- 3; a[1] <- 1; a[2] <- 7; a[3] <- 0;
a[4] <- 4; a[5] <- 1; a[6] <- 6; a[7] <- 3;
insertion_sort a
a[0] <- 53; a[1] <- 91; a[2] <- 17; a[3] <- -5;
a[4] <- 413; a[5] <- 42; a[6] <- 69; a[7] <- 6;
insertion_sort a;
a
let bench () =
let a = test2 () in
if a[0] <> -5 then absurd;
if a[1] <> 6 then absurd;
if a[2] <> 17 then absurd;
if a[3] <> 42 then absurd;
if a[4] <> 53 then absurd;
if a[5] <> 69 then absurd;
if a[6] <> 91 then absurd;
if a[7] <> 413 then absurd
end
......
......@@ -93,4 +93,8 @@ module PrimeNumbers
done;
p
let bench () =
let t = prime_numbers 20 in
if t[0] <> 2 then absurd
end
......@@ -72,6 +72,8 @@ module SameFringe
let test4 () = same_fringe (Node (leaf a) b Empty) (Node Empty a (leaf b))
let test5 () = same_fringe (Node (leaf a) b Empty) (Node Empty b (leaf a))
let bench () = if not (test4 ()) then absurd
end
module Test
......
......@@ -38,9 +38,20 @@ module SelectionSort
let test2 () =
let a = make 8 0 in
a[0] <- 3; a[1] <- 1; a[2] <- 7; a[3] <- 0;
a[4] <- 4; a[5] <- 1; a[6] <- 6; a[7] <- 3;
a[0] <- 53; a[1] <- 91; a[2] <- 17; a[3] <- -5;
a[4] <- 413; a[5] <- 42; a[6] <- 69; a[7] <- 6;
selection_sort a;
a
let bench () =
let a = test2 () in
if a[0] <> -5 then absurd;
if a[1] <> 6 then absurd;
if a[2] <> 17 then absurd;
if a[3] <> 42 then absurd;
if a[4] <> 53 then absurd;
if a[5] <> 69 then absurd;
if a[6] <> 91 then absurd;
if a[7] <> 413 then absurd
end
......@@ -132,4 +132,18 @@ module Harness
let get_b_0 = get b 0 in assert { get_b_0 = default };
()
let bench () =
let a = create 10 default in
let b = create 20 default in
if get a 5 <> default then absurd;
if get b 7 <> default then absurd;
set a 5 c1;
set b 7 c2;
if get a 5 <> c1 then absurd;
if get b 7 <> c2 then absurd;
if get a 7 <> default then absurd;
if get b 5 <> default then absurd;
if get a 0 <> default then absurd;
if get b 0 <> default then absurd
end
......@@ -139,7 +139,6 @@ let lcp (a:array int) (x y:int) : int
end
(*
module LCP_test
(** test harness for lcp *)
......@@ -147,6 +146,7 @@ module LCP_test
use import array.Array
use import LCP
(*
let test () =
let arr = Array.make 4 0 in
arr[0]<-1; arr[1]<-2; arr[2]<-2; arr[3]<-5;
......@@ -175,10 +175,16 @@ let test () =
assert { is_common_prefix drr 2 3 1};
assert { not is_common_prefix drr 2 3 2};
check {x = 1}
*)
let bench () =
let arr = Array.make 4 0 in
arr[0]<-1; arr[1]<-2; arr[2]<-2; arr[3]<-5;
let x = lcp arr 1 2 in
if x <> 1 then absurd
end
*)
(** {2 Second module: sorting suffixes } *)
module SuffixSort
......@@ -339,7 +345,6 @@ end
(*
module SuffixArray_test
use import array.Array
......@@ -376,8 +381,16 @@ let test () =
check {x = 0 (* TODO *)}
*)
let bench () =
let arr = Array.make 4 0 in
arr[0]<-1; arr[1]<-2; arr[2]<-2; arr[3]<-5;
let sa = create arr in
if sa.suffixes[0] <> 0 then absurd;
if sa.suffixes[1] <> 1 then absurd;
if sa.suffixes[2] <> 2 then absurd;
if sa.suffixes[3] <> 3 then absurd
end
*)
(** {2 Fourth module: Longest Repeated Substring} *)
......
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