2 using System.Collections.Generic;
10 static MText mt = new MText ("0123456789");
11 static MSymbol key = MSymbol.PropertyKey ("___");
13 static MSymbol key_r = MSymbol.PropertyKey ("r__",
14 MProperty.Flags.RearSticky);
15 static MSymbol key_f = MSymbol.PropertyKey ("_f_",
16 MProperty.Flags.FrontSticky);
17 static MSymbol key_rf = MSymbol.PropertyKey ("rf_",
18 (MProperty.Flags.RearSticky
19 | MProperty.Flags.FrontSticky));
20 static MSymbol key_s = MSymbol.PropertyKey ("__s",
21 MProperty.Flags.Sensitive);
22 static MSymbol key_rs = MSymbol.PropertyKey ("r_s",
23 (MProperty.Flags.RearSticky
24 | MProperty.Flags.Sensitive));
25 static MSymbol key_fs = MSymbol.PropertyKey ("_fs",
26 (MProperty.Flags.FrontSticky
27 | MProperty.Flags.Sensitive));
28 static MSymbol key_rfs = MSymbol.PropertyKey ("rfs",
29 (MProperty.Flags.RearSticky
30 | MProperty.Flags.FrontSticky
31 | MProperty.Flags.Sensitive));
34 static MSymbol val0 = MSymbol.Of ("0");
35 static MSymbol val1 = MSymbol.Of ("1");
36 static MSymbol val2 = MSymbol.Of ("2");
37 static MProperty prop0 = new MProperty (key, val0);
38 static MProperty prop1 = new MProperty (key, val1);
39 static MProperty prop2 = new MProperty (key, val2);
41 static int[] nvals = new int[LENGTH];
42 static MSymbol[,] valtable = new MSymbol[LENGTH, DEPTH + 1];
44 static void TestPushProp (int from, int to, MSymbol key, MSymbol val)
46 for (int i = from; i < to; i++)
47 if (nvals[i] == DEPTH)
50 for (int i = from; i < to; i++)
52 valtable[i, nvals[i]] = val;
55 Console.WriteLine ("from {0}, to {1}, push {2}, {3}.\n",
58 mt.PushProp (from, to, key, val);
61 static void TestPushProp (int from, int to, MProperty prop)
63 for (int i = from; i < to; i++)
64 if (nvals[i] == DEPTH)
67 for (int i = from; i < to; i++)
69 valtable[i, nvals[i]] = (MSymbol) prop.Val;
72 Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop);
74 mt.PushProp (from, to, prop);
77 static void TestPopProp (int from, int to, MSymbol key)
79 for (int i = from; i < to; i++)
82 valtable[i, nvals[i] - 1] = null;
85 Console.WriteLine ("from {0}, to {1}, pop.\n", from, to);
87 mt.PopProp (from, to, key);
90 static void TestDelIns (int from, int to, int from2)
92 int i, j, l = to - from;
93 int[] nvals2 = new int[LENGTH];
94 MSymbol[,] valtable2 = new MSymbol[LENGTH, DEPTH + 1];
97 for (i = from; i < to; i++)
99 nvals2[i - from] = nvals[i];
100 for (j = 0; j < nvals[i]; j++)
101 valtable2[i - from, j] = valtable[i, j];
105 for (i = to; i < LENGTH; i++)
107 nvals[i - l] = nvals[i];
108 for (j = 0; j < nvals[i]; j++)
109 valtable[i - l, j] = valtable[i, j];
113 for (i = LENGTH - 1; i >= from2 + l; i--)
115 nvals[i] = nvals[i - l];
116 for (j = 0; j < nvals[i]; j++)
117 valtable[i, j] = valtable[i - l, j];
121 for (i = from2; i < from2 + l; i++)
123 nvals[i] = nvals2[i - from2];
124 for (j = 0; j < nvals[i]; j++)
125 valtable[i, j] = valtable2[i - from2, j];
127 Console.WriteLine ("from {0}, to {1}, moveto {2}.\n", from, to, from2);
129 MText mt2 = mt.Dup ();
131 mt.Ins (from2, mt2, from, to);
134 static bool Compare ()
136 for (int i = 0; i < LENGTH; i++)
139 object val = mt.GetProp (i, key, out array);
145 Console.WriteLine ("nvals[{0}] is {1}, array.Length is null.\n",
151 else if (nvals[i] != array.Length)
153 Console.WriteLine ("nvals[{0}] is {1}, array.Length is {2}.\n",
154 i, nvals[i], array.Length);
160 for (int j = 0; j < nvals[i]; j++)
161 if (valtable[i, nvals[i] - 1 - j] != (MSymbol) array[j].Val)
163 Console.WriteLine ("valtable[{0}, {1}] is {2}, array[{1}] is {3}.\n",
164 i, j, valtable[i, j], array[j]);
173 Console.WriteLine ("GetProp returned null for index {0}.\n",
183 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
188 else if (valtable[i, nvals[i] - 1] == null)
190 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
195 else if ((MSymbol) val != valtable[i, nvals[i] - 1])
197 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
208 for (int i = 0; i < LENGTH; i++)
210 Console.Write (i + " ");
211 for (int j = nvals[i] - 1; j >= 0; j--)
212 Console.Write (valtable[i,j] + " ");
213 Console.WriteLine (":");
215 Console.WriteLine ("");
218 public static void Main (string[] args)
220 Random r = new Random (int.Parse (args[0]));
221 int check = (args.Length > 1 ? int.Parse (args[1]) : 0xFFFFFFF);
223 for (int loop = 0; loop < 1000000; loop++)
225 Console.WriteLine ("--- loop = {0} ---\n", loop);
228 mt.DumpPropNested ();
233 int from = r.Next (LENGTH);
234 int to = r.Next (LENGTH + 1);
243 //MSymbol val = r.Next (2) == 0 ? val0 : val1;
258 //MProperty prop = r.Next (2) == 0 ? prop0 : prop1;
275 TestPushProp (from, to, key, val);
278 TestPushProp (from, to, prop);
281 TestPopProp (from, to, key);
284 TestDelIns (from, to, r.Next (LENGTH - (to - from) + 1));
289 mt.DumpPropNested ();
291 if (Compare () == false)
293 Console.WriteLine ("");
295 Console.WriteLine ("Failed.");