+++ /dev/null
-using System;
-using System.Collections.Generic;
-using M17N;
-using M17N.Core;
-
-public class Test
-{
- const int LENGTH = 10;
- const int DEPTH = 10;
- static MText mt = new MText ("0123456789");
- static MSymbol key = MSymbol.PropertyKey ("rf_",
- MProperty.Flags.FrontSticky
- | MProperty.Flags.RearSticky);
- static MSymbol val0 = MSymbol.Of ("0");
- static MSymbol val1 = MSymbol.Of ("1");
- static MSymbol val2 = MSymbol.Of ("2");
- static MProperty prop0 = new MProperty (key, val0);
- static MProperty prop1 = new MProperty (key, val1);
- static MProperty prop2 = new MProperty (key, val2);
-
- static int[] nvals = new int[LENGTH];
- static MSymbol[,] valtable = new MSymbol[LENGTH, DEPTH + 1];
-
- static void TestPushProp (int from, int to, MProperty prop)
- {
- for (int i = from; i < to; i++)
- if (nvals[i] == DEPTH)
- return;
-
- for (int i = from; i < to; i++)
- {
- valtable[i, nvals[i]] = (MSymbol) prop.Val;
- nvals[i]++;
- }
- Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop);
-
- mt.PushProp (from, to, prop);
- }
-
- static void TestPopProp (int from, int to, MSymbol key)
- {
- for (int i = from; i < to; i++)
- if (nvals[i] > 0)
- {
- valtable[i, nvals[i] - 1] = null;
- nvals[i]--;
- }
- Console.WriteLine ("from {0}, to {1}, pop.\n", from, to);
-
- 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
- if (from2 > 0 && nvals[from2 - 1] > 0)
- for (i = from2; i < from2 + l; i++)
- {
- nvals[i] = nvals[from2 - 1];
- for (j = 0; j < nvals[from2 - 1]; j++)
- valtable[i, j] = valtable[from2 - 1, j];
- }
- else if (from2 + l < LENGTH && nvals[from2 + l] > 0)
- for (i = from2; i < from2 + l; i++)
- {
- nvals[i] = nvals[from2 + l];
- for (j = 0; j < nvals[from2 + l]; j++)
- valtable[i, j] = valtable[from2 + l, j];
- }
- else
- for (i = from2; i < from2 + l; i++)
- {
- nvals[i] = nvals2[i - from2];
- for (j = 0; j < nvals2[i - from2]; 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++)
- {
- MProperty[] array;
- object val = mt.GetProp (i, key, out array);
-
- if (array == null)
- {
- if (nvals[i] != 0)
- {
- Console.WriteLine ("nvals[{0}] is {1}, array.Length is null.\n",
- i, nvals[i]);
- return false;
- }
- }
-
- else if (nvals[i] != array.Length)
- {
- Console.WriteLine ("nvals[{0}] is {1}, array.Length is {2}.\n",
- i, nvals[i], array.Length);
- return false;
- }
-
- else
- {
- for (int j = 0; j < nvals[i]; j++)
- if (valtable[i, nvals[i] - 1 - j] != (MSymbol) array[j].Val)
- {
- Console.WriteLine ("valtable[{0}, {1}] is {2}, array[{1}] is {3}.\n",
- i, j, valtable[i, j], array[j]);
- return false;
- }
- }
-
- if (val == null)
- {
- if (nvals[i] != 0)
- {
- Console.WriteLine ("GetProp returned null for index {0}.\n",
- i);
- return false;
- }
- }
-
- else
- {
- if (nvals[i] == 0)
- {
- Console.WriteLine ("GetProp returned {0} for index {1}.\n",
- val, i);
- return false;
- }
-
- else if (valtable[i, nvals[i] - 1] == null)
- {
- Console.WriteLine ("GetProp returned {0} for index {1}.\n",
- val, i);
- return false;
- }
-
- else if ((MSymbol) val != valtable[i, nvals[i] - 1])
- {
- Console.WriteLine ("GetProp returned {0} for index {1}.\n",
- val, i);
- return false;
- }
- }
- }
- return true;
- }
-
- static void Dump ()
- {
- for (int i = 0; i < LENGTH; i++)
- {
- Console.Write (i + " ");
- for (int j = nvals[i] - 1; j >= 0; j--)
- Console.Write (valtable[i,j] + " ");
- Console.WriteLine (":");
- }
- Console.WriteLine ("");
- }
-
- public static void Main (string[] args)
- {
- Random r = new Random (int.Parse (args[0]));
- int check = (args.Length > 1 ? int.Parse (args[1]) : 0xFFFFFFF);
-
- for (int loop = 0; loop < 1000000; loop++)
- {
- Console.WriteLine ("--- loop = {0} ---\n", loop);
- if (loop >= check)
- {
- mt.DumpPropNested ();
- Dump ();
- M17n.debug = true;
- }
-
- int from = r.Next (LENGTH);
- int to = r.Next (LENGTH + 1);
- if (from > to)
- {
- int tmp = from;
- from = to;
- to = tmp;
- }
-
- MProperty prop;
- switch (r.Next (3))
- {
- case 0:
- prop = prop0;
- break;
- case 1:
- prop = prop1;
- break;
- default:
- prop = prop2;
- break;
- }
-
- switch (r.Next (3))
- {
- case 0:
- TestPushProp (from, to, prop);
- break;
- case 1:
- TestPopProp (from, to, key);
- break;
- case 2:
- TestDelIns (from, to, r.Next (LENGTH - (to - from) + 1));
- break;
- }
-
- if (M17n.debug)
- mt.DumpPropNested ();
-
- if (Compare () == false)
- {
- Console.WriteLine ("");
- Dump ();
- Console.WriteLine ("Failed.");
- return;
- }
- }
- }
-}
const int LENGTH = 10;
const int DEPTH = 10;
static MText mt = new MText ("0123456789");
- static MSymbol key = MSymbol.PropertyKey ("__s",
+ static MSymbol key = MSymbol.PropertyKey ("se",
MProperty.Flags.Sensitive);
static MSymbol val0 = MSymbol.Of ("0");
static MSymbol val1 = MSymbol.Of ("1");
static void TestPushProp (int from, int to, MProperty prop)
{
int i;
+ MSymbol sym;
- for (i = from - 1; i >= 0 && valtable[i] == valtable[from]; i--)
- valtable[i] = null;
- for (i = to; i < LENGTH && valtable[i] == valtable[to - 1]; i++)
- valtable[i] = null;
+ if (from > 0 && valtable[from] != null)
+ {
+ sym = valtable[from];
+ for (i = from - 1; i >= 0 && valtable[i] == sym; i--)
+ valtable[i] = null;
+ }
+ if (to < LENGTH && valtable[to - 1] != null)
+ {
+ sym = valtable[to - 1];
+ for (i = to; i < LENGTH && valtable[i] == sym; i++)
+ valtable[i] = null;
+ }
for (i = from; i < to; i++)
valtable[i] = (MSymbol) prop.Val;
Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop.Val);
static void TestPopProp (int from, int to, MSymbol key)
{
int i;
+ MSymbol sym;
- for (i = from - 1; i >= 0 && valtable[i] == valtable[from]; i--)
- valtable[i] = null;
- for (i = to; i < LENGTH && valtable[i] == valtable[to]; i++)
- valtable[i] = null;
+ if (from > 0 && valtable[from] != null)
+ {
+ sym = valtable[from];
+ for (i = from - 1; i >= 0 && valtable[i] == sym; i--)
+ valtable[i] = null;
+ }
+ if (to < LENGTH && valtable[to - 1] != null)
+ {
+ sym = valtable[to - 1];
+ for (i = to; i < LENGTH && valtable[i] == sym; i++)
+ valtable[i] = null;
+ }
for (i = from; i < to; i++)
valtable[i] = null;
Console.WriteLine ("from {0}, to {1}, pop.\n", from, to);
{
int i, l = to - from;
MSymbol[] valtable2 = new MSymbol[LENGTH];
+ MSymbol sym;
+
+ // sensitivity for deletion
+ if (from > 0 && valtable[from - 1] == valtable[from]
+ && valtable[from] != null)
+ {
+ sym = valtable[from];
+ for (i = from - 1; i >= 0 && valtable[i] == sym; i--)
+ valtable[i] = null;
+ for (i = from; i < LENGTH && valtable[i] == sym; i++)
+ valtable[i] = null;
+ }
+ if (to < LENGTH && valtable[to - 1] == valtable[to]
+ && valtable[to] != null)
+ {
+ sym = valtable[to - 1];
+ for (i = to - 1; i >= 0 && valtable[i] == sym; i--)
+ valtable[i] = null;
+ for (i = to; i < LENGTH && valtable[i] == sym; i++)
+ valtable[i] = null;
+ }
// copy
for (i = from; i < to; i++)
valtable2[i - from] = valtable[i];
// delete
- for (i = from - 1; i >= 0 && valtable[i] == valtable[from]; i--)
- valtable[i] = null;
- for (i = to; i < LENGTH && valtable[i] == valtable[to - 1]; i++)
- valtable[i] = null;
for (i = to; i < LENGTH; i++)
valtable[i - l] = valtable[i];
+ for (i = LENGTH - l; i < LENGTH; i++)
+ valtable[i] = null;
- // move
- MSymbol sym = valtable[from2];
- if (from2 > 0 && valtable[from2 - 1] == sym)
+ // sensitivity for insertion
+ if (from2 > 0 && valtable[from2 - 1] == valtable[from2]
+ && valtable[from2] != null)
{
+ sym = valtable[from2];
for (i = from2 - 1; i >= 0 && valtable[i] == sym; i--)
valtable[i] = null;
for (i = from2; i < LENGTH && valtable[i] == sym; i++)
valtable[i] = null;
}
+
+ // move
for (i = LENGTH - 1; i >= from2 + l; i--)
valtable[i] = valtable[i - l];
if (valtable[i] != (MSymbol) val)
{
Console.WriteLine ("valtable[{0}] is {1}, GetProp returned {2}",
- i, valtable[i], val);
+ i,
+ valtable[i] == null ? MSymbol.nil : valtable[i],
+ val == null ? MSymbol.nil : val);
return false;
}
}