Merge commit '2a0ebbeaf79608503428731f7531d18cb0822601' from sequence

This commit is contained in:
Simon Cruanes 2014-12-01 16:05:36 +01:00
commit e8f63c3330
14 changed files with 131 additions and 7486 deletions

View file

@ -576,6 +576,12 @@ By chunks of [4096] bytes:
Sequence.IO.(chunks_of ~size:4096 "a" |> write_to "b");; Sequence.IO.(chunks_of ~size:4096 "a" |> write_to "b");;
]} ]}
Read the lines of a file into a list:
{[
Sequence.IO.lines "a" |> Sequence.to_list
]}
@since 0.3.4 *) @since 0.3.4 *)
module IO : sig module IO : sig

View file

@ -1,25 +1,5 @@
# Changelog # Changelog
## 0.5.4
- depend on `bytes`
- compliance with `-safe-string`
- `sequence.bigarray`
## 0.5.3
- bugfix: interaction between `take` and `is_empty`
## 0.5.2
- bugfix in `take`
- `on_list` for mapping lists through sequences
## 0.5.1
- `Sequence.IO` module, a very very simple way to read/write files
- options: `to_opt/of_opt/head/head_exn`
## 0.5 ## 0.5
- conversion with `klist` - conversion with `klist`
@ -82,4 +62,4 @@
- `zip`, `unzip` and `zip_i` to convert between `t` and `t2` - `zip`, `unzip` and `zip_i` to convert between `t` and `t2`
- added `scan` combinator - added `scan` combinator
note: git log --no-merges --pretty=%s previous_version..HEAD note: git log --no-merges previous_version..HEAD --pretty=%s

View file

@ -1,33 +1,11 @@
# OASIS_START # OASIS_START
# DO NOT EDIT (digest: 0c501104bbf1dfc40db58200fdbfdd57) # DO NOT EDIT (digest: 1e28d93f3671e8db9acf63b73cdbca82)
version = "0.5.4" version = "0.4.1"
description = "Simple sequence (iterator) datatype and combinators" description = "Simple sequence (iterator) datatype and combinators"
requires = "bytes"
archive(byte) = "sequence.cma" archive(byte) = "sequence.cma"
archive(byte, plugin) = "sequence.cma" archive(byte, plugin) = "sequence.cma"
archive(native) = "sequence.cmxa" archive(native) = "sequence.cmxa"
archive(native, plugin) = "sequence.cmxs" archive(native, plugin) = "sequence.cmxs"
exists_if = "sequence.cma" exists_if = "sequence.cma"
package "invert" (
version = "0.5.4"
description = "Simple sequence (iterator) datatype and combinators"
requires = "sequence delimcc"
archive(byte) = "invert.cma"
archive(byte, plugin) = "invert.cma"
archive(native) = "invert.cmxa"
archive(native, plugin) = "invert.cmxs"
exists_if = "invert.cma"
)
package "bigarray" (
version = "0.5.4"
description = "Simple sequence (iterator) datatype and combinators"
requires = "sequence bigarray"
archive(byte) = "bigarray.cma"
archive(byte, plugin) = "bigarray.cma"
archive(native) = "bigarray.cmxa"
archive(native, plugin) = "bigarray.cmxs"
exists_if = "bigarray.cma"
)
# OASIS_STOP # OASIS_STOP

View file

@ -57,13 +57,11 @@ push_stable: all
git push origin git push origin
git checkout master git checkout master
VERSION=$(shell awk '/^Version:/ {print $$2}' _oasis) VERSION=$(shell awk '^/Version:/ {print $$2}' _oasis)
SOURCE=*.ml *.mli invert/*.ml invert/*.mli bigarray/*.ml bigarray/*.mli
update_next_tag: update_next_tag:
@echo "update version to $(VERSION)..." @echo "update version to $(VERSION)..."
sed -i "s/NEXT_VERSION/$(VERSION)/g" $(SOURCE) sed -i "s/NEXT_VERSION/$(VERSION)/g" *.ml *.mli
sed -i "s/NEXT_RELEASE/$(VERSION)/g" $(SOURCE) sed -i "s/NEXT_RELEASE/$(VERSION)/g" *.ml *.mli
.PHONY: benchs tests examples update_next_tag push_doc push_stable .PHONY: benchs tests examples update_next_tag push_doc push_stable

View file

@ -1,6 +1,6 @@
OASISFormat: 0.4 OASISFormat: 0.4
Name: sequence Name: sequence
Version: 0.5.4 Version: dev
Homepage: https://github.com/c-cube/sequence Homepage: https://github.com/c-cube/sequence
Authors: Simon Cruanes Authors: Simon Cruanes
License: BSD-2-clause License: BSD-2-clause
@ -59,7 +59,7 @@ Document sequence
XOCamlbuildLibraries: sequence XOCamlbuildLibraries: sequence
Test all Test all
Type: custom (0.4) Type: custom
Command: make run-tests Command: make run-tests
TestTools: run_tests TestTools: run_tests
Run$: flag(tests) Run$: flag(tests)

View file

@ -1,9 +1,8 @@
# OASIS_START # OASIS_START
# DO NOT EDIT (digest: 29e0c9fc65daf16caa16466d6ff32bac) # DO NOT EDIT (digest: ffd3fbaf00b431777fea1b8279203bf9)
# Ignore VCS directories, you can use the same kind of rule outside # Ignore VCS directories, you can use the same kind of rule outside
# OASIS_START/STOP if you want to exclude directories that contains # OASIS_START/STOP if you want to exclude directories that contains
# useless stuff for the build process # useless stuff for the build process
true: annot, bin_annot
<**/.svn>: -traverse <**/.svn>: -traverse
<**/.svn>: not_hygienic <**/.svn>: not_hygienic
".bzr": -traverse ".bzr": -traverse
@ -16,38 +15,17 @@ true: annot, bin_annot
"_darcs": not_hygienic "_darcs": not_hygienic
# Library sequence # Library sequence
"sequence.cmxs": use_sequence "sequence.cmxs": use_sequence
<*.ml{,i,y}>: pkg_bytes
# Library invert
"invert/invert.cmxs": use_invert
<invert/*.ml{,i,y}>: pkg_bytes
<invert/*.ml{,i,y}>: pkg_delimcc
<invert/*.ml{,i,y}>: use_sequence
# Library bigarray
"bigarray/bigarray.cmxs": use_bigarray
<bigarray/*.ml{,i,y}>: pkg_bigarray
<bigarray/*.ml{,i,y}>: pkg_bytes
<bigarray/*.ml{,i,y}>: use_sequence
# Executable run_tests
"tests/run_tests.native": pkg_bytes
"tests/run_tests.native": pkg_oUnit
"tests/run_tests.native": use_sequence
<tests/*.ml{,i,y}>: pkg_bytes
<tests/*.ml{,i,y}>: pkg_oUnit
<tests/*.ml{,i,y}>: use_sequence
# Executable benchs # Executable benchs
"bench/benchs.native": pkg_benchmark "bench/benchs.native": pkg_benchmark
"bench/benchs.native": pkg_bytes
"bench/benchs.native": use_sequence "bench/benchs.native": use_sequence
# Executable bench_persistent # Executable bench_persistent
"bench/bench_persistent.native": pkg_benchmark "bench/bench_persistent.native": pkg_benchmark
"bench/bench_persistent.native": pkg_bytes
"bench/bench_persistent.native": use_sequence "bench/bench_persistent.native": use_sequence
# Executable bench_persistent_read # Executable bench_persistent_read
"bench/bench_persistent_read.native": pkg_benchmark "bench/bench_persistent_read.native": pkg_benchmark
"bench/bench_persistent_read.native": pkg_bytes
"bench/bench_persistent_read.native": use_sequence "bench/bench_persistent_read.native": use_sequence
<bench/*.ml{,i,y}>: pkg_benchmark <bench/*.ml{,i}>: pkg_benchmark
<bench/*.ml{,i,y}>: pkg_bytes <bench/*.ml{,i}>: use_sequence
<bench/*.ml{,i,y}>: use_sequence
# OASIS_STOP # OASIS_STOP
true: bin_annot true: bin_annot
<**/*.ml>: warn_A, warn(-4)

View file

@ -1,4 +0,0 @@
# OASIS_START
# DO NOT EDIT (digest: dca476c3b57e859aa3b1c75ec0959ed9)
SequenceBigarray
# OASIS_STOP

View file

@ -1,4 +0,0 @@
# OASIS_START
# DO NOT EDIT (digest: dca476c3b57e859aa3b1c75ec0959ed9)
SequenceBigarray
# OASIS_STOP

View file

@ -1,4 +0,0 @@
# OASIS_START
# DO NOT EDIT (digest: d74492d261fcc87665b60e0331c04236)
SequenceInvert
# OASIS_STOP

View file

@ -1,4 +0,0 @@
# OASIS_START
# DO NOT EDIT (digest: d74492d261fcc87665b60e0331c04236)
SequenceInvert
# OASIS_STOP

View file

@ -1,5 +1,5 @@
(* OASIS_START *) (* OASIS_START *)
(* DO NOT EDIT (digest: 2ea21bad023bcdcb9626e204d039d0d2) *) (* DO NOT EDIT (digest: 958ece46307b808952e439e1cc47a739) *)
module OASISGettext = struct module OASISGettext = struct
(* # 22 "src/oasis/OASISGettext.ml" *) (* # 22 "src/oasis/OASISGettext.ml" *)
@ -39,10 +39,10 @@ module OASISExpr = struct
open OASISGettext open OASISGettext
type test = string type test = string
type flag = string type flag = string
type t = type t =
@ -52,10 +52,10 @@ module OASISExpr = struct
| EOr of t * t | EOr of t * t
| EFlag of flag | EFlag of flag
| ETest of test * string | ETest of test * string
type 'a choices = (t * 'a) list
type 'a choices = (t * 'a) list
let eval var_get t = let eval var_get t =
@ -249,9 +249,6 @@ module MyOCamlbuildFindlib = struct
*) *)
open Ocamlbuild_plugin open Ocamlbuild_plugin
type conf =
{ no_automatic_syntax: bool;
}
(* these functions are not really officially exported *) (* these functions are not really officially exported *)
let run_and_read = let run_and_read =
@ -318,7 +315,7 @@ module MyOCamlbuildFindlib = struct
(* This lists all supported packages. *) (* This lists all supported packages. *)
let find_packages () = let find_packages () =
List.map before_space (split_nl & run_and_read (exec_from_conf "ocamlfind" ^ " list")) List.map before_space (split_nl & run_and_read "ocamlfind list")
(* Mock to list available syntaxes. *) (* Mock to list available syntaxes. *)
@ -341,7 +338,7 @@ module MyOCamlbuildFindlib = struct
] ]
let dispatch conf = let dispatch =
function function
| After_options -> | After_options ->
(* By using Before_options one let command line options have an higher (* By using Before_options one let command line options have an higher
@ -360,39 +357,31 @@ module MyOCamlbuildFindlib = struct
* -linkpkg *) * -linkpkg *)
flag ["ocaml"; "link"; "program"] & A"-linkpkg"; flag ["ocaml"; "link"; "program"] & A"-linkpkg";
if not (conf.no_automatic_syntax) then begin (* For each ocamlfind package one inject the -package option when
(* For each ocamlfind package one inject the -package option when * compiling, computing dependencies, generating documentation and
* compiling, computing dependencies, generating documentation and * linking. *)
* linking. *) List.iter
List.iter begin fun pkg ->
begin fun pkg -> let base_args = [A"-package"; A pkg] in
let base_args = [A"-package"; A pkg] in (* TODO: consider how to really choose camlp4o or camlp4r. *)
(* TODO: consider how to really choose camlp4o or camlp4r. *) let syn_args = [A"-syntax"; A "camlp4o"] in
let syn_args = [A"-syntax"; A "camlp4o"] in let args =
let (args, pargs) = (* Heuristic to identify syntax extensions: whether they end in
(* Heuristic to identify syntax extensions: whether they end in ".syntax"; some might not.
".syntax"; some might not. *)
*) if Filename.check_suffix pkg "syntax" ||
if Filename.check_suffix pkg "syntax" || List.mem pkg well_known_syntax then
List.mem pkg well_known_syntax then syn_args @ base_args
(syn_args @ base_args, syn_args) else
else base_args
(base_args, []) in
in flag ["ocaml"; "compile"; "pkg_"^pkg] & S args;
flag ["ocaml"; "compile"; "pkg_"^pkg] & S args; flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S args;
flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S args; flag ["ocaml"; "doc"; "pkg_"^pkg] & S args;
flag ["ocaml"; "doc"; "pkg_"^pkg] & S args; flag ["ocaml"; "link"; "pkg_"^pkg] & S base_args;
flag ["ocaml"; "link"; "pkg_"^pkg] & S base_args; flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S args;
flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S args; end
(find_packages ());
(* TODO: Check if this is allowed for OCaml < 3.12.1 *)
flag ["ocaml"; "compile"; "package("^pkg^")"] & S pargs;
flag ["ocaml"; "ocamldep"; "package("^pkg^")"] & S pargs;
flag ["ocaml"; "doc"; "package("^pkg^")"] & S pargs;
flag ["ocaml"; "infer_interface"; "package("^pkg^")"] & S pargs;
end
(find_packages ());
end;
(* Like -package but for extensions syntax. Morover -syntax is useless (* Like -package but for extensions syntax. Morover -syntax is useless
* when linking. *) * when linking. *)
@ -441,10 +430,10 @@ module MyOCamlbuildBase = struct
module OC = Ocamlbuild_pack.Ocaml_compiler module OC = Ocamlbuild_pack.Ocaml_compiler
type dir = string type dir = string
type file = string type file = string
type name = string type name = string
type tag = string type tag = string
(* # 62 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *) (* # 62 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
@ -459,7 +448,7 @@ module MyOCamlbuildBase = struct
* directory. * directory.
*) *)
includes: (dir * dir list) list; includes: (dir * dir list) list;
} }
let env_filename = let env_filename =
@ -557,13 +546,12 @@ module MyOCamlbuildBase = struct
(* When ocaml link something that use the C library, then one (* When ocaml link something that use the C library, then one
need that file to be up to date. need that file to be up to date.
This holds both for programs and for libraries.
*) *)
dep ["link"; "ocaml"; tag_libstubs lib] dep ["link"; "ocaml"; "program"; tag_libstubs lib]
[dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)]; [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
dep ["compile"; "ocaml"; tag_libstubs lib] dep ["compile"; "ocaml"; "program"; tag_libstubs lib]
[dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)]; [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
(* TODO: be more specific about what depends on headers *) (* TODO: be more specific about what depends on headers *)
(* Depends on .h files *) (* Depends on .h files *)
@ -592,37 +580,30 @@ module MyOCamlbuildBase = struct
() ()
let dispatch_default conf t = let dispatch_default t =
dispatch_combine dispatch_combine
[ [
dispatch t; dispatch t;
MyOCamlbuildFindlib.dispatch conf; MyOCamlbuildFindlib.dispatch;
] ]
end end
# 606 "myocamlbuild.ml" # 594 "myocamlbuild.ml"
open Ocamlbuild_plugin;; open Ocamlbuild_plugin;;
let package_default = let package_default =
{ {
MyOCamlbuildBase.lib_ocaml = MyOCamlbuildBase.lib_ocaml = [("sequence", [], [])];
[
("sequence", [], []);
("invert", ["invert"], []);
("bigarray", ["bigarray"], [])
];
lib_c = []; lib_c = [];
flags = []; flags = [];
includes = [] includes = []
} }
;; ;;
let conf = {MyOCamlbuildFindlib.no_automatic_syntax = false} let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;
let dispatch_default = MyOCamlbuildBase.dispatch_default conf package_default;; # 608 "myocamlbuild.ml"
# 627 "myocamlbuild.ml"
(* OASIS_STOP *) (* OASIS_STOP *)
Ocamlbuild_plugin.dispatch dispatch_default;; Ocamlbuild_plugin.dispatch dispatch_default;;

View file

@ -40,7 +40,7 @@ let rec from_fun f k = match f () with
| None -> () | None -> ()
| Some x -> k x; from_fun f k | Some x -> k x; from_fun f k
let empty k = () let empty _ = ()
let singleton x k = k x let singleton x k = k x
let return x k = k x let return x k = k x
@ -152,10 +152,6 @@ module MList = struct
let of_seq seq = let of_seq seq =
of_seq_with seq (fun _ -> ()) of_seq_with seq (fun _ -> ())
let is_empty = function
| Nil -> true
| Cons _ -> false
let rec iter f l = match l with let rec iter f l = match l with
| Nil -> () | Nil -> ()
| Cons (a, n, tl) -> | Cons (a, n, tl) ->
@ -199,7 +195,7 @@ module MList = struct
cur := !tl; cur := !tl;
i := 0; i := 0;
get_next arg get_next arg
| Cons (a, n, _) -> | Cons (a, _, _) ->
let x = a.(!i) in let x = a.(!i) in
incr i; incr i;
Some x Some x
@ -214,7 +210,7 @@ module MList = struct
let rec make (l,i) () = match l with let rec make (l,i) () = match l with
| Nil -> `Nil | Nil -> `Nil
| Cons (_, n, tl) when i = !n -> make (!tl,0) () | Cons (_, n, tl) when i = !n -> make (!tl,0) ()
| Cons (a, n, _) -> `Cons (a.(i), make (l,i+1)) | Cons (a, _, _) -> `Cons (a.(i), make (l,i+1))
in make (l,0) in make (l,0)
end end
@ -411,7 +407,7 @@ let is_empty seq =
(** {2 Transform a sequence} *) (** {2 Transform a sequence} *)
let empty2 k = () let empty2 _ = ()
let is_empty2 seq2 = let is_empty2 seq2 =
try ignore (seq2 (fun _ _ -> raise ExitIsEmpty)); true try ignore (seq2 (fun _ _ -> raise ExitIsEmpty)); true
@ -525,9 +521,9 @@ let of_hashtbl h k = Hashtbl.iter (fun a b -> k (a, b)) h
let of_hashtbl2 h k = Hashtbl.iter k h let of_hashtbl2 h k = Hashtbl.iter k h
let hashtbl_keys h k = Hashtbl.iter (fun a b -> k a) h let hashtbl_keys h k = Hashtbl.iter (fun a _ -> k a) h
let hashtbl_values h k = Hashtbl.iter (fun a b -> k b) h let hashtbl_values h k = Hashtbl.iter (fun _ b -> k b) h
let of_str s k = String.iter k s let of_str s k = String.iter k s
@ -613,16 +609,16 @@ module Set = struct
end end
(** Create an enriched Set module from the given one *) (** Create an enriched Set module from the given one *)
module Adapt(X : Set.S) = struct module Adapt(X : Set.S) : S with type elt = X.elt and type t = X.t = struct
let to_seq set k = X.iter k set let to_seq set k = X.iter k set
let of_seq seq = fold (fun set x -> X.add x set) X.empty seq let of_seq seq = fold (fun set x -> X.add x set) X.empty seq
let of_list l = of_seq (of_list l)
let to_list set = to_list (to_seq set) let to_list set = to_list (to_seq set)
include X include X
let of_list l = List.fold_left (fun set x -> add x set) empty l
end end
(** Functor to build an extended Set module from an ordered type *) (** Functor to build an extended Set module from an ordered type *)

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,6 @@
open OUnit open OUnit
module S = Sequence module S = Sequence
open Sequence.Infix
let pp_ilist l = let pp_ilist l =
let b = Buffer.create 15 in let b = Buffer.create 15 in
@ -24,14 +23,14 @@ let test_repeat () =
() ()
let test_concat () = let test_concat () =
let s1 = (1 -- 5) in let s1 = S.(1 -- 5) in
let s2 = (6 -- 10) in let s2 = S.(6 -- 10) in
let l = [1;2;3;4;5;6;7;8;9;10] in let l = [1;2;3;4;5;6;7;8;9;10] in
OUnit.assert_equal l (S.to_list (S.append s1 s2)); OUnit.assert_equal l (S.to_list (S.append s1 s2));
() ()
let test_fold () = let test_fold () =
let n = (1 -- 10) let n = S.(1 -- 10)
|> S.fold (+) 0 in |> S.fold (+) 0 in
OUnit.assert_equal 55 n; OUnit.assert_equal 55 n;
() ()
@ -44,33 +43,33 @@ let test_foldi () =
() ()
let test_exists () = let test_exists () =
(1 -- 100) S.(1 -- 100)
|> S.exists (fun x -> x = 59) |> S.exists (fun x -> x = 59)
|> OUnit.assert_bool "exists"; |> OUnit.assert_bool "exists";
(1 -- 100) S.(1 -- 100)
|> S.exists (fun x -> x < 0) |> S.exists (fun x -> x < 0)
|> (fun x -> not x) |> (fun x -> not x)
|> OUnit.assert_bool "not exists"; |> OUnit.assert_bool "not exists";
() ()
let test_length () = let test_length () =
(1 -- 1000) |> S.length |> OUnit.assert_equal 1000 S.(1 -- 1000) |> S.length |> OUnit.assert_equal 1000
let test_concat () = let test_concat2 () =
1 -- 1000 S.(1 -- 1000)
|> S.map (fun i -> (i -- (i+1))) |> S.map (fun i -> S.(i -- (i+1)))
|> S.concat |> S.concat
|> S.length |> S.length
|> OUnit.assert_equal 2000 |> OUnit.assert_equal 2000
let test_flatMap () = let test_flatMap () =
1 -- 1000 S.(1 -- 1000)
|> S.flatMap (fun i -> (i -- (i+1))) |> S.flatMap (fun i -> S.(i -- (i+1)))
|> S.length |> S.length
|> OUnit.assert_equal 2000 |> OUnit.assert_equal 2000
let test_intersperse () = let test_intersperse () =
1 -- 100 S.(1 -- 100)
|> (fun seq -> S.intersperse 0 seq) |> (fun seq -> S.intersperse 0 seq)
|> S.take 10 |> S.take 10
|> S.to_list |> S.to_list
@ -98,7 +97,7 @@ let test_persistent () =
let test_big_persistent () = let test_big_persistent () =
let printer = pp_ilist in let printer = pp_ilist in
let seq = 0 -- 10_000 in let seq = S.(0 -- 10_000) in
let seq' = S.persistent seq in let seq' = S.persistent seq in
OUnit.assert_equal 10_001 (S.length seq'); OUnit.assert_equal 10_001 (S.length seq');
OUnit.assert_equal 10_001 (S.length seq'); OUnit.assert_equal 10_001 (S.length seq');
@ -106,7 +105,7 @@ let test_big_persistent () =
() ()
let test_sort () = let test_sort () =
1 -- 100 S.(1 -- 100)
|> S.sort ~cmp:(fun i j -> j - i) |> S.sort ~cmp:(fun i j -> j - i)
|> S.take 4 |> S.take 4
|> S.to_list |> S.to_list
@ -115,18 +114,18 @@ let test_sort () =
let test_sort_uniq () = let test_sort_uniq () =
[42;1;2;3;4;5;4;3;2;1] [42;1;2;3;4;5;4;3;2;1]
|> S.of_list |> S.of_list
|> S.sort_uniq |> S.sort_uniq ?cmp:None
|> S.to_list |> S.to_list
|> OUnit.assert_equal [1;2;3;4;5;42] |> OUnit.assert_equal [1;2;3;4;5;42]
let test_group () = let test_group () =
[1;2;3;3;2;2;3;4] [1;2;3;3;2;2;3;4]
|> S.of_list |> S.group |> S.to_list |> S.of_list |> S.group ?eq:None |> S.to_list
|> OUnit.assert_equal [[1];[2];[3;3];[2;2];[3];[4]] |> OUnit.assert_equal [[1];[2];[3;3];[2;2];[3];[4]]
let test_uniq () = let test_uniq () =
[1;2;2;3;4;4;4;3;3] [1;2;2;3;4;4;4;3;3]
|> S.of_list |> S.uniq |> S.to_list |> S.of_list |> S.uniq ?eq:None |> S.to_list
|> OUnit.assert_equal [1;2;3;4;3] |> OUnit.assert_equal [1;2;3;4;3]
let test_product () = let test_product () =
@ -140,7 +139,7 @@ let test_product () =
"c",0; "c", 1; "c", 2;] s "c",0; "c", 1; "c", 2;] s
let test_join () = let test_join () =
let s1 = (1 -- 3) in let s1 = S.(1 -- 3) in
let s2 = S.of_list ["1"; "2"] in let s2 = S.of_list ["1"; "2"] in
let join_row i j = let join_row i j =
if string_of_int i = j then Some (string_of_int i ^ " = " ^ j) else None if string_of_int i = j then Some (string_of_int i ^ " = " ^ j) else None
@ -150,16 +149,16 @@ let test_join () =
() ()
let test_scan () = let test_scan () =
1 -- 5 S.(1 -- 5)
|> S.scan (+) 0 |> S.scan (+) 0
|> S.to_list |> S.to_list
|> OUnit.assert_equal ~printer:pp_ilist [0;1;3;6;10;15] |> OUnit.assert_equal ~printer:pp_ilist [0;1;3;6;10;15]
let test_drop () = let test_drop () =
1 -- 5 |> S.drop 2 |> S.to_list |> OUnit.assert_equal [3;4;5] S.(1 -- 5) |> S.drop 2 |> S.to_list |> OUnit.assert_equal [3;4;5]
let test_rev () = let test_rev () =
1 -- 5 |> S.rev |> S.to_list |> OUnit.assert_equal [5;4;3;2;1] S.(1 -- 5) |> S.rev |> S.to_list |> OUnit.assert_equal [5;4;3;2;1]
let test_unfoldr () = let test_unfoldr () =
let f x = if x < 5 then Some (string_of_int x,x+1) else None in let f x = if x < 5 then Some (string_of_int x,x+1) else None in
@ -168,12 +167,12 @@ let test_unfoldr () =
|> OUnit.assert_equal ["0"; "1"; "2"; "3"; "4"] |> OUnit.assert_equal ["0"; "1"; "2"; "3"; "4"]
let test_hashtbl () = let test_hashtbl () =
let h = 1 -- 5 let h = S.(1 -- 5)
|> S.zip_i |> S.zip_i
|> S.to_hashtbl2 in |> S.to_hashtbl2 in
0 -- 4 S.(0 -- 4)
|> S.iter (fun i -> OUnit.assert_equal (i+1) (Hashtbl.find h i)); |> S.iter (fun i -> OUnit.assert_equal (i+1) (Hashtbl.find h i));
OUnit.assert_equal [0;1;2;3;4] (S.hashtbl_keys h |> S.sort |> S.to_list); OUnit.assert_equal [0;1;2;3;4] (S.hashtbl_keys h |> S.sort ?cmp:None |> S.to_list);
() ()
let test_buff () = let test_buff () =
@ -208,6 +207,7 @@ let suite =
[ "test_empty" >:: test_empty; [ "test_empty" >:: test_empty;
"test_repeat" >:: test_repeat; "test_repeat" >:: test_repeat;
"test_concat" >:: test_concat; "test_concat" >:: test_concat;
"test_concat2" >:: test_concat2;
"test_fold" >:: test_fold; "test_fold" >:: test_fold;
"test_foldi" >:: test_foldi; "test_foldi" >:: test_foldi;
"test_exists" >:: test_exists; "test_exists" >:: test_exists;
@ -231,5 +231,5 @@ let suite =
"test_hashtbl" >:: test_hashtbl; "test_hashtbl" >:: test_hashtbl;
"test_int_range" >:: test_int_range; "test_int_range" >:: test_int_range;
"test_take" >:: test_take; "test_take" >:: test_take;
"test_regression1" >:: test_regression1 "test_regression1" >:: test_regression1;
] ]