2 using System.Collections.Generic;
10 static MText mt = new MText ("0123456789");
11 static MSymbol key = MSymbol.PropertyKey ("rf_",
12 MProperty.Flags.FrontSticky
13 | MProperty.Flags.RearSticky);
14 static MSymbol val0 = MSymbol.Of ("0");
15 static MSymbol val1 = MSymbol.Of ("1");
16 static MSymbol val2 = MSymbol.Of ("2");
17 static MProperty prop0 = new MProperty (key, val0);
18 static MProperty prop1 = new MProperty (key, val1);
19 static MProperty prop2 = new MProperty (key, val2);
21 static int[] nvals = new int[LENGTH];
22 static MSymbol[,] valtable = new MSymbol[LENGTH, DEPTH + 1];
24 static void TestPushProp (int from, int to, MProperty prop)
26 for (int i = from; i < to; i++)
27 if (nvals[i] == DEPTH)
30 for (int i = from; i < to; i++)
32 valtable[i, nvals[i]] = (MSymbol) prop.Val;
35 Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop);
37 mt.PushProp (from, to, prop);
40 static void TestPopProp (int from, int to, MSymbol key)
42 for (int i = from; i < to; i++)
45 valtable[i, nvals[i] - 1] = null;
48 Console.WriteLine ("from {0}, to {1}, pop.\n", from, to);
50 mt.PopProp (from, to, key);
53 static void TestDelIns (int from, int to, int from2)
55 int i, j, l = to - from;
56 int[] nvals2 = new int[LENGTH];
57 MSymbol[,] valtable2 = new MSymbol[LENGTH, DEPTH + 1];
60 for (i = from; i < to; i++)
62 nvals2[i - from] = nvals[i];
63 for (j = 0; j < nvals[i]; j++)
64 valtable2[i - from, j] = valtable[i, j];
68 for (i = to; i < LENGTH; i++)
70 nvals[i - l] = nvals[i];
71 for (j = 0; j < nvals[i]; j++)
72 valtable[i - l, j] = valtable[i, j];
76 for (i = LENGTH - 1; i >= from2 + l; i--)
78 nvals[i] = nvals[i - l];
79 for (j = 0; j < nvals[i]; j++)
80 valtable[i, j] = valtable[i - l, j];
84 if (from2 > 0 && nvals[from2 - 1] > 0)
85 for (i = from2; i < from2 + l; i++)
87 nvals[i] = nvals[from2 - 1];
88 for (j = 0; j < nvals[from2 - 1]; j++)
89 valtable[i, j] = valtable[from2 - 1, j];
91 else if (from2 + l < LENGTH && nvals[from2 + l] > 0)
92 for (i = from2; i < from2 + l; i++)
94 nvals[i] = nvals[from2 + l];
95 for (j = 0; j < nvals[from2 + l]; j++)
96 valtable[i, j] = valtable[from2 + l, j];
99 for (i = from2; i < from2 + l; i++)
101 nvals[i] = nvals2[i - from2];
102 for (j = 0; j < nvals2[i - from2]; 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);
237 TestPushProp (from, to, prop);
240 TestPopProp (from, to, key);
243 TestDelIns (from, to, r.Next (LENGTH - (to - from) + 1));
248 mt.DumpPropNested ();
250 if (Compare () == false)
252 Console.WriteLine ("");
254 Console.WriteLine ("Failed.");