From a37088db2d91df0e9444a99994667e9e0cfc4d5f Mon Sep 17 00:00:00 2001 From: ntakahas Date: Thu, 23 Apr 2009 07:57:43 +0000 Subject: [PATCH] Add TestDelIns (). --- textprop.cs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/textprop.cs b/textprop.cs index 0b7c8a1..aed4f04 100644 --- a/textprop.cs +++ b/textprop.cs @@ -15,7 +15,7 @@ public class Test 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) @@ -29,7 +29,8 @@ 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); } @@ -45,7 +46,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,6 +64,50 @@ 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++) @@ -152,7 +197,7 @@ public class Test 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) @@ -201,7 +246,7 @@ public class Test break; } - switch (r.Next (3)) + switch (r.Next (4)) { case 0: TestPushProp (from, to, key, val); @@ -212,6 +257,9 @@ public class Test case 2: TestPopProp (from, to, key); break; + case 3: + TestDelIns (from, to, r.Next (LENGTH - (to - from) + 1)); + break; } if (Compare () == false) -- 1.7.10.4