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[10];
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}, {2}.\n", from, to, val);
34 mt.PushProp (from, to, key, val);
37 static void TestPushProp (int from, int to, MTextProperty prop)
39 for (int i = from; i < to; i++)
40 if (nvals[i] == DEPTH)
43 for (int i = from; i < to; i++)
45 valtable[i, nvals[i]] = (MSymbol) prop.Val;
48 Console.WriteLine ("from {0}, to {1}, {2}.\n", from, to, prop);
50 mt.PushProp (from, to, prop);
53 static void TestPopProp (int from, int to, MSymbol key)
55 for (int i = from; i < to; i++)
58 valtable[i, nvals[i] - 1] = null;
61 Console.WriteLine ("from {0}, to {1}, pop.\n", from, to);
63 mt.PopProp (from, to, key);
66 static bool Compare ()
68 for (int i = 0; i < LENGTH; i++)
70 MTextProperty[] array;
71 object val = mt.GetProp (i, key, out array);
77 Console.WriteLine ("nvals[{0}] is {1}, array.Length is null.\n",
83 else if (nvals[i] != array.Length)
85 Console.WriteLine ("nvals[{0}] is {1}, array.Length is {2}.\n",
86 i, nvals[i], array.Length);
92 for (int j = 0; j < nvals[i]; j++)
93 if (valtable[i, nvals[i] - 1 - j] != (MSymbol) array[j].Val)
95 Console.WriteLine ("valtable[{0}, {1}] is {2}, array[{1}] is {3}.\n",
96 i, j, valtable[i, j], array[j]);
105 Console.WriteLine ("GetProp returned null for index {0}.\n",
115 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
120 else if (valtable[i, nvals[i] - 1] == null)
122 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
127 else if ((MSymbol) val != valtable[i, nvals[i] - 1])
129 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
140 for (int i = 0; i < LENGTH; i++)
142 Console.Write (i + " ");
143 for (int j = nvals[i] - 1; j >= 0; j--)
144 Console.Write (valtable[i,j] + " ");
145 Console.WriteLine (":");
147 Console.WriteLine ("");
150 public static void Main (string[] args)
152 Random r = new Random (int.Parse (args[0]));
153 int check = (args.Length > 1 ? int.Parse (args[1]) : -1);
155 for (int loop = 0; loop < 100000; loop++)
157 Console.WriteLine ("--- loop = {0} ---\n", loop);
160 mt.DumpPropNested ();
162 M17N.M17N.debug = true;
165 int from = r.Next (LENGTH);
166 int to = r.Next (LENGTH + 1);
175 //MSymbol val = r.Next (2) == 0 ? val0 : val1;
190 //MTextProperty prop = r.Next (2) == 0 ? prop0 : prop1;
207 TestPushProp (from, to, key, val);
210 TestPushProp (from, to, prop);
213 TestPopProp (from, to, key);
217 if (Compare () == false)
219 mt.DumpPropNested ();
220 Console.WriteLine ("");
222 Console.WriteLine ("Failed.");