public void TestAddErrors() { var list = new MathList(); Assert.Throws <InvalidOperationException>(() => list.Add(null)); Assert.Throws <InvalidOperationException>(() => list.Add(MathAtoms.Create(MathAtomType.Boundary, ""))); }
public void TestAtomInit() { var atom = MathAtoms.Create(MathAtomType.Open, "("); Assert.Equal(MathAtomType.Open, atom.AtomType); Assert.Equal("(", atom.Nucleus); var atom2 = MathAtoms.Create(MathAtomType.Radical, "("); Assert.Equal(MathAtomType.Radical, atom2.AtomType); Assert.Equal("(", atom2.Nucleus); }
public void TestScripts() { var atom = MathAtoms.Create(MathAtomType.Open, "("); Assert.True(atom.ScriptsAllowed); atom.Subscript = new MathList(); Assert.NotNull(atom.Subscript); atom.Superscript = new MathList(); Assert.NotNull(atom.Superscript); var atom2 = MathAtoms.Create(MathAtomType.Boundary, "("); Assert.False(atom2.ScriptsAllowed); atom2.Subscript = null; Assert.Null(atom2.Subscript); atom2.Superscript = null; Assert.Null(atom2.Superscript); var list = new MathList(); Assert.ThrowsAny <Exception>(() => atom2.Subscript = list); Assert.ThrowsAny <Exception>(() => atom2.Superscript = list); }
public void TestCopyInner() { var atom1 = MathAtoms.Placeholder; var atom2 = MathAtoms.Times; var atom3 = MathAtoms.Divide; var list = MathLists.WithAtoms(atom1, atom2, atom3); var inner = new Inner { InnerList = list, LeftBoundary = MathAtoms.Create(MathAtomType.Boundary, "("), RightBoundary = MathAtoms.Create(MathAtomType.Boundary, ")") }; Assert.Equal(MathAtomType.Inner, inner.AtomType); var copy = new Inner(inner, false); CheckClone(inner, copy); CheckClone(inner.InnerList, copy.InnerList); CheckClone(inner.LeftBoundary, copy.LeftBoundary); CheckClone(inner.RightBoundary, copy.RightBoundary); }
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 TestCopy() { var list = new MathList { MathAtoms.Placeholder, MathAtoms.Times, MathAtoms.Divide }; var list2 = new MathList { MathAtoms.Divide, MathAtoms.Times }; var open = MathAtoms.Create(MathAtomType.Open, "("); open.Subscript = list; open.Superscript = list2; var clone = AtomCloner.Clone(open, false); CheckClone(open, clone); CheckClone(open.Superscript, clone.Superscript); CheckClone(open.Subscript, clone.Subscript); }
public void TestInner() { var mathList = new MathList { new Inner { InnerList = new MathList { MathAtoms.ForCharacter('x'), }, LeftBoundary = MathAtoms.Create(MathAtomType.Boundary, '('), RightBoundary = MathAtoms.Create(MathAtomType.Boundary, ')') } }; var display = Typesetter <TFont, TGlyph> .CreateLine(mathList, _font, _context, LineStyle.Display); Assert.Equal(LinePosition.Regular, display.LinePosition); Assert.Equal(new Range(0, 1), display.Range); Assert.False(display.HasScript); Assert.Equal(Range.UndefinedInt, display.IndexInParent); Assert.Single(display.Displays); var display2 = display.Displays[0] as ListDisplay <TFont, TGlyph>; Assert.Equal(LinePosition.Regular, display2.LinePosition); Assert.Equal(new PointF(), display2.Position); Assert.Equal(new Range(0, 1), display2.Range); Assert.False(display2.HasScript); Assert.Equal(Range.UndefinedInt, display2.IndexInParent); Assert.Equal(3, display2.Displays.Count); var glyph = display2.Displays[0] as GlyphDisplay <TFont, TGlyph>; Assert.Equal(new PointF(), glyph.Position); Assert.Equal(Range.NotFound, glyph.Range); Assert.False(glyph.HasScript); var display3 = display2.Displays[1] as ListDisplay <TFont, TGlyph>; Assert.Equal(LinePosition.Regular, display3.LinePosition); Assertions.ApproximatePoint(10, 0, display3.Position, 0.01); Assert.Equal(new Range(0, 1), display3.Range); Assert.False(display3.HasScript); Assert.Equal(Range.UndefinedInt, display3.IndexInParent); Assert.Single(display3.Displays); var line = display3.Displays[0] as TextLineDisplay <TFont, TGlyph>; Assert.Single(line.Atoms); Assert.Equal("x", line.StringText()); Assert.Equal(new PointF(), line.Position); Assert.False(line.HasScript); var glyph2 = display2.Displays[2] as GlyphDisplay <TFont, TGlyph>; Assertions.ApproximatePoint(20, 0, glyph2.Position, 0.01); Assert.Equal(Range.NotFound, glyph2.Range); Assert.False(glyph2.HasScript); Assert.Equal(display.Ascent, display2.Ascent); Assert.Equal(display.Descent, display2.Descent); Assert.Equal(display.Width, display2.Width); Assertions.ApproximatelyEqual(14, display.Ascent, 0.01); Assertions.ApproximatelyEqual(4, display.Descent, 0.01); Assertions.ApproximatelyEqual(30, display.Width, 0.01); }