mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 11:45:31 -05:00
more tests
This commit is contained in:
parent
4b4764f3bf
commit
f77172ee26
2 changed files with 22 additions and 1 deletions
|
|
@ -108,6 +108,11 @@ let peek_front d = match d.cur.cell with
|
||||||
| Two (x,_) -> x
|
| Two (x,_) -> x
|
||||||
| Three (x,_,_) -> x
|
| Three (x,_,_) -> x
|
||||||
|
|
||||||
|
(*$T
|
||||||
|
of_list [1;2;3] |> peek_front = 1
|
||||||
|
try (ignore (of_list [] |> peek_front); false) with Empty -> true
|
||||||
|
*)
|
||||||
|
|
||||||
let peek_back d =
|
let peek_back d =
|
||||||
if is_empty d then raise Empty
|
if is_empty d then raise Empty
|
||||||
else match d.cur.prev.cell with
|
else match d.cur.prev.cell with
|
||||||
|
|
@ -116,6 +121,11 @@ let peek_back d =
|
||||||
| Two (_,x) -> x
|
| Two (_,x) -> x
|
||||||
| Three (_,_,x) -> x
|
| Three (_,_,x) -> x
|
||||||
|
|
||||||
|
(*$T
|
||||||
|
of_list [1;2;3] |> peek_back = 3
|
||||||
|
try (ignore (of_list [] |> peek_back); false) with Empty -> true
|
||||||
|
*)
|
||||||
|
|
||||||
let take_back_node_ n = match n.cell with
|
let take_back_node_ n = match n.cell with
|
||||||
| Zero -> assert false
|
| Zero -> assert false
|
||||||
| One x -> n.cell <- Zero; x
|
| One x -> n.cell <- Zero; x
|
||||||
|
|
@ -141,12 +151,20 @@ let take_back d =
|
||||||
x
|
x
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(*$T
|
||||||
|
let q = of_list [1;2;3] in take_back q = 3 && to_list q = [1;2]
|
||||||
|
*)
|
||||||
|
|
||||||
let take_front_node_ n = match n.cell with
|
let take_front_node_ n = match n.cell with
|
||||||
| Zero -> assert false
|
| Zero -> assert false
|
||||||
| One x -> n.cell <- Zero; x
|
| One x -> n.cell <- Zero; x
|
||||||
| Two (x,y) -> n.cell <- One y; x
|
| Two (x,y) -> n.cell <- One y; x
|
||||||
| Three (x,y,z) -> n.cell <- Two (y,z); x
|
| Three (x,y,z) -> n.cell <- Two (y,z); x
|
||||||
|
|
||||||
|
(*$T
|
||||||
|
let q = of_list [1;2;3] in take_front q = 1 && to_list q = [2;3]
|
||||||
|
*)
|
||||||
|
|
||||||
let take_front d =
|
let take_front d =
|
||||||
if is_empty d then raise Empty
|
if is_empty d then raise Empty
|
||||||
else if d.cur.prev == d.cur
|
else if d.cur.prev == d.cur
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,8 @@ val compare : ?cmp:('a -> 'a -> int) -> 'a t -> 'a t -> int
|
||||||
@since NEXT_RELEASE *)
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val length : 'a t -> int
|
val length : 'a t -> int
|
||||||
(** Number of elements (linear) *)
|
(** Number of elements
|
||||||
|
used to be linear time, now constant time *)
|
||||||
|
|
||||||
val push_front : 'a t -> 'a -> unit
|
val push_front : 'a t -> 'a -> unit
|
||||||
(** Push value at the front *)
|
(** Push value at the front *)
|
||||||
|
|
@ -130,6 +131,8 @@ val to_rev_list : 'a t -> 'a list
|
||||||
(** Efficient conversion to list, in reverse order
|
(** Efficient conversion to list, in reverse order
|
||||||
@since NEXT_RELEASE *)
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
(** {2 print} *)
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
val print : 'a printer -> 'a t printer
|
val print : 'a printer -> 'a t printer
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue