X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=textprop.cs;h=c44f0e8a6f72b1f2d9990b5080d3534b78534b5d;hb=139bdc3719eee81aa203e40f40c612fb799b8ed4;hp=d036b83cd0de0426bcd36efa52caace9fbe55049;hpb=6fe558ba3d59de23002825b25336b465b5b7ae49;p=m17n%2Fm17n-lib-cs.git diff --git a/textprop.cs b/textprop.cs index d036b83..c44f0e8 100644 --- a/textprop.cs +++ b/textprop.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using M17N; using M17N.Core; public class Test @@ -7,15 +8,37 @@ public class Test const int LENGTH = 10; const int DEPTH = 10; static MText mt = new MText ("0123456789"); - static MSymbol key = new MSymbol ("k"); - static MSymbol val0 = new MSymbol ("0"); - static MSymbol val1 = new MSymbol ("1"); - static MSymbol val2 = new MSymbol ("2"); - static MTextProperty prop0 = new MTextProperty (key, val0); - static MTextProperty prop1 = new MTextProperty (key, val1); - static MTextProperty prop2 = new MTextProperty (key, val2); - - static int[] nvals = new int[10]; + static MSymbol key = MSymbol.PropertyKey ("___"); +#if false + 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)); +#endif + + 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, MSymbol key, MSymbol val) @@ -29,12 +52,13 @@ public class Test 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); } - static void TestPushProp (int from, int to, MTextProperty prop) + static void TestPushProp (int from, int to, MProperty prop) { for (int i = from; i < to; i++) if (nvals[i] == DEPTH) @@ -45,7 +69,7 @@ public class Test 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); } @@ -63,11 +87,55 @@ public class Test 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++) { - MTextProperty[] array; + MProperty[] array; object val = mt.GetProp (i, key, out array); if (array == null) @@ -150,16 +218,16 @@ public class Test public static void Main (string[] args) { Random r = new Random (int.Parse (args[0])); - int check = (args.Length > 1 ? int.Parse (args[1]) : -1); + int check = (args.Length > 1 ? int.Parse (args[1]) : 0xFFFFFFF); - for (int loop = 0; loop < 100000; loop++) + for (int loop = 0; loop < 1000000; loop++) { - if (loop == check) + Console.WriteLine ("--- loop = {0} ---\n", loop); + if (loop >= check) { - Console.WriteLine ("--- loop = {0} ---\n", loop); mt.DumpPropNested (); Dump (); - M17N.M17N.debug = true; + M17n.debug = true; } int from = r.Next (LENGTH); @@ -186,8 +254,8 @@ public class Test break; } - MTextProperty prop; - //MTextProperty prop = r.Next (2) == 0 ? prop0 : prop1; + MProperty prop; + //MProperty prop = r.Next (2) == 0 ? prop0 : prop1; switch (r.Next (3)) { case 0: @@ -201,7 +269,7 @@ public class Test break; } - switch (r.Next (3)) + switch (r.Next (4)) { case 0: TestPushProp (from, to, key, val); @@ -212,17 +280,21 @@ public class Test case 2: TestPopProp (from, to, key); break; + case 3: + TestDelIns (from, to, r.Next (LENGTH - (to - from) + 1)); + break; } + if (M17n.debug) + mt.DumpPropNested (); + if (Compare () == false) { - mt.DumpPropNested (); Console.WriteLine (""); Dump (); Console.WriteLine ("Failed."); return; } } - } }