package ounit2

  1. Overview
  2. Docs
OUnit testing framework

Install

Dune Dependency

Authors

Maintainers

Sources

ounit-2.2.7.tbz
sha256=90f6e63bd1240a51d8b9b2f722059bd79ce00b5276bdd6238b8f5c613c0e7388
sha512=53463e5b1b5a40f424e19f5f6a86338a544079600d1fd121ffc1a6fcaa239630194018faf91ccf360ba40b1b2a8b01cf491935e014c68d2947f6e027a2f0a0f9

doc/ounit2.advanced/OUnitDiff/index.html

Module OUnitDiffSource

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

Sourcemodule type DIFF_ELEMENT = sig ... end

Definition of an element

Sourcemodule type S = sig ... end

Definition of standard operations

Implementations

Sourcemodule SetMake (D : DIFF_ELEMENT) : S with type e = D.t

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

Sourcemodule ListSimpleMake (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.

Sourceval pp_comma_separator : Format.formatter -> unit -> unit
Sourcemodule EString : DIFF_ELEMENT with type t = string
Sourcemodule EInt : DIFF_ELEMENT with type t = int
OCaml

Innovation. Community. Security.