private readonly Dictionary<NameInstance, MutationCollection> mutations; //only contains atomic keys that change into composite ones I think public CompositeNameInstance GetRoot() { if (mutations.Count != 0) { root = (CompositeNameInstance)GetMutatedState(root, mutations); mutations.Clear(); root.SetParent(null);//sets all parent references } return root; }
public void asososTest() { var a = new AtomicNameInstance('a', new LinearPosition(0)); var s = new AtomicNameInstance('s', new LinearPosition(1)); var o = new AtomicNameInstance('o', new LinearPosition(2)); var s_ = new AtomicNameInstance('s', new LinearPosition(3)); var o_ = new AtomicNameInstance('o', new LinearPosition(4)); var s__ = new AtomicNameInstance('s', new LinearPosition(5)); var root = new CompositeNameInstance(new NameInstance[] { a, s, o, s_, o_, s__ }.ToList(), new LinearPosition(0)); root.SetParent(null); var inferrer = new NameInstanceNameInferrer(new[] { Notations.sos, Notations.aso }.ToReadOnlyList()); var result = inferrer.Match(root).ToList(); Contract.Assert(result.Count == 1); Contract.Assert(result[0].Select(match => (match.Binding.Name as Name).Notation).ContainsSameElements(Notations.aso.Notation, Notations.sos.Notation)); Contract.Assert(result[0][result[0].IndexOf(match => (match.Binding.Name as Name).Notation == Notations.aso)].Binding.Index.Index == 0); Contract.Assert(result[0][result[0].IndexOf(match => (match.Binding.Name as Name).Notation == Notations.sos)].Binding.Index.Index == 3); }
public void SinCosWithArgsTest() { var s = new AtomicNameInstance('s', new LinearPosition(0)); var i = new AtomicNameInstance('i', new LinearPosition(1)); var n = new AtomicNameInstance('n', new LinearPosition(2)); var sin = new CompositeNameInstance(new NameInstance[] { s, i, n }.ToList(), new LinearPosition(0)); var sinarg = new AtomicNameInstance('a', new LinearPosition(0)); var sinRoot = new CompositeNameInstance(new NameInstance[] { sin, sinarg }.ToList(), new LinearPosition(0)); var c = new AtomicNameInstance('c', new LinearPosition(0)); var o = new AtomicNameInstance('o', new LinearPosition(1)); var s_ = new AtomicNameInstance('s', new LinearPosition(2)); var cos = new CompositeNameInstance(new NameInstance[] { c, o, s_ }.ToList(), new LinearPosition(0)); var cosarg = new AtomicNameInstance('b', new LinearPosition(0)); var cosRoot = new CompositeNameInstance(new NameInstance[] { cos, cosarg }.ToList(), new LinearPosition(0)); var root = new CompositeNameInstance(new NameInstance[] { sinRoot, cosRoot }.ToList(), new LinearPosition(0)); root.SetParent(null); var result = inferrer.Match(root).ToList(); var test = result[0].IndexOf(match => match.Binding.Name == Notations.sin); Contract.Assert(result[0].Select(match => match.Binding.Name.Notation).ContainsSameElements(Notations.sin.Notation, Notations.a.Notation, Notations.cos.Notation, Notations.b.Notation)); Contract.Assert(result[0][result[0].IndexOf(match => (match.Binding.Name as Name).Notation == Notations.sin)].Binding.Index.Index == 0); Contract.Assert(result[0][result[0].IndexOf(match => (match.Binding.Name as Name).Notation == Notations.a)].Binding.Index.Index == 3); Contract.Assert(result[0][result[0].IndexOf(match => (match.Binding.Name as Name).Notation == Notations.cos)].Binding.Index.Index == 4); Contract.Assert(result[0][result[0].IndexOf(match => (match.Binding.Name as Name).Notation == Notations.b)].Binding.Index.Index == 7); }
public void SinCosWithArgsWithout4thTest() { var s = new AtomicNameInstance('s', new LinearPosition(0)); var i = new AtomicNameInstance('i', new LinearPosition(1)); var n = new AtomicNameInstance('n', new LinearPosition(2)); var sin = new CompositeNameInstance(new NameInstance[] { s, i, n }.ToList(), new LinearPosition(0)); var sinarg = new AtomicNameInstance('a', new LinearPosition(0)); var sinRoot = new CompositeNameInstance(new NameInstance[] { sin, sinarg }.ToList(), new LinearPosition(0)); var c = new AtomicNameInstance('c', new LinearPosition(0)); var o = new AtomicNameInstance('o', new LinearPosition(1)); var s_ = new AtomicNameInstance('s', new LinearPosition(2)); var cos = new CompositeNameInstance(new NameInstance[] { c, o, s_ }.ToList(), new LinearPosition(0)); var cosarg = new AtomicNameInstance('b', new LinearPosition(0)); var cosRoot = new CompositeNameInstance(new NameInstance[] { cos, cosarg }.ToList(), new LinearPosition(0)); var root = new CompositeNameInstance(new NameInstance[] { sinRoot, cosRoot }.ToList(), new LinearPosition(0)); root.SetParent(null); var result = inferrer.Match(root, new BitArray(new[] { false, false, false, true/*of the leaf 'a'*/, false, false, false, false })).ToList(); Contract.Assert(result.Count == 1); Contract.Assert(result[0].Select(match => (match.Binding.Name as Name).Notation).ContainsSameElements(Notations.sin.Notation/*, Notations.a*/, Notations.cos.Notation, Notations.b.Notation)); Contract.Assert(result[0][result[0].IndexOf(match => (match.Binding.Name as Name).Notation == Notations.sin)].Binding.Index.Index == 0); Contract.Assert(result[0][result[0].IndexOf(match => (match.Binding.Name as Name).Notation == Notations.cos)].Binding.Index.Index == 4); Contract.Assert(result[0][result[0].IndexOf(match => (match.Binding.Name as Name).Notation == Notations.b)].Binding.Index.Index == 7); }
public void SinCosTest() { var s = new AtomicNameInstance('s', new LinearPosition(0)); var i = new AtomicNameInstance('i', new LinearPosition(1)); var n = new AtomicNameInstance('n', new LinearPosition(2)); var sinRoot = new CompositeNameInstance(new NameInstance[] { s, i, n }.ToList(), new LinearPosition(0)); var c = new AtomicNameInstance('c', new LinearPosition(0)); var o = new AtomicNameInstance('o', new LinearPosition(1)); var s_ = new AtomicNameInstance('s', new LinearPosition(2)); var cosRoot = new CompositeNameInstance(new NameInstance[] { c, o, s_ }.ToList(), new LinearPosition(0)); var root = new CompositeNameInstance(new NameInstance[] { sinRoot, cosRoot }.ToList(), new LinearPosition(0)); root.SetParent(null); var result = inferrer.Match(root).ToList(); Contract.Assert(result.Count == 1); var test = result[0].Select(match => match.Binding).ToList(); Contract.Assert(result.Count == 1); Contract.Assert(Enumerable.SequenceEqual(result[0].Select(match => ((Name)match.Binding.Name).Notation), new[] { Notations.sin.Notation, Notations.cos.Notation })); Contract.Assert(result[0][0].Binding.Index.Index == 0); Contract.Assert(result[0][1].Binding.Index.Index == 3); }
public void SinPlusCosTest() { var s = new AtomicNameInstance('s', new LinearPosition(0)); var i = new AtomicNameInstance('i', new LinearPosition(1)); var n = new AtomicNameInstance('n', new LinearPosition(2)); var c = new AtomicNameInstance('c', new LinearPosition(3)); var o = new AtomicNameInstance('o', new LinearPosition(4)); var s_ = new AtomicNameInstance('s', new LinearPosition(5)); var root = new CompositeNameInstance(new NameInstance[] { s, i, n, c, o, s_ }.ToList(), new LinearPosition(0)); root.SetParent(null); SinPlusCosTest(root); root = new NameInstanceBinding(new BoxViewModel(new BoxCtor(new[] { new TextCtor("sincos") }.ToReadOnlyList(), getFontSize: getFontSize))).GetRoot(); SinPlusCosTest(root); var boxRoot = new BoxViewModel(); boxRoot.Elements.Insert(0, new TextCtor("ncos")); boxRoot.Elements.Insert(0, new TextCtor("si")); root = new NameInstanceBinding(boxRoot).GetRoot(); SinPlusCosTest(root); }
public void SinTest() { var s = new AtomicNameInstance('s', new LinearPosition(0)); var i = new AtomicNameInstance('i', new LinearPosition(1)); var n = new AtomicNameInstance('n', new LinearPosition(2)); var test = Notations.sos; var root = new CompositeNameInstance(new NameInstance[] { s, i, n }.ToList(), new LinearPosition(0)); root.SetParent(null); SinTest(root); var binding = new NameInstanceBinding(new BoxViewModel(new BoxCtor(new[] { new TextCtor("sin") }.ToReadOnlyList(), getFontSize: getFontSize))); root = binding.GetRoot(); SinTest(root); var boxRoot = new BoxViewModel(); boxRoot.Elements.Insert(0, new TextCtor("si")); boxRoot.Elements.Insert(2, new TextCtor("n")); root = new NameInstanceBinding(boxRoot).GetRoot(); SinTest(root); }
public void LeafTwoIdenticalNamesTest() { var treeLeafA = new AtomicNameInstance('d', new LinearPosition(0)); var treeLeafA2 = new AtomicNameInstance('d', new LinearPosition(1)); var root = new CompositeNameInstance(new NameInstance[] { treeLeafA, treeLeafA2 }.ToList(), new LinearPosition(0)); root.SetParent(null); LeafTwoIdenticalNamesTest(root); root = new NameInstanceBinding(new BoxViewModel(new BoxCtor(new[] { new TextCtor("d"), new TextCtor("d") }.ToReadOnlyList(), getFontSize: getFontSize))).GetRoot(); LeafTwoIdenticalNamesTest(root); var boxRoot = new BoxViewModel(); boxRoot.Elements.Insert(0, new TextCtor("d")); boxRoot.Elements.Insert(0, new TextCtor("d")); root = new NameInstanceBinding(boxRoot).GetRoot(); LeafTwoIdenticalNamesTest(root); }
public void TwoIdenticalLeafTest() { var treeLeafA = new AtomicNameInstance('a', new LinearPosition(0)); var treeLeafA2 = new AtomicNameInstance('a', new LinearPosition(1)); var root = new CompositeNameInstance(new NameInstance[] { treeLeafA, treeLeafA2 }.ToList(), new LinearPosition(0)); root.SetParent(null); var result = inferrer.Match(root).ToList(); Contract.Assert(result.Count == 1); Contract.Assert(result[0].Count == 2); Contract.Assert(Contract.ForAll(result, f => f.Sum(match => match.Occupation.Cast<bool>().Count(_ => _)) == result[0].Count));//counts the bits. There must be one bit per leaf Assert(result, new[] { new Expectation(Notations.a, 0), new Expectation(Notations.a, 1) }); }