public void ExpressionSetTest() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Peach>\n" + " <DataModel name=\"TheDataModel\">"+ " <Number name=\"TheNumber\" size=\"8\">"+ " <Relation type=\"count\" of=\"Array\" expressionSet=\"count + 1\" />"+ " </Number>"+ " <String name=\"Array\" value=\"1\" maxOccurs=\"100\"/>"+ " </DataModel>"+ "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); Number num = dom.dataModels[0][0] as Number; Dom.Array array = dom.dataModels[0][1] as Dom.Array; array.origionalElement = array[0]; array.hasExpanded = true; array.Add(new Dom.String("Child2") { DefaultValue = new Variant("2") }); array.Add(new Dom.String("Child3") { DefaultValue = new Variant("3") }); Assert.AreEqual(4, (int)num.InternalValue); Assert.AreEqual("123", ASCIIEncoding.ASCII.GetString(array.Value.ToArray())); }
// PERFORM_MUTATION // private void performMutation(DataElement obj) { Dom.Array objAsArray = (Dom.Array)obj; List <DataElement> items = new List <DataElement>(); for (int i = 0; i < objAsArray.Count; ++i) { items.Add(objAsArray[i]); } items.Reverse(); objAsArray.Clear(); for (int i = 0; i < items.Count; ++i) { objAsArray.Add(items[i]); } }
// PERFORM_MUTATION // private void performMutation(DataElement obj) { Dom.Array objAsArray = (Dom.Array)obj; List <DataElement> items = new List <DataElement>(); for (int i = 0; i < objAsArray.Count; ++i) { items.Add(objAsArray[i]); } var shuffledItems = context.Random.Shuffle(items.ToArray()); objAsArray.Clear(); for (int i = 0; i < shuffledItems.Length; ++i) { objAsArray.Add(shuffledItems[i]); } }