using System; using System.Linq; using System.Utility; using Chernobyl.Extensions; using Chernobyl.Mathematics.Vectors; using NUnit.Framework; namespace Chernobyl.Mathematics.Geometry { [TestFixture, Description("Tests for the Func type")] class PlaneTests { #region To1D [Test, Description(".To1D throws an exception when given a width or height less than 2")] public void To1DThrowsWhenGivenNegativeWidthHeight() { // ReSharper disable ReturnValueOfPureMethodIsNotUsed Assert.Throws(() => Func.Passthrough().To1D(1, 5).ToArray()); Assert.Throws(() => Func.Passthrough().To1D(5, 1).ToArray()); // ReSharper restore ReturnValueOfPureMethodIsNotUsed } [Test, Description(".To1D outputs data in the correct order.")] public void To1DCorrectOrder() { var dataset2D = Func.Counter().To2D().To1D(3, 3).ToArray(); dataset2D.IsEqualTo(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, }, nameof(dataset2D)); } [Test, Description(".To1D converts a 2D dataset method to 1D dataset method")] public void To1DCorrectConversion() { var dataset2D = Func.Passthrough().To1D(5, 5).ToArray(); dataset2D.IsEqualTo(new Vector2d[] { (0.0, 1.0), (0.25, 1.0), (0.5, 1.0), (0.75, 1.0), (1.0, 1.0), (0.0, 0.75), (0.25, 0.75), (0.5, 0.75), (0.75, 0.75), (1.0, 0.75), (0.0, 0.5), (0.25, 0.5), (0.5, 0.5), (0.75, 0.5), (1.0, 0.5), (0.0, 0.25), (0.25, 0.25), (0.5, 0.25), (0.75, 0.25), (1.0, 0.25), (0.0, 0.0), (0.25, 0.0), (0.5, 0.0), (0.75, 0.0), (1.0, 0.0), }, "To1D result"); } #endregion // To1D #region SquarePredicate [Test, Description(".SquarePredicate throws when given bad arguments.")] public void SquarePredicateThrowsBadWidthHeight() { Assert.Throws(() => Plane.Predicate.Square((3, 4), 0, 1), "bad width argument must cause exception"); Assert.Throws(() => Plane.Predicate.Square((3, 4), 1, 0), "bad height argument must cause exception"); } [Test, Description(".SquarePredicate returns correct result based on position.")] public void SquarePredicateReturnsCorrectResults() { var predicate = Plane.Predicate.Square((3, 4), 5, 6); // Left test predicate((2, 5)).IsFalse("left outside"); predicate((4, 5)).IsTrue("left inside"); // Right test predicate((9, 5)).IsFalse("right outside"); predicate((7, 5)).IsTrue("right inside"); // Top test predicate((4, 11)).IsFalse("top outside"); predicate((4, 9)).IsTrue("top inside"); // Bottom test predicate((4, 3)).IsFalse("bottom outside"); predicate((4, 5)).IsTrue("bottom inside"); } #endregion // SquarePredicate } }