Пример #1
0
 [Test] public void ToDegrees()
 {
     Assert.IsTrue(Compare.AlmostEqual(1f, Trig.ToDegrees(0.0174533), 1e5));
     Assert.IsTrue(Compare.AlmostEqual(33f, Trig.ToDegrees(0.575959), 1e5));
     Assert.IsTrue(Compare.AlmostEqual(74f, Trig.ToDegrees(1.29154), 1e5));
     Assert.IsTrue(Compare.AlmostEqual(89f, Trig.ToDegrees(1.55334), 1e5));
     Assert.IsTrue(Compare.AlmostEqual(90f, Trig.ToDegrees(1.5708), 1e5));
     Assert.IsTrue(Compare.AlmostEqual(91f, Trig.ToDegrees(1.58825), 1e5));
     Assert.IsTrue(Compare.AlmostEqual(123f, Trig.ToDegrees(2.14675), 1e5));
     Assert.IsTrue(Compare.AlmostEqual(198f, Trig.ToDegrees(3.45575), 1e5));
     Assert.IsTrue(Compare.AlmostEqual(255f, Trig.ToDegrees(4.45059), 1e5));
     Assert.IsTrue(Compare.AlmostEqual(313f, Trig.ToDegrees(5.46288), 1e5));
 }
Пример #2
0
        [Test] public void LengthSquared()
        {
            Reset(test: "LengthSquared", setsWithNewSeed: 100, nearRepeats: 1000, maxDegrees: 180);

            Walker(
                () => {
                var expected = 1;

                float actual = seed.normalized.LengthSquared();

                Assert.IsTrue(Compare.AlmostEqual(expected, actual));
            });
        }
Пример #3
0
 [Test] public void ToRadians()
 {
     Assert.IsTrue(Compare.AlmostEqual(0.0174533, Trig.ToRadians(1)));
     Assert.IsTrue(Compare.AlmostEqual(0.575959, Trig.ToRadians(33)));
     Assert.IsTrue(Compare.AlmostEqual(1.29154, Trig.ToRadians(74)));
     Assert.IsTrue(Compare.AlmostEqual(1.55334, Trig.ToRadians(89)));
     Assert.IsTrue(Compare.AlmostEqual(1.5708, Trig.ToRadians(90)));
     Assert.IsTrue(Compare.AlmostEqual(1.58825, Trig.ToRadians(91)));
     Assert.IsTrue(Compare.AlmostEqual(2.14675, Trig.ToRadians(123)));
     Assert.IsTrue(Compare.AlmostEqual(3.45575, Trig.ToRadians(198)));
     Assert.IsTrue(Compare.AlmostEqual(4.45059, Trig.ToRadians(255)));
     Assert.IsTrue(Compare.AlmostEqual(5.46288, Trig.ToRadians(313)));
 }
Пример #4
0
        [Test] public void AlmostEqualFloatingPoint()
        {
            Assert.IsFalse(Compare.AlmostEqual(a: 1.1f, b: 1.2f, minimumChange: 0.1f));
            Assert.IsTrue(Compare.AlmostEqual(a: 1.1f, b: 1.2f, minimumChange: 0.11f));

            Assert.IsFalse(Compare.AlmostEqual(a: 1.1f, b: 1.11f));
            Assert.IsTrue(Compare.AlmostEqual(a: 1.1f, b: 1.0999f));

            Assert.IsFalse(Compare.AlmostEqual(a: 103.11, b: 104, minimumChange: 0.5));
            Assert.IsTrue(Compare.AlmostEqual(a: 103.11, b: 104, minimumChange: 0.9));

            Assert.IsFalse(Compare.AlmostEqual(a: 123.45678, b: 123.45679));
            Assert.IsTrue(Compare.AlmostEqual(a: 123.456789, b: 123.45679));
        }
Пример #5
0
        [Test] public void AlmostEqualInteger()
        {
            Assert.IsFalse(Compare.AlmostEqual(a: 123L, b: 133L, minimumChange: 10L));
            Assert.IsTrue(Compare.AlmostEqual(a: 123L, b: 133L, minimumChange: 11L));

            Assert.IsFalse(Compare.AlmostEqual(a: 123L, b: 125L));
            Assert.IsFalse(Compare.AlmostEqual(a: 123L, b: 121L));
            Assert.IsTrue(Compare.AlmostEqual(a: 123L, b: 124L));
            Assert.IsTrue(Compare.AlmostEqual(a: 123L, b: 122L));

            Assert.IsFalse(Compare.AlmostEqual(a: 1, b: 4, minimumChange: 2));
            Assert.IsTrue(Compare.AlmostEqual(a: 1, b: 3, minimumChange: 4));

            Assert.IsFalse(Compare.AlmostEqual(a: 1, b: 4));
            Assert.IsTrue(Compare.AlmostEqual(a: 1, b: 2));
        }
Пример #6
0
 private void AreEqual(Vector2 expected, Vector2 actual)
 {
     Assert.IsTrue(
         Compare.AlmostEqual(expected.x, actual.x) & Compare.AlmostEqual(expected.y, actual.y),
         $"expected: {expected.x:F4},{expected.y:F4}, actual: {actual.x:F4},{actual.y:F4}");
 }
 private void AreEqual(float expected, float actual) => Assert.IsTrue(
     Compare.AlmostEqual(expected, actual), $"Expected {expected}, Actual {actual}");
Пример #8
0
 private static int eq(double a, double b) => Compare.AlmostEqual(a, b) ? 1 : 0;
Пример #9
0
 private static int eq(float a, float b) => Compare.AlmostEqual(a, b) ? 1 : 0;
Пример #10
0
 private static int nz(double number) => Compare.AlmostEqual(number, 0) ? 0 : 1;
Пример #11
0
 private static int nz(float number) => Compare.AlmostEqual(number, 0) ? 0 : 1;