Blame test/test_Dllist.ml

rpm-build 0f2925
(*
rpm-build 0f2925
 * ExtLib Testing Suite
rpm-build 0f2925
 * Copyright (C) 2004 Janne Hellsten
rpm-build 0f2925
 *
rpm-build 0f2925
 * This library is free software; you can redistribute it and/or
rpm-build 0f2925
 * modify it under the terms of the GNU Lesser General Public
rpm-build 0f2925
 * License as published by the Free Software Foundation; either
rpm-build 0f2925
 * version 2.1 of the License, or (at your option) any later version,
rpm-build 0f2925
 * with the special exception on linking described in file LICENSE.
rpm-build 0f2925
 *
rpm-build 0f2925
 * This library is distributed in the hope that it will be useful,
rpm-build 0f2925
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 0f2925
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 0f2925
 * Lesser General Public License for more details.
rpm-build 0f2925
 *
rpm-build 0f2925
 * You should have received a copy of the GNU Lesser General Public
rpm-build 0f2925
 * License along with this library; if not, write to the Free Software
rpm-build 0f2925
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
rpm-build 0f2925
 *)
rpm-build 0f2925
rpm-build 0f2925
let test_simple () = 
rpm-build 0f2925
  for i = 1 to 5 do
rpm-build 0f2925
    let rec make_lst accu n = 
rpm-build 0f2925
      if n < i then make_lst (i::accu) (n+1)
rpm-build 0f2925
      else accu in
rpm-build 0f2925
    let lst = make_lst [] 0 in
rpm-build 0f2925
    let dlst = Dllist.of_list lst in
rpm-build 0f2925
    assert (List.length lst = Dllist.length dlst);
rpm-build 0f2925
    List.iter 
rpm-build 0f2925
      (fun e -> 
rpm-build 0f2925
         let dl_elem = Dllist.get dlst in
rpm-build 0f2925
         assert (e = dl_elem);
rpm-build 0f2925
         Dllist.remove dlst) lst;
rpm-build 0f2925
  done
rpm-build 0f2925
rpm-build 0f2925
(* Failure case reported by Christopher Wedman on extlib mailing list 2005/Feb/12.  *)
rpm-build 0f2925
let test_regression_1 () = 
rpm-build 0f2925
  let lst = Dllist.create 1 in
rpm-build 0f2925
  ignore (Dllist.append lst 2);
rpm-build 0f2925
  ignore (Dllist.demote lst);
rpm-build 0f2925
  ignore (Dllist.length lst) (* <-- hangs here *)
rpm-build 0f2925
rpm-build 0f2925
(* Failure case reported by Christopher Wedman on extlib mailing list 2005/Feb/12.  *)
rpm-build 0f2925
let test_regression_2 () = 
rpm-build 0f2925
  let lst = Dllist.create 1 in
rpm-build 0f2925
  ignore (Dllist.append lst 2);
rpm-build 0f2925
  ignore (Dllist.promote lst);
rpm-build 0f2925
  assert (Dllist.length lst = 2)  (* returned 1, but should return 2 *)
rpm-build 0f2925
rpm-build 0f2925
let () = 
rpm-build 0f2925
  Util.register "Dllist" [
rpm-build 0f2925
    "simple", test_simple;
rpm-build 0f2925
    "regression_1", test_regression_1;
rpm-build 0f2925
    "regression_2", test_regression_2;
rpm-build 0f2925
  ]