File: test_Dllist.ml

package info (click to toggle)
extlib 1.7.7-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 632 kB
  • sloc: ml: 6,980; makefile: 128; sh: 42; ansic: 31
file content (63 lines) | stat: -rw-r--r-- 2,267 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(*
 * ExtLib Testing Suite
 * Copyright (C) 2004 Janne Hellsten
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version,
 * with the special exception on linking described in file LICENSE.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *)

let test_simple () = 
  for i = 1 to 5 do
    let rec make_lst accu n = 
      if n < i then make_lst (i::accu) (n+1)
      else accu in
    let lst = make_lst [] 0 in
    let dlst = Dllist.of_list lst in
    assert (List.length lst = Dllist.length dlst);
    List.iter 
      (fun e -> 
         let dl_elem = Dllist.get dlst in
         assert (e = dl_elem);
         Dllist.remove dlst) lst;
  done

(* Failure case reported by Christopher Wedman on extlib mailing list 2005/Feb/12.  *)
let test_regression_1 () = 
  let lst = Dllist.create 1 in
  ignore (Dllist.append lst 2);
  ignore (Dllist.demote lst);
  ignore (Dllist.length lst) (* <-- hangs here *)

(* Failure case reported by Christopher Wedman on extlib mailing list 2005/Feb/12.  *)
let test_regression_2 () = 
  let lst = Dllist.create 1 in
  ignore (Dllist.append lst 2);
  ignore (Dllist.promote lst);
  assert (Dllist.length lst = 2)  (* returned 1, but should return 2 *)

let skip_both_ways () =
  let lst = Dllist.create "left" in
  ignore (Dllist.add lst "right");
  let lm = Dllist.append lst "middle" in
  assert (Dllist.get (Dllist.skip lm 1) = "right");
  assert (Dllist.get (Dllist.skip lm (-1)) = "left") (* returned right *)

let () = 
  Util.register "Dllist" [
    "simple", test_simple;
    "regression_1", test_regression_1;
    "regression_2", test_regression_2;
    "skip_both_ways", skip_both_ways;
  ]