Up

module OUnitDiff

: sig

Unit tests for collection of elements

This module allows to define a more precise way to display differences between collection of elements. When collection differ, the tester is interested by what are the missing/extra elements. This module provides a diff operation to spot the difference quickly between two sets of elements.

Example:

open OUnit;;

module EInt =
struct
  type t = int
  let compare = ( - )
  let pp_printer = Format.pp_print_int
  let pp_print_sep = OUnitDiff.pp_comma_separator
end

module ListInt = OUnitDiff.ListSimpleMake(EInt);;

let test_diff () =
  ListInt.assert_equal
    [1; 2; 3; 4; 5]
    [1; 2; 5; 4]
;;

let _ =
  run_test_tt_main ("test_diff" >:: test_diff)
;;

when run this test outputs:

OUnit: expected: 1, 2, 3, 4, 5 but got: 1, 2, 5, 4
differences: element number 2 differ (3 <> 5)
Since 1.1.0
Author Sylvain Le Gall

Signatures

#
module type DIFF_ELEMENT = sig

Definition of an element

#
type t

Type of an element

#
val pp_printer : Format.formatter -> t -> unit

Pretty printer for an element

#
val compare : t -> t -> int

Element comparison

#
val pp_print_sep : Format.formatter -> unit -> unit

Pretty print element separator

end
#
module type S = sig

Definition of standard operations

#
type e

Type of an element

#
type t

Type of a collection of element

#
val compare : t -> t -> int

Compare a collection of element

#
val pp_printer : Format.formatter -> t -> unit

Pretty printer a collection of element

#
val pp_diff : Format.formatter -> t * t -> unit

Pretty printer for collection differences

#
val assert_equal : ?msg:string -> t -> t -> unit

assert_equal with ~diff, ~cmp and ~printer predefined for this collection events

#
val of_list : e list -> t

Create t using of list

end

Implementations

#
module SetMake : functor (D : DIFF_ELEMENT) -> S with type e = D.t

Collection of elements based on a Set, elements order doesn't matter

#
module ListSimpleMake : functor (D : DIFF_ELEMENT) -> S with type e = D.t and type t = D.t list

Collection of elements based on a List, order matters but difference display is very simple. It stops at the first element which differs.

#
val pp_comma_separator : Format.formatter -> unit -> unit
end