more tests

This commit is contained in:
Simon Cruanes 2015-08-31 18:37:38 +02:00
parent 4b4764f3bf
commit f77172ee26
2 changed files with 22 additions and 1 deletions

View file

@ -108,6 +108,11 @@ let peek_front d = match d.cur.cell with
| Two (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 =
if is_empty d then raise Empty
else match d.cur.prev.cell with
@ -116,6 +121,11 @@ let peek_back d =
| Two (_,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
| Zero -> assert false
| One x -> n.cell <- Zero; x
@ -141,12 +151,20 @@ let take_back d =
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
| Zero -> assert false
| One x -> n.cell <- Zero; x
| Two (x,y) -> n.cell <- One y; 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 =
if is_empty d then raise Empty
else if d.cur.prev == d.cur

View file

@ -48,7 +48,8 @@ val compare : ?cmp:('a -> 'a -> int) -> 'a t -> 'a t -> int
@since NEXT_RELEASE *)
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
(** Push value at the front *)
@ -130,6 +131,8 @@ val to_rev_list : 'a t -> 'a list
(** Efficient conversion to list, in reverse order
@since NEXT_RELEASE *)
(** {2 print} *)
type 'a printer = Format.formatter -> 'a -> unit
val print : 'a printer -> 'a t printer