static MTextProperty prop1 = new MTextProperty (key, val1);
static MTextProperty prop2 = new MTextProperty (key, val2);
- static int[] nvals = new int[10];
+ static int[] nvals = new int[LENGTH];
static MSymbol[,] valtable = new MSymbol[LENGTH, DEPTH + 1];
static void TestPushProp (int from, int to, MSymbol key, MSymbol val)
valtable[i, nvals[i]] = val;
nvals[i]++;
}
- Console.WriteLine ("from {0}, to {1}, {2}.\n", from, to, val);
+ Console.WriteLine ("from {0}, to {1}, push {2}, {3}.\n",
+ from, to, key, val);
mt.PushProp (from, to, key, val);
}
valtable[i, nvals[i]] = (MSymbol) prop.Val;
nvals[i]++;
}
- Console.WriteLine ("from {0}, to {1}, {2}.\n", from, to, prop);
+ Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop);
mt.PushProp (from, to, prop);
}
mt.PopProp (from, to, key);
}
+ static void TestDelIns (int from, int to, int from2)
+ {
+ int i, j, l = to - from;
+ int[] nvals2 = new int[LENGTH];
+ MSymbol[,] valtable2 = new MSymbol[LENGTH, DEPTH + 1];
+
+ // copy
+ for (i = from; i < to; i++)
+ {
+ nvals2[i - from] = nvals[i];
+ for (j = 0; j < nvals[i]; j++)
+ valtable2[i - from, j] = valtable[i, j];
+ }
+
+ // delete
+ for (i = to; i < LENGTH; i++)
+ {
+ nvals[i - l] = nvals[i];
+ for (j = 0; j < nvals[i]; j++)
+ valtable[i - l, j] = valtable[i, j];
+ }
+
+ // move
+ for (i = LENGTH - 1; i >= from2 + l; i--)
+ {
+ nvals[i] = nvals[i - l];
+ for (j = 0; j < nvals[i]; j++)
+ valtable[i, j] = valtable[i - l, j];
+ }
+
+ // insert
+ for (i = from2; i < from2 + l; i++)
+ {
+ nvals[i] = nvals2[i - from2];
+ for (j = 0; j < nvals[i]; j++)
+ valtable[i, j] = valtable2[i - from2, j];
+ }
+ Console.WriteLine ("from {0}, to {1}, moveto {2}.\n", from, to, from2);
+
+ MText mt2 = mt.Dup ();
+ mt.Del (from, to);
+ mt.Ins (from2, mt2, from, to);
+ }
+
static bool Compare ()
{
for (int i = 0; i < LENGTH; i++)
Random r = new Random (int.Parse (args[0]));
int check = (args.Length > 1 ? int.Parse (args[1]) : -1);
- for (int loop = 0; loop < 100000; loop++)
+ for (int loop = 0; loop < 30; loop++)
{
Console.WriteLine ("--- loop = {0} ---\n", loop);
if (loop == check)
break;
}
- switch (r.Next (3))
+ switch (r.Next (4))
{
case 0:
TestPushProp (from, to, key, val);
case 2:
TestPopProp (from, to, key);
break;
+ case 3:
+ TestDelIns (from, to, r.Next (LENGTH - (to - from) + 1));
+ break;
}
if (Compare () == false)