2 using System.Collections.Generic;
10 static MText mt = new MText ("0123456789");
11 static MSymbol key = MSymbol.Of ("k");
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, MSymbol key, MSymbol val)
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]] = val;
33 Console.WriteLine ("from {0}, to {1}, push {2}, {3}.\n",
36 mt.PushProp (from, to, key, val);
39 static void TestPushProp (int from, int to, MProperty prop)
41 for (int i = from; i < to; i++)
42 if (nvals[i] == DEPTH)
45 for (int i = from; i < to; i++)
47 valtable[i, nvals[i]] = (MSymbol) prop.Val;
50 Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop);
52 mt.PushProp (from, to, prop);
55 static void TestPopProp (int from, int to, MSymbol key)
57 for (int i = from; i < to; i++)
60 valtable[i, nvals[i] - 1] = null;
63 Console.WriteLine ("from {0}, to {1}, pop.\n", from, to);
65 mt.PopProp (from, to, key);
68 static void TestDelIns (int from, int to, int from2)
70 int i, j, l = to - from;
71 int[] nvals2 = new int[LENGTH];
72 MSymbol[,] valtable2 = new MSymbol[LENGTH, DEPTH + 1];
75 for (i = from; i < to; i++)
77 nvals2[i - from] = nvals[i];
78 for (j = 0; j < nvals[i]; j++)
79 valtable2[i - from, j] = valtable[i, j];
83 for (i = to; i < LENGTH; i++)
85 nvals[i - l] = nvals[i];
86 for (j = 0; j < nvals[i]; j++)
87 valtable[i - l, j] = valtable[i, j];
91 for (i = LENGTH - 1; i >= from2 + l; i--)
93 nvals[i] = nvals[i - l];
94 for (j = 0; j < nvals[i]; j++)
95 valtable[i, j] = valtable[i - l, j];
99 for (i = from2; i < from2 + l; i++)
101 nvals[i] = nvals2[i - from2];
102 for (j = 0; j < nvals[i]; j++)
103 valtable[i, j] = valtable2[i - from2, j];
105 Console.WriteLine ("from {0}, to {1}, moveto {2}.\n", from, to, from2);
107 MText mt2 = mt.Dup ();
109 mt.Ins (from2, mt2, from, to);
112 static bool Compare ()
114 for (int i = 0; i < LENGTH; i++)
117 object val = mt.GetProp (i, key, out array);
123 Console.WriteLine ("nvals[{0}] is {1}, array.Length is null.\n",
129 else if (nvals[i] != array.Length)
131 Console.WriteLine ("nvals[{0}] is {1}, array.Length is {2}.\n",
132 i, nvals[i], array.Length);
138 for (int j = 0; j < nvals[i]; j++)
139 if (valtable[i, nvals[i] - 1 - j] != (MSymbol) array[j].Val)
141 Console.WriteLine ("valtable[{0}, {1}] is {2}, array[{1}] is {3}.\n",
142 i, j, valtable[i, j], array[j]);
151 Console.WriteLine ("GetProp returned null for index {0}.\n",
161 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
166 else if (valtable[i, nvals[i] - 1] == null)
168 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
173 else if ((MSymbol) val != valtable[i, nvals[i] - 1])
175 Console.WriteLine ("GetProp returned {0} for index {1}.\n",
186 for (int i = 0; i < LENGTH; i++)
188 Console.Write (i + " ");
189 for (int j = nvals[i] - 1; j >= 0; j--)
190 Console.Write (valtable[i,j] + " ");
191 Console.WriteLine (":");
193 Console.WriteLine ("");
196 public static void Main (string[] args)
198 Random r = new Random (int.Parse (args[0]));
199 int check = (args.Length > 1 ? int.Parse (args[1]) : 0xFFFFFFF);
201 for (int loop = 0; loop < 1000000; loop++)
203 Console.WriteLine ("--- loop = {0} ---\n", loop);
206 mt.DumpPropNested ();
211 int from = r.Next (LENGTH);
212 int to = r.Next (LENGTH + 1);
221 //MSymbol val = r.Next (2) == 0 ? val0 : val1;
236 //MProperty prop = r.Next (2) == 0 ? prop0 : prop1;
253 TestPushProp (from, to, key, val);
256 TestPushProp (from, to, prop);
259 TestPopProp (from, to, key);
262 TestDelIns (from, to, r.Next (LENGTH - (to - from) + 1));
267 mt.DumpPropNested ();
269 if (Compare () == false)
271 Console.WriteLine ("");
273 Console.WriteLine ("Failed.");