Skip to content

Commit

Permalink
(#63) WpfTeXFormulaExtensions: document and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Jan 12, 2023
1 parent 2e2514b commit d132658
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/WpfMath.Tests/RenderingTests.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module WpfMath.Tests.RenderingTests

open System.Windows.Media

open Xunit

open WpfMath.Parsers
Expand All @@ -8,15 +10,15 @@ open WpfMath.Rendering
let private parser = WpfTeXFormulaParser.Instance

[<Fact>]
let ``TexRenderer.RenderToBitmap should create an image of proper size``() =
let ``WpfTeXFormulaExtensions::RenderToBitmap should create an image of proper size``(): unit =
let formula = parser.Parse "2+2=2"
let environment = WpfTeXEnvironment.Create()
let bitmap = formula.RenderToBitmap environment
Assert.Equal(82, bitmap.PixelWidth)
Assert.Equal(17, bitmap.PixelHeight)

[<Fact>]
let ``TexRenderer.RenderToBitmap should create an image of proper size with offset``() =
let ``WpfTeXFormulaExtensions::RenderToBitmap should create an image of proper size with offset``(): unit =
let formula = parser.Parse "2+2=2"
let environment = WpfTeXEnvironment.Create()
let margin = 50
Expand All @@ -28,11 +30,18 @@ let ``TexRenderer.RenderToBitmap should create an image of proper size with offs
Assert.Equal(formulaHeight + (margin * 2), bitmap.PixelHeight)

[<Fact>]
let ``TexRenderer.RenderToBitmap should work with different DPI``() =
let ``WpfTeXFormulaExtensions::RenderToBitmap should work with different DPI``(): unit =
let formula = parser.Parse "2+2=2"
let environment = WpfTeXEnvironment.Create()
let bitmap = formula.RenderToBitmap(environment, dpi = 192.0)
Assert.Equal(163, bitmap.PixelWidth)
Assert.Equal(34, bitmap.PixelHeight)
Assert.Equal(192.0, bitmap.DpiX)
Assert.Equal(192.0, bitmap.DpiY)

[<Fact>]
let ``WpfTeXFormulaExtensions::RenderToGeometry should work``() =
let formula = parser.Parse "2+2=2"
let environment = WpfTeXEnvironment.Create()
let geometry = formula.RenderToGeometry(environment) :?> GeometryGroup
Assert.Equal(5, geometry.Children.Count)
4 changes: 2 additions & 2 deletions src/WpfMath/Rendering/WpfTeXFormulaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class WpfTeXFormulaExtensions
/// <summary>Default DPI for WPF.</summary>
private const int DefaultDpi = 96;

public static Geometry RenderToGeometry( // TODO: Tests for this method.
public static Geometry RenderToGeometry(
this TexFormula formula,
TexEnvironment environment,
double scale = 20.0,
Expand All @@ -22,7 +22,7 @@ public static class WpfTeXFormulaExtensions
return geometry;
}

public static BitmapSource RenderToBitmap( // TODO: Tests for this method.
public static BitmapSource RenderToBitmap(
this TexFormula formula,
TexEnvironment environment,
double scale = 20.0,
Expand Down

0 comments on commit d132658

Please sign in to comment.