2 using System.Collections.Generic;
10 static MText mt = new MText ("0123456789");
11 static MSymbol key = MSymbol.PropertyKey ("fst", MProperty.Flags.FrontSticky);
12 static MSymbol val0 = MSymbol.Of ("0");
13 static MSymbol val1 = MSymbol.Of ("1");
14 static MSymbol val2 = MSymbol.Of ("2");
15 static MProperty prop0 = new MProperty (key, val0);
16 static MProperty prop1 = new MProperty (key, val1);
17 static MProperty prop2 = new MProperty (key, val2);
19 static int[] nvals = new int[LENGTH];
20 static MSymbol[,] valtable = new MSymbol[LENGTH, DEPTH + 1];
22 static void TestPushProp (int from, int to, MProperty prop)
24 for (int i = from; i < to; i++)
25 if (nvals[i] == DEPTH)
28 for (int i = from; i < to; i++)
30 valtable[i, nvals[i]] = (MSymbol) prop.Val;
33 Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop);
35 mt.PushProp (from, to, prop);
38 static void TestPopProp (int from, int to, MSymbol key)
40 for (int i = from; i < to; i++)
43 valtable[i, nvals[i] - 1] = null;
46 Console.WriteLine ("from {0}, to {1}, pop.\n", from, to);
48 mt.PopProp (from, to, key);
51 static void TestDelIns (int from, int to, int from2)
53 int i, j, l = to - from;
54 int[] nvals2 = new int[LENGTH];
55 MSymbol[,] valtable2 = new MSymbol[LENGTH, DEPTH + 1];
58 for (i = from; i < to; i++)
60 nvals2[i - from] = nvals[i];
61 for (j = 0; j < nvals[i]; j++)
62 valtable2[i - from, j] = valtable[i, j];
66 for (i = to; i < LENGTH; i++)
68 nvals[i - l] = nvals[i];
69 for (j = 0; j < nvals[i]; j++)
70 valtable[i - l, j] = valtable[i, j];
74 for (i = LENGTH - 1; i >= from2 + l; i--)
76 nvals[i] = nvals[i - l];
77 for (j = 0; j < nvals[i]; j++)
78 valtable[i, j] = valtable[i - l, j];
82 for (i = from2; i < from2 + l; i++)
84 if (from2 + l == LENGTH || nvals[from2 + l] == 0)
86 nvals[i] = nvals2[i - from2];
87 for (j = 0; j < nvals[i]; j++)
88 valtable[i, j] = valtable2[i - from2, j];
92 nvals[i] = nvals[from2 + l];
93 for (j = 0; j < nvals[i]; j++)
94 valtable[i, j] = valtable[from2 + l, j];
97 Console.WriteLine ("from {0}, to {1}, moveto {2}.\n", from, to, from2);
99 MText mt2 = mt.Dup ();
101 mt.Ins (from2, mt2, from, to);
104 static bool Compare ()
106 for (int i = 0; i < LENGTH; i++)
109 object val = mt.GetProp (i, key, out array);
115 Console.WriteLine ("nvals[{0}] is {1}, array.Length is null.\n",
121 else if (nvals[i] != array.Length)
123 Console.WriteLine ("nvals[{0}] is {1}, array.Length is {2}.\n",
124 i, nvals[i], array.Length);
130 for (int j = 0; j < nvals[i]; j++)
131 if (valtable[i, nvals[i] - 1 - j] != (MSymbol) array[j].Val)
133 Console.WriteLine ("valtable[{0}, {1}] is {2}, array[{1}] is {3}.\n",
134 i, j, valtable[i, j], array[j]);
143 Console.WriteLine ("GetProp returned null for index {0}.\n",
153 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
158 else if (valtable[i, nvals[i] - 1] == null)
160 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
165 else if ((MSymbol) val != valtable[i, nvals[i] - 1])
167 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
178 for (int i = 0; i < LENGTH; i++)
180 Console.Write (i + " ");
181 for (int j = nvals[i] - 1; j >= 0; j--)
182 Console.Write (valtable[i,j] + " ");
183 Console.WriteLine (":");
185 Console.WriteLine ("");
188 public static void Main (string[] args)
190 Random r = new Random (int.Parse (args[0]));
191 int check = (args.Length > 1 ? int.Parse (args[1]) : 0xFFFFFFF);
193 for (int loop = 0; loop < 1000000; loop++)
195 Console.WriteLine ("--- loop = {0} ---\n", loop);
198 mt.DumpPropNested ();
203 int from = r.Next (LENGTH);
204 int to = r.Next (LENGTH + 1);
229 TestPushProp (from, to, prop);
232 TestPopProp (from, to, key);
235 TestDelIns (from, to, r.Next (LENGTH - (to - from) + 1));
240 mt.DumpPropNested ();
242 if (Compare () == false)
244 Console.WriteLine ("");
246 Console.WriteLine ("Failed.");