UnitConversionTests.cs 825 B

12345678910111213141516171819202122232425
  1. using System.Collections.Generic;
  2. using NUnit.Framework;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.UnitTests;
  5. [TestFixture]
  6. public class UnitConversionTests
  7. {
  8. [TestCase(Unit.Point, 1f, 1f)]
  9. [TestCase(Unit.Inch, 1f, 72f)]
  10. [TestCase(Unit.Feet, 1f, 864f)]
  11. [TestCase(Unit.Mil, 1000f, 72f)]
  12. [TestCase(Unit.Centimetre, 2.54f, 72f)] // 2.54 cm = 1 inch
  13. [TestCase(Unit.Millimetre, 25.4f, 72f)] // 25.4 mm = 1 inch
  14. [TestCase(Unit.Meter, 0.0254f, 72f)] // 0.0254 m = 1 inch
  15. public void ToPoints_ConvertsCorrectly(Unit unit, float input, float expected)
  16. {
  17. var result = input.ToPoints(unit);
  18. Assert.That(result, Is.EqualTo(expected));
  19. var result2 = (input * 2).ToPoints(unit);
  20. Assert.That(result2, Is.EqualTo(expected * 2));
  21. }
  22. }