Exemple #1
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]);
        }
        public void TestInsert()
        {
            var list = new MathList();

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

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

            list.Insert(0, atom2);
            Assert.Equal(2, list.Count);
            Assert.Equal(atom2, list[0]);
            Assert.Equal(atom, list[1]);
            var atom3 = new 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]);
        }
Exemple #3
0
 static void InsertAtAtomIndexAndAdvance(this MathList self, int atomIndex, MathAtom atom, ref MathListIndex advance, MathListSubIndexType advanceType)
 {
     if (atomIndex < 0 || atomIndex > self.Count)
     {
         throw new IndexOutOfRangeException($"Index {atomIndex} is out of bounds for list of size {self.Atoms.Count}");
     }
     // Test for placeholder to the right of index, e.g. \sqrt{‸■} -> \sqrt{2‸}
     if (atomIndex < self.Count && self[atomIndex] is Atoms.Placeholder placeholder)
     {
         atom.Superscript.Append(placeholder.Superscript);
         atom.Subscript.Append(placeholder.Subscript);
         self[atomIndex] = atom;
     }
     else
     {
         self.Insert(atomIndex, atom);
     }
     advance = advanceType switch
     {
         MathListSubIndexType.None => advance.Next,
         _ => advance.LevelUpWithSubIndex(advanceType, MathListIndex.Level0Index(0)),
     };
 }