-CS=gmcs
+CS=gmcs2
M17N_SRC = M17N.cs
CORE_SRC = MSymbol.cs MPlist.cs MText.cs MDatabase.cs
+++ /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 ("__s",
- MProperty.Flags.Sensitive);
- 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 MSymbol[] valtable = new MSymbol[LENGTH];
-
- static void TestPushProp (int from, int to, MProperty prop)
- {
- int i;
-
- if (from > 0 && valtable[from - 1] == valtable[from])
- for (i = from - 1; i >= 0 && valtable[i] == valtable[from]; i--)
- valtable[i] = null;
- if (to < LENGTH && valtable[to] == valtable[to - 1])
- for (i = to; i < LENGTH && valtable[i] == valtable[to - 1]; 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);
-
- mt.PushProp (from, to, prop);
- }
-
- static void TestPopProp (int from, int to, MSymbol key)
- {
- for (int i = from; i < to; i++)
- valtable[i] = null;
- 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, l = to - from;
- MSymbol[] valtable2 = new MSymbol[LENGTH];
-
- // copy
- for (i = from; i < to; i++)
- valtable2[i - from] = valtable[i];
-
- // delete
- if (from > 0 && valtable[from - 1] == valtable[from])
- for (i = from - 1; i >= 0 && valtable[i] == valtable[from]; i--)
- valtable[i] = null;
- if (to < LENGTH && valtable[to] == valtable[to - 1])
- 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];
-
- // move
- MSymbol sym = valtable[from2];
- if (from2 > 0 && from2 < LENGTH - l && valtable[from2 - 1] == sym)
- {
- 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;
- }
- for (i = LENGTH - 1; i >= from2 + l; i--)
- valtable[i] = valtable[i - l];
-
- // insert
- for (i = from2; i < from2 + l; i++)
- valtable[i] = valtable2[i - from2];
- 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++)
- {
- object val = mt.GetProp (i, key);
-
- if (valtable[i] != (MSymbol) val)
- {
- Console.WriteLine ("valtable[{0}] is {1}, GetProp returned {2}",
- i, valtable[i], val);
- return false;
- }
- }
- return true;
- }
-
- static void Dump ()
- {
- for (int i = 0; i < LENGTH; i++)
- Console.WriteLine ("{0} {1} :", i, valtable[i]);
- }
-
- 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++)
- {
- int from, to;
-
- Console.WriteLine ("--- loop = {0} ---\n", loop);
- if (loop >= check)
- {
- mt.DumpPropNested ();
- Dump ();
- M17n.debug = true;
- }
-
- do {
- from = r.Next (LENGTH);
- to = r.Next (LENGTH) + 1;
- } while (from == to);
- 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;
- }
- }
- }
-}
+++ /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 ("_f_", MProperty.Flags.FrontSticky);
- 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
- for (i = from2; i < from2 + l; i++)
- {
- if (from2 + l == LENGTH || nvals[from2 + l] == 0)
- {
- nvals[i] = nvals2[i - from2];
- for (j = 0; j < nvals[i]; j++)
- valtable[i, j] = valtable2[i - from2, j];
- }
- else
- {
- nvals[i] = nvals[from2 + l];
- for (j = 0; j < nvals[i]; j++)
- valtable[i, j] = valtable[from2 + l, 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;
- }
- }
- }
-}
--- /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 ("_f_", MProperty.Flags.FrontSticky);
+ 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
+ for (i = from2; i < from2 + l; i++)
+ {
+ if (from2 + l == LENGTH || nvals[from2 + l] == 0)
+ {
+ nvals[i] = nvals2[i - from2];
+ for (j = 0; j < nvals[i]; j++)
+ valtable[i, j] = valtable2[i - from2, j];
+ }
+ else
+ {
+ nvals[i] = nvals[from2 + l];
+ for (j = 0; j < nvals[i]; j++)
+ valtable[i, j] = valtable[from2 + l, 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;
+ }
+ }
+ }
+}
+++ /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 ("r__", 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
- for (i = from2; i < from2 + l; i++)
- {
- if (from2 == 0 || nvals[from2 - 1] == 0)
- {
- nvals[i] = nvals2[i - from2];
- for (j = 0; j < nvals[i]; j++)
- valtable[i, j] = valtable2[i - from2, j];
- }
- else
- {
- nvals[i] = nvals[from2 - 1];
- for (j = 0; j < nvals[i]; j++)
- valtable[i, j] = valtable[from2 - 1, 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;
- }
- }
- }
-}
--- /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 ("r__", 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
+ for (i = from2; i < from2 + l; i++)
+ {
+ if (from2 == 0 || nvals[from2 - 1] == 0)
+ {
+ nvals[i] = nvals2[i - from2];
+ for (j = 0; j < nvals[i]; j++)
+ valtable[i, j] = valtable2[i - from2, j];
+ }
+ else
+ {
+ nvals[i] = nvals[from2 - 1];
+ for (j = 0; j < nvals[i]; j++)
+ valtable[i, j] = valtable[from2 - 1, 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;
+ }
+ }
+ }
+}
--- /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 ("__s",
+ MProperty.Flags.Sensitive);
+ 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 MSymbol[] valtable = new MSymbol[LENGTH];
+
+ static void TestPushProp (int from, int to, MProperty prop)
+ {
+ int i;
+
+ 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 = from; i < to; i++)
+ valtable[i] = (MSymbol) prop.Val;
+ Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop.Val);
+
+ mt.PushProp (from, to, prop);
+ }
+
+ static void TestPopProp (int from, int to, MSymbol key)
+ {
+ int i;
+
+ 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;
+ for (i = from; i < to; i++)
+ valtable[i] = null;
+ 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, l = to - from;
+ MSymbol[] valtable2 = new MSymbol[LENGTH];
+
+ // 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];
+
+ // move
+ MSymbol sym = valtable[from2];
+ if (from2 > 0 && valtable[from2 - 1] == sym)
+ {
+ 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;
+ }
+ for (i = LENGTH - 1; i >= from2 + l; i--)
+ valtable[i] = valtable[i - l];
+
+ // insert
+ for (i = from2; i < from2 + l; i++)
+ valtable[i] = valtable2[i - from2];
+ 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++)
+ {
+ object val = mt.GetProp (i, key);
+
+ if (valtable[i] != (MSymbol) val)
+ {
+ Console.WriteLine ("valtable[{0}] is {1}, GetProp returned {2}",
+ i, valtable[i], val);
+ return false;
+ }
+ }
+ return true;
+ }
+
+ static void Dump ()
+ {
+ for (int i = 0; i < LENGTH; i++)
+ Console.WriteLine ("{0} {1} :", i, valtable[i]);
+ }
+
+ 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++)
+ {
+ int from, to;
+
+ Console.WriteLine ("--- loop = {0} ---\n", loop);
+ if (loop >= check)
+ {
+ mt.DumpPropNested ();
+ Dump ();
+ M17n.debug = true;
+ }
+
+ do {
+ from = r.Next (LENGTH);
+ to = r.Next (LENGTH) + 1;
+ } while (from == to);
+ 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 ("k");
+ static MSymbol key = MSymbol.PropertyKey ("___");
+ static MSymbol key_r = MSymbol.PropertyKey ("r__",
+ MProperty.Flags.RearSticky);
+ static MSymbol key_f = MSymbol.PropertyKey ("_f_",
+ MProperty.Flags.FrontSticky);
+ static MSymbol key_rf = MSymbol.PropertyKey ("rf_",
+ (MProperty.Flags.RearSticky
+ | MProperty.Flags.FrontSticky));
+ static MSymbol key_s = MSymbol.PropertyKey ("__s",
+ MProperty.Flags.Sensitive);
+ static MSymbol key_rs = MSymbol.PropertyKey ("r_s",
+ (MProperty.Flags.RearSticky
+ | MProperty.Flags.Sensitive));
+ static MSymbol key_fs = MSymbol.PropertyKey ("_fs",
+ (MProperty.Flags.FrontSticky
+ | MProperty.Flags.Sensitive));
+ static MSymbol key_rfs = MSymbol.PropertyKey ("rfs",
+ (MProperty.Flags.RearSticky
+ | MProperty.Flags.FrontSticky
+ | MProperty.Flags.Sensitive));
+
static MSymbol val0 = MSymbol.Of ("0");
static MSymbol val1 = MSymbol.Of ("1");
static MSymbol val2 = MSymbol.Of ("2");