2 using System.Collections.Generic;
10 static MText mt = new MText ("0123456789");
11 static MSymbol key = MSymbol.PropertyKey ("___");
12 static MSymbol key_r = MSymbol.PropertyKey ("r__",
13 MProperty.Flags.RearSticky);
14 static MSymbol key_f = MSymbol.PropertyKey ("_f_",
15 MProperty.Flags.FrontSticky);
16 static MSymbol key_rf = MSymbol.PropertyKey ("rf_",
17 (MProperty.Flags.RearSticky
18 | MProperty.Flags.FrontSticky));
19 static MSymbol key_s = MSymbol.PropertyKey ("__s",
20 MProperty.Flags.Sensitive);
21 static MSymbol key_rs = MSymbol.PropertyKey ("r_s",
22 (MProperty.Flags.RearSticky
23 | MProperty.Flags.Sensitive));
24 static MSymbol key_fs = MSymbol.PropertyKey ("_fs",
25 (MProperty.Flags.FrontSticky
26 | MProperty.Flags.Sensitive));
27 static MSymbol key_rfs = MSymbol.PropertyKey ("rfs",
28 (MProperty.Flags.RearSticky
29 | MProperty.Flags.FrontSticky
30 | MProperty.Flags.Sensitive));
32 static MSymbol val0 = MSymbol.Of ("0");
33 static MSymbol val1 = MSymbol.Of ("1");
34 static MSymbol val2 = MSymbol.Of ("2");
35 static MProperty prop0 = new MProperty (key, val0);
36 static MProperty prop1 = new MProperty (key, val1);
37 static MProperty prop2 = new MProperty (key, val2);
39 static int[] nvals = new int[LENGTH];
40 static MSymbol[,] valtable = new MSymbol[LENGTH, DEPTH + 1];
42 static void TestPushProp (int from, int to, MSymbol key, MSymbol val)
44 for (int i = from; i < to; i++)
45 if (nvals[i] == DEPTH)
48 for (int i = from; i < to; i++)
50 valtable[i, nvals[i]] = val;
53 Console.WriteLine ("from {0}, to {1}, push {2}, {3}.\n",
56 mt.PushProp (from, to, key, val);
59 static void TestPushProp (int from, int to, MProperty prop)
61 for (int i = from; i < to; i++)
62 if (nvals[i] == DEPTH)
65 for (int i = from; i < to; i++)
67 valtable[i, nvals[i]] = (MSymbol) prop.Val;
70 Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop);
72 mt.PushProp (from, to, prop);
75 static void TestPopProp (int from, int to, MSymbol key)
77 for (int i = from; i < to; i++)
80 valtable[i, nvals[i] - 1] = null;
83 Console.WriteLine ("from {0}, to {1}, pop.\n", from, to);
85 mt.PopProp (from, to, key);
88 static void TestDelIns (int from, int to, int from2)
90 int i, j, l = to - from;
91 int[] nvals2 = new int[LENGTH];
92 MSymbol[,] valtable2 = new MSymbol[LENGTH, DEPTH + 1];
95 for (i = from; i < to; i++)
97 nvals2[i - from] = nvals[i];
98 for (j = 0; j < nvals[i]; j++)
99 valtable2[i - from, j] = valtable[i, j];
103 for (i = to; i < LENGTH; i++)
105 nvals[i - l] = nvals[i];
106 for (j = 0; j < nvals[i]; j++)
107 valtable[i - l, j] = valtable[i, j];
111 for (i = LENGTH - 1; i >= from2 + l; i--)
113 nvals[i] = nvals[i - l];
114 for (j = 0; j < nvals[i]; j++)
115 valtable[i, j] = valtable[i - l, j];
119 for (i = from2; i < from2 + l; i++)
121 nvals[i] = nvals2[i - from2];
122 for (j = 0; j < nvals[i]; j++)
123 valtable[i, j] = valtable2[i - from2, j];
125 Console.WriteLine ("from {0}, to {1}, moveto {2}.\n", from, to, from2);
127 MText mt2 = mt.Dup ();
129 mt.Ins (from2, mt2, from, to);
132 static bool Compare ()
134 for (int i = 0; i < LENGTH; i++)
137 object val = mt.GetProp (i, key, out array);
143 Console.WriteLine ("nvals[{0}] is {1}, array.Length is null.\n",
149 else if (nvals[i] != array.Length)
151 Console.WriteLine ("nvals[{0}] is {1}, array.Length is {2}.\n",
152 i, nvals[i], array.Length);
158 for (int j = 0; j < nvals[i]; j++)
159 if (valtable[i, nvals[i] - 1 - j] != (MSymbol) array[j].Val)
161 Console.WriteLine ("valtable[{0}, {1}] is {2}, array[{1}] is {3}.\n",
162 i, j, valtable[i, j], array[j]);
171 Console.WriteLine ("GetProp returned null for index {0}.\n",
181 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
186 else if (valtable[i, nvals[i] - 1] == null)
188 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
193 else if ((MSymbol) val != valtable[i, nvals[i] - 1])
195 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
206 for (int i = 0; i < LENGTH; i++)
208 Console.Write (i + " ");
209 for (int j = nvals[i] - 1; j >= 0; j--)
210 Console.Write (valtable[i,j] + " ");
211 Console.WriteLine (":");
213 Console.WriteLine ("");
216 public static void Main (string[] args)
218 Random r = new Random (int.Parse (args[0]));
219 int check = (args.Length > 1 ? int.Parse (args[1]) : 0xFFFFFFF);
221 for (int loop = 0; loop < 1000000; loop++)
223 Console.WriteLine ("--- loop = {0} ---\n", loop);
226 mt.DumpPropNested ();
231 int from = r.Next (LENGTH);
232 int to = r.Next (LENGTH + 1);
241 //MSymbol val = r.Next (2) == 0 ? val0 : val1;
256 //MProperty prop = r.Next (2) == 0 ? prop0 : prop1;
273 TestPushProp (from, to, key, val);
276 TestPushProp (from, to, prop);
279 TestPopProp (from, to, key);
282 TestDelIns (from, to, r.Next (LENGTH - (to - from) + 1));
287 mt.DumpPropNested ();
289 if (Compare () == false)
291 Console.WriteLine ("");
293 Console.WriteLine ("Failed.");