module Mock:This module provides support for mock functions, that record their calls.sig
..end
exception Unexpected_value of string
exception End_of_sequence
type ('a, 'b)
t
'a
to 'b
.val from_mapping : ?cmp:('a -> 'a -> int) ->
?prn:('a -> string) -> ('a * 'b) list -> ('a, 'b) t
from_mapping ~cmp ~prn l
returns a mock function based on the
association list l
whose couples are (input, output)
indicating
that the function should return output
when call with paramer
input
. cmp
(defaulting to Pervasives.compare
) is used to
compare input values), while prn
is used to convert input values
into strings.
Raises Unexpected_value
if the function received an input value
that do not appear in l
.
val from_sequence : ?cmp:('a -> 'a -> int) ->
?prn:('a -> string) -> ('a * 'b) list -> ('a, 'b) t
from_sequence ~cmp ~prn l
returns a mock function based on the
association list l
whose couples are (input_i, output_i)
indicating that the i
th call to the function should have parameter
input_i
and should return output_i
. cmp
(defaulting to
Pervasives.compare
) is used to compare input values), while prn
is used to convert input values into strings.
Raises Unexpected_value
if the function received as the i
th input
value a value that is different from fst (List.nth l i)
.
Raises End_of_sequence
if more than List.length l
calls.
val from_function : ?cmp:('a -> 'a -> int) -> ('a -> 'b) -> ('a, 'b) t
from_function ~cmp f
returns a mock function based on the
function f
, only recording calls actually made to the function.
cmp
(defaulting to Pervasives.compare
) is used to compare input
values).
f
should raise Unexpected_value
if presented an input value it
cannot handle.
val func : ('a, 'b) t -> 'a -> 'b
val func2 : ('a1 * 'a2, 'b) t -> 'a1 -> 'a2 -> 'b
val func3 : ('a1 * 'a2 * 'a3, 'b) t -> 'a1 -> 'a2 -> 'a3 -> 'b
val func4 : ('a1 * 'a2 * 'a3 * 'a4, 'b) t -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'b
val func5 : ('a1 * 'a2 * 'a3 * 'a4 * 'a5, 'b) t ->
'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'b
val count : ('a, 'b) t -> 'a -> int
count f x
returns how many time the function f
has been called
with a parameter value equal to x
.val total : ('a, 'b) t -> int
f
has been called.val calls : ('a, 'b) t -> 'a list