Exemplo n.º 1
0
        private void RunScriptTest(string input, Func <IMathAtom, IMathList> scriptGetter, MathAtomType[][] atomTypes, string output)
        {
            var builder = new MathListBuilder(input);
            var list    = builder.Build();

            Assert.Null(builder.Error);
            ExpandGroups(list);
            CheckAtomTypes(list, atomTypes[0]);

            IMathAtom firstAtom = list[0];
            var       types     = atomTypes[1];

            if (types.Count() > 0)
            {
                Assert.NotNull(scriptGetter(firstAtom));
            }
            var scriptList = scriptGetter(firstAtom);

            CheckAtomTypes(scriptList, atomTypes[1]);
            if (atomTypes.Count() == 3)
            {
                // one more level
                var firstScript      = scriptList[0];
                var scriptScriptList = scriptGetter(firstScript);
                CheckAtomTypes(scriptScriptList, atomTypes[2]);
            }

            string latex = MathListBuilder.MathListToString(list);

            Assert.Equal(output, latex);
        }
Exemplo n.º 2
0
        public void TestLeftRight(
            string input,
            MathAtomType[] expectedOutputTypes,
            int innerIndex,
            MathAtomType[] expectedInnerTypes,
            string leftBoundary,
            string rightBoundary,
            string expectedLatex)
        {
            var builder = new MathListBuilder(input);
            var list    = builder.Build();

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

            ExpandGroups(list);
            CheckAtomTypes(list, expectedOutputTypes);
            var inner = list[innerIndex] as Inner;

            Assert.NotNull(inner);
            CheckAtomTypeAndNucleus(inner, MathAtomType.Inner, "");

            CheckAtomTypes(inner.InnerList, expectedInnerTypes);
            CheckAtomTypeAndNucleus(inner.LeftBoundary, MathAtomType.Boundary, leftBoundary);
            CheckAtomTypeAndNucleus(inner.RightBoundary, MathAtomType.Boundary, rightBoundary);

            var latex = MathListBuilder.MathListToString(list);

            Assert.Equal(expectedLatex, latex);
        }
Exemplo n.º 3
0
        public void TestErrors(string badInput)
        {
            var builder = new MathListBuilder(badInput);
            var list    = builder.Build();

            Assert.Null(list);
            Assert.NotNull(builder.Error);
        }
Exemplo n.º 4
0
        public void TestBuilder(string input, MathAtomType[] atomTypes, string output)
        {
            var builder = new MathListBuilder(input);
            var list    = builder.Build();

            Assert.Null(builder.Error);

            ExpandGroups(list);
            CheckAtomTypes(list, atomTypes);


            var latex = MathListBuilder.MathListToString(list);

            Assert.Equal(output, latex);
        }
Exemplo n.º 5
0
        public void TestListCopyWithFusedItems()
        {
            var builder = new MathListBuilder("12+x");
            var list    = builder.Build();

            var finalized  = list.FinalizedList();
            var fusedCount = finalized.Sum(atom => atom.FusedAtoms?.Count ?? 0);

            Assert.Equal(2, fusedCount);

            var copy           = AtomCloner.Clone(finalized, true);
            var fusedCopyCount = copy.Sum(atom => atom.FusedAtoms?.Count ?? 0);

            Assert.Equal(2, fusedCopyCount);
        }
Exemplo n.º 6
0
        public void TestSymbols()
        {
            string str     = @"5\times3^{2\div2}";
            var    builder = new MathListBuilder(str);
            var    list    = builder.Build();

            Assert.NotNull(list);
            Assert.Equal(3, list.Atoms.Count());

            CheckAtomTypeAndNucleus(list[0], MathAtomType.Number, "5");
            CheckAtomTypeAndNucleus(list[1], MathAtomType.BinaryOperator, "\u00D7");
            CheckAtomTypeAndNucleus(list[2], MathAtomType.Number, "3");

            var superList = list[2].Superscript;

            Assert.NotNull(superList);
            Assert.Equal(3, superList.Atoms.Count());
            CheckAtomTypeAndNucleus(superList[0], MathAtomType.Number, "2");
            CheckAtomTypeAndNucleus(superList[1], MathAtomType.BinaryOperator, "\u00F7");
            CheckAtomTypeAndNucleus(superList[2], MathAtomType.Number, "2");
        }
Exemplo n.º 7
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);
        }