2 using System.Collections.Generic;
10 static MText mt = new MText ("0123456789");
11 static MSymbol key = MSymbol.PropertyKey ("bse",
12 MProperty.Flags.FrontSensitive
13 | MProperty.Flags.RearSensitive);
14 static MSymbol val0 = MSymbol.Of ("0");
15 static MSymbol val1 = MSymbol.Of ("1");
16 static MSymbol val2 = MSymbol.Of ("2");
17 static MProperty prop0 = new MProperty (key, val0);
18 static MProperty prop1 = new MProperty (key, val1);
19 static MProperty prop2 = new MProperty (key, val2);
21 static MSymbol[] valtable = new MSymbol[LENGTH];
23 static void TestPushProp (int from, int to, MProperty prop)
28 if (from > 0 && valtable[from] != null)
31 for (i = from - 1; i >= 0 && valtable[i] == sym; i--)
34 if (to < LENGTH && valtable[to - 1] != null)
36 sym = valtable[to - 1];
37 for (i = to; i < LENGTH && valtable[i] == sym; i++)
40 for (i = from; i < to; i++)
41 valtable[i] = (MSymbol) prop.Val;
42 Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop.Val);
44 mt.PushProp (from, to, prop);
47 static void TestPopProp (int from, int to, MSymbol key)
52 if (from > 0 && valtable[from] != null)
55 for (i = from - 1; i >= 0 && valtable[i] == sym; i--)
58 if (to < LENGTH && valtable[to - 1] != null)
60 sym = valtable[to - 1];
61 for (i = to; i < LENGTH && valtable[i] == sym; i++)
64 for (i = from; i < to; i++)
66 Console.WriteLine ("from {0}, to {1}, pop.\n", from, to);
68 mt.PopProp (from, to, key);
71 static void TestDelIns (int from, int to, int from2)
74 MSymbol[] valtable2 = new MSymbol[LENGTH];
77 // sensitivity for deletion
80 if (valtable[from - 1] != null)
82 sym = valtable[from - 1];
83 for (i = from - 1; i >= 0 && valtable[i] == sym; i--)
86 if (valtable[from] != null)
89 for (i = from; i < LENGTH && valtable[i] == sym; i++)
95 if (valtable[to - 1] != null)
97 sym = valtable[to - 1];
98 for (i = to - 1; i >= 0 && valtable[i] == sym; i--)
101 if (valtable[to] != null)
104 for (i = to; i < LENGTH && valtable[i] == sym; i++)
110 for (i = from; i < to; i++)
111 valtable2[i - from] = valtable[i];
114 for (i = to; i < LENGTH; i++)
115 valtable[i - l] = valtable[i];
116 valtable[LENGTH - l] = null;
118 // sensitivity for insertion
119 if (l < LENGTH && valtable[from2] != null)
121 sym = valtable[from2];
122 for (i = from2; i < LENGTH && valtable[i] == sym; i++)
125 if (from2 > 0 && valtable[from2 - 1] != null)
127 sym = valtable[from2 - 1];
128 for (i = from2 - 1; i >= 0 && valtable[i] == sym; i--)
131 if ((from > 0 || from2 > 0) && valtable2[0] != null)
134 for (i = 0; i < LENGTH && valtable2[i] == sym; i++)
137 if ((to < LENGTH || from2 + l < LENGTH) && valtable2[l - 1] != null)
139 sym = valtable2[l - 1];
140 for (i = l - 1; i >= 0; i--)
145 for (i = LENGTH - 1; i >= from2 + l; i--)
146 valtable[i] = valtable[i - l];
149 for (i = from2; i < from2 + l; i++)
150 valtable[i] = valtable2[i - from2];
151 Console.WriteLine ("from {0}, to {1}, moveto {2}.\n", from, to, from2);
153 MText mt2 = mt.Dup ();
155 mt.Ins (from2, mt2, from, to);
158 static bool Compare ()
160 for (int i = 0; i < LENGTH; i++)
162 object val = mt.GetProp (i, key);
164 if (valtable[i] != (MSymbol) val)
166 Console.WriteLine ("valtable[{0}] is {1}, GetProp returned {2}",
168 valtable[i] == null ? MSymbol.nil : valtable[i],
169 val == null ? MSymbol.nil : val);
178 for (int i = 0; i < LENGTH; i++)
179 Console.WriteLine ("{0} {1} :", i, valtable[i]);
182 public static void Main (string[] args)
184 Random r = new Random (int.Parse (args[0]));
185 int check = (args.Length > 1 ? int.Parse (args[1]) : 0xFFFFFFF);
187 for (int loop = 0; loop < 1000000; loop++)
191 Console.WriteLine ("--- loop = {0} ---\n", loop);
194 mt.DumpPropNested ();
200 from = r.Next (LENGTH);
201 to = r.Next (LENGTH) + 1;
202 } while (from == to);
227 TestPushProp (from, to, prop);
230 TestPopProp (from, to, key);
233 TestDelIns (from, to, r.Next (LENGTH - (to - from) + 1));
238 mt.DumpPropNested ();
240 if (Compare () == false)
242 Console.WriteLine ("");
244 Console.WriteLine ("Failed.");