From 40942047c34366f97803a3f079aa14d48c87c1fc Mon Sep 17 00:00:00 2001 From: ntakahas Date: Fri, 1 May 2009 11:27:37 +0000 Subject: [PATCH] New file. Test Sensitive textprop. --- __s.cs | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 __s.cs diff --git a/__s.cs b/__s.cs new file mode 100644 index 0000000..8b4344b --- /dev/null +++ b/__s.cs @@ -0,0 +1,178 @@ +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; + } + } + } +} -- 1.7.10.4