2 using System.Collections.Generic;
10 static MText mt = new MText ("0123456789");
11 static MSymbol key = MSymbol.PropertyKey ("rse",
12 MProperty.Flags.RearSensitive);
13 static MSymbol val0 = MSymbol.Of ("0");
14 static MSymbol val1 = MSymbol.Of ("1");
15 static MSymbol val2 = MSymbol.Of ("2");
16 static MProperty prop0 = new MProperty (key, val0);
17 static MProperty prop1 = new MProperty (key, val1);
18 static MProperty prop2 = new MProperty (key, val2);
20 static MSymbol[] valtable = new MSymbol[LENGTH];
22 static void TestPushProp (int from, int to, MProperty prop)
27 if (from > 0 && valtable[from] != null)
30 for (i = from - 1; i >= 0 && valtable[i] == sym; i--)
33 if (to < LENGTH && valtable[to - 1] != null)
35 sym = valtable[to - 1];
36 for (i = to; i < LENGTH && valtable[i] == sym; i++)
39 for (i = from; i < to; i++)
40 valtable[i] = (MSymbol) prop.Val;
41 Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop.Val);
43 mt.PushProp (from, to, prop);
46 static void TestPopProp (int from, int to, MSymbol key)
51 if (from > 0 && valtable[from] != null)
54 for (i = from - 1; i >= 0 && valtable[i] == sym; i--)
57 if (to < LENGTH && valtable[to - 1] != null)
59 sym = valtable[to - 1];
60 for (i = to; i < LENGTH && valtable[i] == sym; i++)
63 for (i = from; i < to; i++)
65 Console.WriteLine ("from {0}, to {1}, pop.\n", from, to);
67 mt.PopProp (from, to, key);
70 static void TestDelIns (int from, int to, int from2)
73 MSymbol[] valtable2 = new MSymbol[LENGTH];
76 // sensitivity for deletion
77 if (from > 0 && valtable[from - 1] != null)
79 sym = valtable[from - 1];
80 for (i = from - 1; i >= 0 && valtable[i] == sym; i--)
82 for (i = from; i < LENGTH && valtable[i] == sym; i++)
85 if (to < LENGTH && valtable[to - 1] != null)
87 sym = valtable[to - 1];
88 for (i = to - 1; i >= 0 && valtable[i] == sym; i--)
90 for (i = to; i < LENGTH && valtable[i] == sym; i++)
95 for (i = from; i < to; i++)
96 valtable2[i - from] = valtable[i];
99 for (i = to; i < LENGTH; i++)
100 valtable[i - l] = valtable[i];
101 valtable[LENGTH - l] = null;
103 // sensitivity for insertion
104 if (from2 > 0 && valtable[from2 - 1] != null)
106 sym = valtable[from2 - 1];
107 for (i = from2 - 1; i >= 0 && valtable[i] == sym; i--)
110 if ((to < LENGTH || from2 + l < LENGTH) && valtable2[l - 1] != null)
112 sym = valtable2[l - 1];
113 for (i = l - 1; i >= 0; i--)
118 for (i = LENGTH - 1; i >= from2 + l; i--)
119 valtable[i] = valtable[i - l];
122 for (i = from2; i < from2 + l; i++)
123 valtable[i] = valtable2[i - from2];
124 Console.WriteLine ("from {0}, to {1}, moveto {2}.\n", from, to, from2);
126 MText mt2 = mt.Dup ();
128 mt.Ins (from2, mt2, from, to);
131 static bool Compare ()
133 for (int i = 0; i < LENGTH; i++)
135 object val = mt.GetProp (i, key);
137 if (valtable[i] != (MSymbol) val)
139 Console.WriteLine ("valtable[{0}] is {1}, GetProp returned {2}",
141 valtable[i] == null ? MSymbol.nil : valtable[i],
142 val == null ? MSymbol.nil : val);
151 for (int i = 0; i < LENGTH; i++)
152 Console.WriteLine ("{0} {1} :", i, valtable[i]);
155 public static void Main (string[] args)
157 Random r = new Random (int.Parse (args[0]));
158 int check = (args.Length > 1 ? int.Parse (args[1]) : 0xFFFFFFF);
160 for (int loop = 0; loop < 1000000; loop++)
164 Console.WriteLine ("--- loop = {0} ---\n", loop);
167 mt.DumpPropNested ();
173 from = r.Next (LENGTH);
174 to = r.Next (LENGTH) + 1;
175 } while (from == to);
200 TestPushProp (from, to, prop);
203 TestPopProp (from, to, key);
206 TestDelIns (from, to, r.Next (LENGTH - (to - from) + 1));
211 mt.DumpPropNested ();
213 if (Compare () == false)
215 Console.WriteLine ("");
217 Console.WriteLine ("Failed.");