123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227(**************************************************************************)(* The OUnit library *)(* *)(* Copyright (C) 2002-2008 Maas-Maarten Zeeman. *)(* Copyright (C) 2010 OCamlCore SARL *)(* Copyright (C) 2013 Sylvain Le Gall *)(* *)(* The package OUnit is copyright by Maas-Maarten Zeeman, OCamlCore SARL *)(* and Sylvain Le Gall. *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining *)(* a copy of this document and the OUnit software ("the Software"), to *)(* deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, *)(* sublicense, and/or sell copies of the Software, and to permit persons *)(* to whom the Software is furnished to do so, subject to the following *)(* conditions: *)(* *)(* The above copyright notice and this permission notice shall be *)(* included in all copies or substantial portions of the Software. *)(* *)(* The Software is provided ``as is'', without warranty of any kind, *)(* express or implied, including but not limited to the warranties of *)(* merchantability, fitness for a particular purpose and noninfringement. *)(* In no event shall Maas-Maarten Zeeman be liable for any claim, damages *)(* or other liability, whether in an action of contract, tort or *)(* otherwise, arising from, out of or in connection with the Software or *)(* the use or other dealings in the software. *)(* *)(* See LICENSE.txt for details. *)(**************************************************************************)openFormatmoduletypeDIFF_ELEMENT=sigtypetvalpp_printer:Format.formatter->t->unitvalcompare:t->t->intvalpp_print_sep:Format.formatter->unit->unitendmoduletypeS=sigtypeetypetvalcompare:t->t->intvalpp_printer:Format.formatter->t->unitvalpp_diff:Format.formatter->(t*t)->unitvalassert_equal:?msg:string->t->t->unitvalof_list:elist->tendletassert_equal?msgcomparepp_printerpp_diffexpact=OUnitAssert.assert_equal~cmp:(funt1t2->(comparet1t2)=0)~printer:(funt->letbuff=Buffer.create13inletfmt=formatter_of_bufferbuffinpp_printerfmtt;pp_print_flushfmt();Buffer.contentsbuff)~pp_diff?msgexpactmoduleSetMake(D:DIFF_ELEMENT):Swithtypee=D.t=structmoduleSet=Set.Make(D)typee=D.ttypet=Set.tletcompare=Set.compareletpp_printerfmtt=letfirst=reftrueinpp_open_boxfmt0;Set.iter(fune->ifnot!firstthenD.pp_print_sepfmt();D.pp_printerfmte;first:=false)t;pp_close_boxfmt()letpp_difffmt(t1,t2)=letfirst=reftrueinletprint_listct=Set.iter(fune->ifnot!firstthenD.pp_print_sepfmt();pp_print_charfmtc;D.pp_printerfmte;first:=false)tinpp_open_boxfmt0;print_list'+'(Set.difft2t1);print_list'-'(Set.difft1t2);pp_close_boxfmt()letassert_equal?msgexpact=assert_equal?msgcomparepp_printerpp_diffexpactletof_listlst=List.fold_left(funacce->Set.addeacc)Set.emptylstendmoduleListSimpleMake(D:DIFF_ELEMENT):Swithtypee=D.tandtypet=D.tlist=structtypee=D.ttypet=elistletreccomparet1t2=matcht1,t2with|e1::tl1,e2::tl2->beginmatchD.comparee1e2with|0->comparetl1tl2|n->nend|[],[]->0|_,[]->-1|[],_->1letpp_print_genprefmtt=letfirst=reftrueinpp_open_boxfmt0;List.iter(fune->ifnot!firstthenD.pp_print_sepfmt();fprintffmt"%s%a"preD.pp_printere;first:=false)t;pp_close_boxfmt()letpp_printerfmtt=pp_print_gen""fmttletpp_difffmt(t1,t2)=letrecpp_diff'nt1t2=matcht1,t2with|e1::tl1,e2::tl2->beginmatchD.comparee1e2with|0->pp_diff'(n+1)tl1tl2|_->fprintffmt"element number %d differ (%a <> %a)"nD.pp_printere1D.pp_printere2end|[],[]->()|[],lst->fprintffmt"at end,@ ";pp_print_gen"+"fmtlst|lst,[]->fprintffmt"at end,@ ";pp_print_gen"-"fmtlstinpp_open_boxfmt0;pp_diff'0t1t2;pp_close_boxfmt()letassert_equal?msgexpact=assert_equal?msgcomparepp_printerpp_diffexpactletof_listlst=lstendletpp_comma_separatorfmt()=fprintffmt",@ "moduleEString=structtypet=stringletcompare=String.compareletpp_printer=Format.pp_print_stringletpp_print_sep=pp_comma_separatorendmoduleEInt=structtypet=intletcompare=(-)letpp_printer=Format.pp_print_intletpp_print_sep=pp_comma_separatorend