Ejemplo n.º 1
0
		public void RootWithTextTest()
		{
			var root = new BoxViewModel(new Boxctor(new Textctor("b").ToSingletonReadOnlyList(), getFontSize: @null => 30));

			var binding = new NameInstanceBinding(root);
			var rootContainingb = binding.GetRoot();

			Contract.Assert(rootContainingb.Elements.Count == 1);
			Contract.Assert((rootContainingb.Elements[0] as AtomicNameInstance).Value == 'b');

			root.Elements.Insert(1, new Textctor("a"));//binding.WithText("a", 1, root);
			var rootContainingba = binding.GetRoot();
			Contract.Assert(rootContainingba.Elements.Count == 2);
			Contract.Assert((rootContainingba.Elements[0] as AtomicNameInstance).Value == 'b');
			Contract.Assert((rootContainingba.Elements[1] as AtomicNameInstance).Value == 'a');

			root.Elements.RemoveAt(0);//binding.Without(root, 0, 1);
			var rootContaininga = binding.GetRoot();
			Contract.Assert(rootContaininga.Elements.Count == 1);
			Contract.Assert((rootContaininga.Elements[0] as AtomicNameInstance).Value == 'a');

			root.Elements.Insert(0, new Textctor("c"));//binding.WithText("c", 0, root);
			var rootContainingca = binding.GetRoot();
			Contract.Assert(rootContainingca.Elements.Count == 2);
			Contract.Assert((rootContainingca.Elements[0] as AtomicNameInstance).Value == 'c');
			Contract.Assert((rootContainingca.Elements[1] as AtomicNameInstance).Value == 'a');

			root.Elements.Insert(0, new Textctor("d"));//binding.WithText("d", 0, root);
			root.Elements.RemoveAt(1);//binding.Without(root, 1, "c".Length);
			var rootContainingda = binding.GetRoot();
			Contract.Assert(rootContainingda.Elements.Count == 2);
			Contract.Assert((rootContainingda.Elements[0] as AtomicNameInstance).Value == 'd');
			Contract.Assert((rootContainingda.Elements[1] as AtomicNameInstance).Value == 'a');


			root.Elements.RemoveAt(0);//binding.Without(root, 0, "d".Length);
			rootContaininga = binding.GetRoot();
			Contract.Assert(rootContaininga.Elements.Count == 1);
			Contract.Assert((rootContaininga.Elements[0] as AtomicNameInstance).Value == 'a');

			root.Elements.Insert(0, new Textctor("e"));//binding.WithText("e", 0, root);
			root.Elements.RemoveAt(1);//binding.Without(root, 1, "a".Length);
			var rootContaininge = binding.GetRoot();
			Contract.Assert(rootContaininge.Elements.Count == 1);
			Contract.Assert((rootContaininge.Elements[0] as AtomicNameInstance).Value == 'e');

			root.Elements.Insert(1, new Textctor("fh"));//binding.WithText("fh", 1, root);
			root.Elements.Insert(2, new Textctor("g"));//binding.WithText("g", 2, root);
			var rootContainingefgh = binding.GetRoot();
			Contract.Assert(rootContainingefgh.Elements.Count == 4);
			Contract.Assert("efgh".SequenceEqual((rootContainingefgh.Elements.Select(element => ((AtomicNameInstance)element).Value))));

		}
Ejemplo n.º 2
0
		public void RootWithBCTest()
		{
			var root = new BoxViewModel(new Boxctor(new Compositionctor(boxes => new NaryOperatorViewModel(boxes, false), new Boxctor(new Textctor("t").ToSingletonReadOnlyList()), new Boxctor()).ToSingletonReadOnlyList()
																	 , getFontSize: @null => 30));

			var main = ((BoxCompositionViewModel)root.Elements[0]).Boxes[0];
			var limit = ((BoxCompositionViewModel)root.Elements[0]).Boxes[1];


			var binding = new NameInstanceBinding(root);
			dynamic getRoot = binding.GetRoot();

			Contract.DynamicAssert(getRoot.Elements.Count == 1);
			Contract.DynamicAssert(getRoot.Elements[0].Elements.Count == 2);
			Contract.DynamicAssert(getRoot.Elements[0].Elements[0].Elements.Count == 1);
			Contract.DynamicAssert(getRoot.Elements[0].Elements[0].Elements[0].Value == 't');
			Contract.DynamicAssert(getRoot.Elements[0].Elements[1].Elements.Count == 0);
			//							  .root box   .Nary       .Nary box
			//										   boxes	   elements 
		}
Ejemplo n.º 3
0
		public void DiacriticTest()
		{
			var root = new BoxViewModel(new Boxctor(new Textctor("é").ToSingletonReadOnlyList(), getFontSize: @null => 30));
			var binding = new NameInstanceBinding(root);
			Contract.Assert(binding.GetRoot().Elements.Count == 1);
			Contract.Assert(binding.GetRoot().Elements[0] is CompositeNameInstance);
			var eAcuteBC = (CompositeNameInstance)binding.GetRoot().Elements[0];
			Contract.Assert(eAcuteBC.Elements.Count == 1);
			Contract.Assert(eAcuteBC.Position is LinearPosition);
			Contract.Assert(eAcuteBC.Elements[0] is CompositeNameInstance);
			var eAcuteBox = (CompositeNameInstance)eAcuteBC.Elements[0];
			Contract.Assert(eAcuteBox.Elements.Count == 1);
			Contract.Assert(eAcuteBox.Position is DiacriticPosition);
			Contract.Assert(eAcuteBox.Elements[0] is AtomicNameInstance);
			var eAcuteGlyph = (AtomicNameInstance)eAcuteBox.Elements[0];
			Contract.Assert(eAcuteGlyph.Value == 'e');//stripped from acute

			root.Elements.Insert(1, new Textctor("ä"));//binding.WithText("ä", 1, root);
			Contract.Assert(binding.GetRoot().Elements.Count == 2);
			Contract.Assert(binding.GetRoot().Elements[0] is CompositeNameInstance);
			eAcuteBC = (CompositeNameInstance)binding.GetRoot().Elements[0];
			Contract.Assert(eAcuteBC.Elements.Count == 1);
			Contract.Assert(eAcuteBC.Position is LinearPosition);
			Contract.Assert(eAcuteBC.Elements[0] is CompositeNameInstance);
			eAcuteBox = (CompositeNameInstance)eAcuteBC.Elements[0];
			Contract.Assert(eAcuteBox.Elements.Count == 1);
			Contract.Assert(eAcuteBox.Position is DiacriticPosition);
			Contract.Assert(eAcuteBox.Elements[0] is AtomicNameInstance);
			eAcuteGlyph = (AtomicNameInstance)eAcuteBox.Elements[0];
			Contract.Assert(eAcuteGlyph.Value == 'e');//stripped from acute

			Contract.Assert(binding.GetRoot().Elements[1] is CompositeNameInstance);
			var aTremaBC = (CompositeNameInstance)binding.GetRoot().Elements[1];
			Contract.Assert(aTremaBC.Elements.Count == 1);
			Contract.Assert(aTremaBC.Position is LinearPosition);
			Contract.Assert(aTremaBC.Elements[0] is CompositeNameInstance);
			var aTremaBox = (CompositeNameInstance)aTremaBC.Elements[0];
			Contract.Assert(aTremaBox.Elements.Count == 1);
			Contract.Assert(aTremaBox.Position is DiacriticPosition);
			Contract.Assert(aTremaBox.Elements[0] is AtomicNameInstance);
			eAcuteGlyph = (AtomicNameInstance)aTremaBox.Elements[0];
			Contract.Assert(eAcuteGlyph.Value == 'a');//stripped from trema
		}
Ejemplo n.º 4
0
		public void ComplexTest()
		{
			var root = new BoxViewModel(new Boxctor(new Textctor("a").ToSingletonReadOnlyList(), getFontSize: @null => 30));
			var bindingBefore = new NameInstanceBinding(root);
			var untouchedBinding = new NameInstanceBinding(root);

			var boxWithTextte = new Boxctor(new Textctor("té").ToSingletonReadOnlyList());
			var bc1 = new Compositionctor(boxes => new NaryOperatorViewModel(boxes, false), new Boxctor(), new Boxctor(), boxWithTextte);

			root.Elements.Insert(1, bc1);
			root.Elements.Insert(0, bc1);

			var bindingInCtor = new NameInstanceBinding(root);

			foreach (var bindingRoot in new[] { bindingInCtor, bindingBefore }.Select(binding => binding.GetRoot()))
			{
				Contract.Assert(bindingRoot.Elements.Count == 3);
				Contract.Assert(bindingRoot.Elements.Select(e => e.GetType()).SequenceEqual(new[] { typeof(CompositeNameInstance), typeof(AtomicNameInstance), typeof(CompositeNameInstance) }));

				Contract.Assert(((CompositeNameInstance)bindingRoot.Elements[0]).Elements.Count == 3);
				Contract.Assert(((AtomicNameInstance)bindingRoot.Elements[1]).Value == 'a');
				Contract.Assert(((CompositeNameInstance)bindingRoot.Elements[2]).Elements.Count == 3);

				Contract.Assert(((CompositeNameInstance)((CompositeNameInstance)bindingRoot.Elements[0]).Elements[0]).Elements.Count == 0);
				Contract.Assert(((CompositeNameInstance)((CompositeNameInstance)bindingRoot.Elements[0]).Elements[1]).Elements.Count == 0);

				var boxContainingte = (CompositeNameInstance)((CompositeNameInstance)bindingRoot.Elements[0]).Elements[2];
				Contract.Assert(boxContainingte.Elements.Count == 2);
				Contract.Assert(boxContainingte.Elements[0] is AtomicNameInstance);
				Contract.Assert(boxContainingte.Elements[1] is CompositeNameInstance);
				Contract.Assert(((CompositeNameInstance)boxContainingte.Elements[1]).Elements[0].Position is DiacriticPosition);
				Contract.Assert(((CompositeNameInstance)((CompositeNameInstance)boxContainingte.Elements[1]).Elements[0]).Elements[0].Position.Equals(new LinearPosition(0)));
			}

			((BoxCompositionViewModel)root.Elements[0]).RemoveAt(0);//removes empty box in first bc
			((BoxCompositionViewModel)root.Elements[2]).Boxes[2].Elements.RemoveAt(0);//removes t in second bc's third box


			var boxCompositionOfWhichOneBoxIsRemoved = (CompositeNameInstance)untouchedBinding.GetRoot().Elements[0];
			Contract.Assert(((CompositeNameInstance)boxCompositionOfWhichOneBoxIsRemoved.Elements[0]).Elements.Count == 0);
			Contract.Assert(((CompositeNameInstance)boxCompositionOfWhichOneBoxIsRemoved.Elements[1]).Elements.Count == 2);

			var boxCompositionWhoseThirdBoxLost_t = (CompositeNameInstance)untouchedBinding.GetRoot().Elements[2];
			var boxWhoLost_t = (CompositeNameInstance)boxCompositionWhoseThirdBoxLost_t.Elements[2];
			Contract.Assert(boxWhoLost_t.Position is NaryPosition);
			var boxCompositionDiacritic = (CompositeNameInstance)boxWhoLost_t.Elements[0];
			Contract.Assert(boxCompositionDiacritic.Position is LinearPosition);//the box composition that is the diacritic has linear position, as it is positioned in a box (at lienar pos 1)
			Contract.Assert(boxCompositionDiacritic.Elements.Count == 1);
			var diacritic = (CompositeNameInstance)boxCompositionDiacritic.Elements[0];
			Contract.Assert(diacritic.Position is DiacriticPosition);
			Contract.Assert((diacritic.Elements[0] as AtomicNameInstance)?.Value == 'e');
		}
Ejemplo n.º 5
0
		public void RootWithBCInBCTest()
		{
			var root = new BoxViewModel(new Boxctor(new Compositionctor(boxes => new NaryOperatorViewModel(boxes, false), new Boxctor(new Compositionctor(boxes => new NaryOperatorViewModel(boxes, false), new Boxctor(), new Boxctor()).ToSingletonReadOnlyList()), new Boxctor()).ToSingletonReadOnlyList()
																	 , getFontSize: @null => 30));


			//the root is a box with a Nary where the second box is empty but the first contains a Nary with two empty boxes
			var binding = new NameInstanceBinding(root);
			Contract.Assert(binding.GetRoot().Elements.Count == 1);
			var bc1 = (CompositeNameInstance)binding.GetRoot().Elements[0];
			Contract.Assert(bc1.Elements.Count == 2);
			var boxInBc1 = (CompositeNameInstance)bc1.Elements[0];
			Contract.Assert(boxInBc1.Elements.Count == 1);
			var bc2 = (CompositeNameInstance)boxInBc1.Elements[0];
			Contract.Assert(bc2.Elements.Count == 2);
			Contract.Assert(((CompositeNameInstance)bc2.Elements[0]).Elements.Count == 0);
			Contract.Assert(((CompositeNameInstance)bc2.Elements[1]).Elements.Count == 0);

			var box2InBc1 = (CompositeNameInstance)bc1.Elements[1];
			Contract.Assert(box2InBc1.Elements.Count == 0);
		}
Ejemplo n.º 6
0
		public void DiacriticTest()
		{
			//new BoxViewModel(new BoxCtor(new BoxCompCtor(boxes => DiacriticArranger(boxes), new BoxCtor()), getFontSize: getFontSize));
			var boxRoot = new BoxViewModel(new BoxCtor(new TextCtor("é").ToSingletonList(), getFontSize: getFontSize));
			CompositeNameInstance root = new NameInstanceBinding(boxRoot).GetRoot();

			var result = inferrer.Match(root).ToList();

		}
Ejemplo n.º 7
0
		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);
		}
Ejemplo n.º 8
0
		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);
		}
Ejemplo n.º 9
0
		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);
		}