예제 #1
0
        public void TestAppend()
        {
            var list1 = new MathList();
            var atom1 = MathAtoms.Placeholder;
            var atom2 = MathAtoms.Operator("+", false);
            var atom3 = MathAtoms.Operator("-", false);

            list1.Add(atom1);
            list1.Add(atom2);
            list1.Add(atom3);

            var list2 = new MathList();
            var atom5 = MathAtoms.Times;
            var atom6 = MathAtoms.Divide;

            list2.Add(atom5);
            list2.Add(atom6);

            Assert.Equal(3, list1.Count);
            Assert.Equal(2, list2.Count);

            list1.Append(list2);
            Assert.Equal(5, list1.Count);
            Assert.Equal(atom5, list1[3]);
            Assert.Equal(atom6, list1[4]);
        }
예제 #2
0
        public void TestCustom()
        {
            var input   = @"\lcm(a,b)";
            var builder = new MathListBuilder(input);
            var list    = builder.Build();

            Assert.Null(list);
            Assert.NotNull(builder.Error);

            MathAtoms.AddLatexSymbol("lcm", MathAtoms.Operator("lcm", false));
            var builder2 = new MathListBuilder(input);
            var list2    = builder2.Build();

            ExpandGroups(list2);
            CheckAtomTypes(list2, MathAtomType.LargeOperator, MathAtomType.Open,
                           MathAtomType.Variable, MathAtomType.Punctuation, MathAtomType.Variable,
                           MathAtomType.Close);
            var latex = MathListBuilder.MathListToString(list2);

            Assert.Equal(@"\lcm (a,b)", latex);
        }
예제 #3
0
        public void TestInsert()
        {
            var list = new MathList();

            Assert.Empty(list);
            var atom = MathAtoms.Placeholder;

            list.Insert(0, atom);
            Assert.Single(list);
            Assert.Equal(atom, list[0]);
            var atom2 = MathAtoms.Operator("+", false);

            list.Insert(0, atom2);
            Assert.Equal(2, list.Count);
            Assert.Equal(atom2, list[0]);
            Assert.Equal(atom, list[1]);
            var atom3 = MathAtoms.Create(MathAtomType.Variable, "x");

            list.Insert(2, atom3);
            Assert.Equal(3, list.Count);
            Assert.Equal(atom2, list[0]);
            Assert.Equal(atom, list[1]);
            Assert.Equal(atom3, list[2]);
        }