Beispiel #1
0
        public void TestFraction(string latex, double lineThickness) =>
        TestOuter(latex, 1, 27.54, 17.72, 10,
                  d => {
            var fraction = Assert.IsType <FractionDisplay <TFont, TGlyph> >(d);
            Assert.Equal(new Range(0, 1), fraction.Range);
            Assert.Equal(new PointF(), fraction.Position);
            Assert.False(fraction.HasScript);
            Approximately.Equal(lineThickness, fraction.LineThickness);

            TestList(1, 14, 4, 10, 0, 13.54, LinePosition.Regular, Range.UndefinedInt,
                     dd => {
                var subNumerator = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(dd);
                Assert.Single(subNumerator.Atoms);
                AssertText("1", subNumerator);
                Assert.Equal(new PointF(), subNumerator.Position);
                Assert.Equal(new Range(0, 1), subNumerator.Range);
                Assert.False(subNumerator.HasScript);
            })(fraction.Numerator);

            TestList(1, 14, 4, 10, 0, -13.72, LinePosition.Regular, Range.UndefinedInt,
                     dd => {
                var subDenominator = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(dd);
                Assert.Single(subDenominator.Atoms);
                AssertText("3", subDenominator);
                Assert.Equal(new PointF(), subDenominator.Position);
                Assert.Equal(new Range(0, 1), subDenominator.Range);
                Assert.False(subDenominator.HasScript);
            })(fraction.Denominator);
        });
Beispiel #2
0
 public void TestSuperSubscript() =>
 TestOuter("x^2_1", 1, 19.48, 8.92, 17.32,
           d => {
     var line = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
     Assert.Single(line.Atoms);
     AssertText("x", line);
     Assert.Equal(new PointF(), line.Position);
     Assert.True(line.HasScript);
 },
           TestList(1, 9.8, 2.8, 7, 10.32, 9.68, LinePosition.Superscript, 0,
                    d => {
     var line2 = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
     Assert.Single(line2.Atoms);
     AssertText("2", line2);
     Assert.Equal(new PointF(), line2.Position);
     Assert.False(line2.HasScript);
     Approximately.Equal(20.12, 10.32 + line2.Ascent);
 }),
           // Because both subscript and superscript are present, coords are
           // different from the subscript-only case.
           TestList(1, 9.8, 2.8, 7, 10, -6.12, LinePosition.Subscript, 0,
                    d => {
     var line3 = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
     Assert.Single(line3.Atoms);
     AssertText("1", line3);
     Assert.Equal(new PointF(), line3.Position);
     Assert.False(line3.HasScript);
     Approximately.Equal(8.92, line3.Descent - (-6.12));
 }));
Beispiel #3
0
 public void TestLimit() =>
 TestOuter(@"\infty = \lim_{x\to 0^+} \frac{1}{x}", 4, 27.54, 21.186, 84.444,
           d => {
     var textBefore = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
     AssertText("∞=", textBefore);
     Assert.Equal(new Range(0, 2), textBefore.Range);
 },
           d => {
     var largeOp = Assert.IsType <LargeOpLimitsDisplay <TFont, TGlyph> >(d);
     Assert.Equal(new Range(2, 1), largeOp.Range);
     var largeOpText = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(largeOp.NucleusDisplay);
     AssertText("lim", largeOpText);
     Approximately.Equal(new PointF(31.111f, 0), largeOpText.Position);
     Assert.False(largeOpText.HasScript);
     TestList(3, 11.046, 2.8, 26, 38.111, -18.386, LinePosition.Regular, Range.UndefinedInt,
              d => {
         var subscript = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
         AssertText("x→0", subscript);
         Assert.Equal(3, subscript.Atoms.Count);
         Assert.Equal(new PointF(), subscript.Position);
         Assert.True(subscript.HasScript);
         Assert.Equal(new Range(0, 3), subscript.Range);
     },
              TestList(1, 7, 2, 5, 21, 4.046, LinePosition.Superscript, 2,
                       d => {
         var superscript = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
         AssertText("+", superscript);
         Assert.Single(superscript.Atoms);
         Assert.Equal(new PointF(), superscript.Position);
         Assert.False(superscript.HasScript);
         Assert.Equal(new Range(0, 1), superscript.Range);
     }))(largeOp.LowerLimit);
 },
           d => {
     var fraction = Assert.IsType <FractionDisplay <TFont, TGlyph> >(d);
     Assert.Equal(new Range(3, 1), fraction.Range);
     TestList(1, 14, 4, 10, 74.444, 13.54, LinePosition.Regular, Range.UndefinedInt,
              d => {
         var superscript = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
         AssertText("1", superscript);
         Assert.Single(superscript.Atoms);
         Assert.Equal(new PointF(), superscript.Position);
         Assert.False(superscript.HasScript);
         Assert.Equal(new Range(0, 1), superscript.Range);
     })(fraction.Numerator);
     TestList(1, 14, 4, 10, 74.444, -13.72, LinePosition.Regular, Range.UndefinedInt,
              d => {
         var subscript = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
         AssertText("x", subscript);
         Assert.Single(subscript.Atoms);
         Assert.Equal(new PointF(), subscript.Position);
         Assert.False(subscript.HasScript);
         Assert.Equal(new Range(0, 1), subscript.Range);
     })(fraction.Denominator);
 });
Beispiel #4
0
 System.Action <IDisplay <TFont, TGlyph> > TestList(int rangeMax, double ascent, double descent, double width, double x, double y,
                                                    LinePosition linePos, int indexInParent, params System.Action <IDisplay <TFont, TGlyph> >[] inspectors) => d => {
     var list = Assert.IsType <ListDisplay <TFont, TGlyph> >(d);
     Assert.False(list.HasScript);
     Assert.Equal(new Range(0, rangeMax), list.Range);
     Approximately.Equal(ascent, list.Ascent);
     Approximately.Equal(descent, list.Descent);
     Approximately.Equal(width, list.Width);
     Approximately.At(x, y, list.Position); // may change as we implement more details?
     Assert.Equal(linePos, list.LinePosition);
     Assert.Equal(indexInParent, list.IndexInParent);
     Assert.Collection(list.Displays, inspectors);
 };
Beispiel #5
0
 public void TestAccent() =>
 TestOuter(@"\bar{x}", 1, 19, 9, 10.16, d => {
     var accent = Assert.IsType <AccentDisplay <TFont, TGlyph> >(d);
     Assert.Equal(0, accent.Accent.ShiftDown);
     Assert.Equal('\u0304', accent.Accent.Glyph);
     Approximately.Equal(new PointF(0.16f, 5), accent.Accent.Position);
     Assert.False(accent.Accent.HasScript);
     Assert.Equal(new Range(0, 1), accent.Accent.Range);
     TestList(1, 14, 4, 10, 0, 0, LinePosition.Regular, Range.UndefinedInt,
              d => {
         var line = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
         Assert.Single(line.Atoms);
         AssertText("x", line);
         Assert.Equal(new PointF(), line.Position);
         Assert.False(line.HasScript);
     })(accent.Accentee);
 });