Browse Source

remove scripts, add ocamlformat check

master
zapashcanon 2 years ago
parent
commit
4cf163cdf8
Signed by: zapashcanon GPG Key ID: 8981C3C62D1D28F1
  1. 9
      .build.yml
  2. 16
      .ocamlformat
  3. 7
      scripts/build.sh
  4. 7
      scripts/clean.sh
  5. 12
      scripts/coverage.sh
  6. 7
      scripts/doc.sh
  7. 8
      scripts/format.sh
  8. 7
      scripts/test.sh
  9. 9
      scripts/view_coverage.sh
  10. 7
      scripts/view_doc.sh
  11. 21
      src/memo.ml
  12. 17
      test/test.ml

9
.build.yml

@ -10,7 +10,11 @@ tasks:
- setup: |
opam init -y
opam update -y
opam install -y dune bisect_ppx odoc
opam install -y dune bisect_ppx odoc ocamlformat
- lint-format: |
cd memo
eval "$(opam env)"
ocamlformat -p ocamlformat --enable-outside-detected-project --check $(find . -name '*.ml')
- build: |
cd memo
eval "$(opam env)"
@ -28,6 +32,7 @@ tasks:
- deploy-coverage: |
cd memo
eval "$(opam env)"
scripts/coverage.sh
BISECT_ENABLE=YES dune runtest --no-buffer --force > /dev/null
bisect-ppx-report -html _coverage/ "$(find . -name 'bisect*.out')"
ssh -o StrictHostKeyChecking=no fs@zapashcanon.fr "mkdir -p /var/www/coverage.zapashcanon.fr/memo/"
scp -o StrictHostKeyChecking=no -q -r _coverage/* fs@zapashcanon.fr:/var/www/coverage.zapashcanon.fr/memo/

16
.ocamlformat

@ -1,16 +0,0 @@
version=0.11.0
break-sequences=true
doc-comments=before
field-space=loose
let-and=sparse
sequence-style=terminator
type-decl=sparse
wrap-comments=true
if-then-else=k-r
let-and=sparse
space-around-records
space-around-lists
space-around-arrays
cases-exp-indent=2
max-indent=2
break-cases=all

7
scripts/build.sh

@ -1,7 +0,0 @@
#!/bin/sh
set -eu
( cd "$(dirname "$0")/../"
eval "$(opam env)"
dune build @all )

7
scripts/clean.sh

@ -1,7 +0,0 @@
#!/bin/sh
set -eu
( cd "$(dirname "$0")/../"
eval "$(opam env)"
dune clean )

12
scripts/coverage.sh

@ -1,12 +0,0 @@
#!/bin/sh
set -eu
( cd "$(dirname "$0")/../"
scripts/clean.sh
eval "$(opam env)"
coverage=_coverage
rm -f "$(find . -name 'bisect*.out')" || true
rm -rf $coverage
BISECT_ENABLE=YES dune runtest --no-buffer --force > /dev/null
bisect-ppx-report -html $coverage/ "$(find . -name 'bisect*.out')" )

7
scripts/doc.sh

@ -1,7 +0,0 @@
#!/bin/sh
set -eu
( cd "$(dirname "$0")/../"
eval "$(opam env)"
dune build @doc )

8
scripts/format.sh

@ -1,8 +0,0 @@
#!/bin/sh
set -eu
( cd "$(dirname "$0")/../"
eval "$(opam env)"
ocamlformat -i src/*.ml
ocamlformat -i test/*.ml )

7
scripts/test.sh

@ -1,7 +0,0 @@
#!/bin/sh
set -eu
( cd "$(dirname "$0")/../"
eval "$(opam env)"
dune runtest )

9
scripts/view_coverage.sh

@ -1,9 +0,0 @@
#!/bin/sh
set -eu
( cd "$(dirname "$0")/../"
scripts/clean.sh
eval "$(opam env)"
coverage=_coverage
xdg-open $coverage/index.html )

7
scripts/view_doc.sh

@ -1,7 +0,0 @@
#!/bin/sh
set -eu
( cd "$(dirname "$0")/../"
doc=_build/default/_doc/_html
xdg-open $doc/index.html )

21
src/memo.ml

@ -5,9 +5,9 @@ module type S = sig
val memo : ((t -> 'a) -> t -> 'a) -> t -> 'a
end
(** Functions on the initial size used when creating a cache, you can change
get the current value, update it to a number of your choice, or reset it to
the default value. *)
(** Functions on the initial size used when creating a cache, you can change get
the current value, update it to a number of your choice, or reset it to the
default value. *)
let get_initial_cache_size, set_initial_cache_size, reset_initial_cache_size =
let default = 512 in
let initial_cache_size = ref default in
@ -15,8 +15,8 @@ let get_initial_cache_size, set_initial_cache_size, reset_initial_cache_size =
, (fun size -> initial_cache_size := size)
, fun () -> initial_cache_size := default )
(** [mk_memo create find add ff] gives a memoïzed version of the functional
[ff] using the functions [create], [find] and [add] for the cache. It's used
(** [mk_memo create find add ff] gives a memoïzed version of the functional [ff]
using the functions [create], [find] and [add] for the cache. It's used
internally and you shouldn't have to use it. *)
let mk_memo create find add ff =
let cache = create (get_initial_cache_size ()) in
@ -24,15 +24,14 @@ let mk_memo create find add ff =
try find cache k
with Not_found ->
let v = ff f k in
add cache k v;
v
add cache k v ; v
in
f
(** With the [Mk] functor, you can also directly provide a [Cache] module,
which should have the signature [Hashtbl.S]. We will include your cache
module and use it to define a [memo] function. It should be useful only if
you want to use another [Hashtbl] implementation or things like this. *)
(** With the [Mk] functor, you can also directly provide a [Cache] module, which
should have the signature [Hashtbl.S]. We will include your cache module and
use it to define a [memo] function. It should be useful only if you want to
use another [Hashtbl] implementation or things like this. *)
module Mk (Cache : Hashtbl.S) = struct
include Cache

17
test/test.ml

@ -1,11 +1,8 @@
let _ =
let fibo_res = [| 0; 1; 1; 2; 3; 5; 8; 13; 21; 34; 55; 89 |] in
let fibo_res = [|0; 1; 1; 2; 3; 5; 8; 13; 21; 34; 55; 89|] in
let fibo fibo x =
if x < 0 then invalid_arg "fibo";
if x < 2 then
x
else
fibo (x - 1) + fibo (x - 2)
if x < 0 then invalid_arg "fibo" ;
if x < 2 then x else fibo (x - 1) + fibo (x - 2)
in
let fibo1 = Memo.memo fibo in
let module Mem = Memo.Make (struct
@ -33,9 +30,9 @@ let _ =
end) in
let fibo4 = MemFake.memo fibo in
for i = 0 to Array.length fibo_res - 1 do
assert (fibo1 i = fibo_res.(i));
assert (fibo2 i = fibo_res.(i));
assert (fibo3 i = fibo_res.(i));
assert (fibo1 i = fibo_res.(i)) ;
assert (fibo2 i = fibo_res.(i)) ;
assert (fibo3 i = fibo_res.(i)) ;
assert (fibo4 i = fibo_res.(i))
done;
done ;
Format.printf "Tests are OK !@."
Loading…
Cancel
Save