2 using System.Collections.Generic;
9 static MText mt = new MText ("0123456789");
10 static MSymbol key = new MSymbol ("k");
11 static MSymbol val0 = new MSymbol ("0");
12 static MSymbol val1 = new MSymbol ("1");
13 static MSymbol val2 = new MSymbol ("2");
14 static MTextProperty prop0 = new MTextProperty (key, val0);
15 static MTextProperty prop1 = new MTextProperty (key, val1);
16 static MTextProperty prop2 = new MTextProperty (key, val2);
18 static int[] nvals = new int[LENGTH];
19 static MSymbol[,] valtable = new MSymbol[LENGTH, DEPTH + 1];
21 static void TestPushProp (int from, int to, MSymbol key, MSymbol val)
23 for (int i = from; i < to; i++)
24 if (nvals[i] == DEPTH)
27 for (int i = from; i < to; i++)
29 valtable[i, nvals[i]] = val;
32 Console.WriteLine ("from {0}, to {1}, push {2}, {3}.\n",
35 mt.PushProp (from, to, key, val);
38 static void TestPushProp (int from, int to, MTextProperty prop)
40 for (int i = from; i < to; i++)
41 if (nvals[i] == DEPTH)
44 for (int i = from; i < to; i++)
46 valtable[i, nvals[i]] = (MSymbol) prop.Val;
49 Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop);
51 mt.PushProp (from, to, prop);
54 static void TestPopProp (int from, int to, MSymbol key)
56 for (int i = from; i < to; i++)
59 valtable[i, nvals[i] - 1] = null;
62 Console.WriteLine ("from {0}, to {1}, pop.\n", from, to);
64 mt.PopProp (from, to, key);
67 static void TestDelIns (int from, int to, int from2)
69 int i, j, l = to - from;
70 int[] nvals2 = new int[LENGTH];
71 MSymbol[,] valtable2 = new MSymbol[LENGTH, DEPTH + 1];
74 for (i = from; i < to; i++)
76 nvals2[i - from] = nvals[i];
77 for (j = 0; j < nvals[i]; j++)
78 valtable2[i - from, j] = valtable[i, j];
82 for (i = to; i < LENGTH; i++)
84 nvals[i - l] = nvals[i];
85 for (j = 0; j < nvals[i]; j++)
86 valtable[i - l, j] = valtable[i, j];
90 for (i = LENGTH - 1; i >= from2 + l; i--)
92 nvals[i] = nvals[i - l];
93 for (j = 0; j < nvals[i]; j++)
94 valtable[i, j] = valtable[i - l, j];
98 for (i = from2; i < from2 + l; i++)
100 nvals[i] = nvals2[i - from2];
101 for (j = 0; j < nvals[i]; j++)
102 valtable[i, j] = valtable2[i - from2, j];
104 Console.WriteLine ("from {0}, to {1}, moveto {2}.\n", from, to, from2);
106 MText mt2 = mt.Dup ();
108 mt.Ins (from2, mt2, from, to);
111 static bool Compare ()
113 for (int i = 0; i < LENGTH; i++)
115 MTextProperty[] array;
116 object val = mt.GetProp (i, key, out array);
122 Console.WriteLine ("nvals[{0}] is {1}, array.Length is null.\n",
128 else if (nvals[i] != array.Length)
130 Console.WriteLine ("nvals[{0}] is {1}, array.Length is {2}.\n",
131 i, nvals[i], array.Length);
137 for (int j = 0; j < nvals[i]; j++)
138 if (valtable[i, nvals[i] - 1 - j] != (MSymbol) array[j].Val)
140 Console.WriteLine ("valtable[{0}, {1}] is {2}, array[{1}] is {3}.\n",
141 i, j, valtable[i, j], array[j]);
150 Console.WriteLine ("GetProp returned null for index {0}.\n",
160 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
165 else if (valtable[i, nvals[i] - 1] == null)
167 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
172 else if ((MSymbol) val != valtable[i, nvals[i] - 1])
174 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
185 for (int i = 0; i < LENGTH; i++)
187 Console.Write (i + " ");
188 for (int j = nvals[i] - 1; j >= 0; j--)
189 Console.Write (valtable[i,j] + " ");
190 Console.WriteLine (":");
192 Console.WriteLine ("");
195 public static void Main (string[] args)
197 Random r = new Random (int.Parse (args[0]));
198 int check = (args.Length > 1 ? int.Parse (args[1]) : -1);
200 for (int loop = 0; loop < 30; loop++)
202 Console.WriteLine ("--- loop = {0} ---\n", loop);
205 mt.DumpPropNested ();
207 M17N.M17N.debug = true;
210 int from = r.Next (LENGTH);
211 int to = r.Next (LENGTH + 1);
220 //MSymbol val = r.Next (2) == 0 ? val0 : val1;
235 //MTextProperty prop = r.Next (2) == 0 ? prop0 : prop1;
252 TestPushProp (from, to, key, val);
255 TestPushProp (from, to, prop);
258 TestPopProp (from, to, key);
261 TestDelIns (from, to, r.Next (LENGTH - (to - from) + 1));
265 if (Compare () == false)
267 mt.DumpPropNested ();
268 Console.WriteLine ("");
270 Console.WriteLine ("Failed.");