Import Upstream version 20180207
[hcoop/debian/mlton.git] / lib / mlton / queue / test.sml
CommitLineData
7f918cf1
CE
1(* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 *
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
6 *)
7
8structure Q = QueueLogarithmicExplicit();
9fun p q = Q.output(q, ", ", Int.output, Out.standard);
10let val q = ref(Q.empty())
11in Iterate.for(1, 20, fn n =>
12 (p(!q) ;
13 Out.newline Out.standard ;
14 q := Q.enqueue(!q,n)))
15end
16
17
18structure Q = QueuePersistentTwoList
19
20structure Q = Queue(QueuePersistentOrderOne())
21
22
23val q = Q.empty(): int Q.t
24
25Q.destruct q
26
27Q.dequeue q
28
29val q = Q.enqueue(Q.enqueue(q, 1), 2)
30
31val (one, q') = Q.dequeue q
32
33val (two, q'') = Q.dequeue q'
34
35 Q.isEmpty q;
36 Q.isEmpty q';
37 Q.isEmpty q''
38
39local
40 functor Test = QueueTest (structure ListUtil = ListUtil)
41 (structure Queue = QueuePersistentList) ;
42
43 structure Ephemeral = Test(structure Queue' = QueueEphemeral)
44 structure PersistentTwoList = Test(structure Queue' = QueuePersistentTwoList)
45 structure OrderOne = Test(structure Queue' = QueuePersistentOrderOne)
46
47 val numOps = 1000
48in
49 val _ = (Ephemeral.test numOps ;
50 PersistentTwoList.test numOps ;
51 OrderOne.test numOps)
52end