Exemple #1
0
    public void Test_S1IntervalTestBase_ApproxEquals()
    {
        // Choose two values kLo and kHi such that it's okay to shift an endpoint by
        // kLo (i.e., the resulting interval is equivalent) but not by kHi.
        const double kLo = 4 * S2.DoubleEpsilon;  // < max_error default
        const double kHi = 6 * S2.DoubleEpsilon;  // > max_error default

        // Empty intervals.
        Assert.True(empty.ApproxEquals(empty));
        Assert.True(zero.ApproxEquals(empty) && empty.ApproxEquals(zero));
        Assert.True(pi.ApproxEquals(empty) && empty.ApproxEquals(pi));
        Assert.True(mipi.ApproxEquals(empty) && empty.ApproxEquals(mipi));
        Assert.False(empty.ApproxEquals(full));
        Assert.True(empty.ApproxEquals(new S1Interval(1, 1 + 2 * kLo)));
        Assert.False(empty.ApproxEquals(new S1Interval(1, 1 + 2 * kHi)));
        Assert.True(new S1Interval(Math.PI - kLo, -Math.PI + kLo).ApproxEquals(empty));

        // Full intervals.
        Assert.True(full.ApproxEquals(full));
        Assert.False(full.ApproxEquals(empty));
        Assert.False(full.ApproxEquals(zero));
        Assert.False(full.ApproxEquals(pi));
        Assert.True(full.ApproxEquals(new S1Interval(kLo, -kLo)));
        Assert.False(full.ApproxEquals(new S1Interval(2 * kHi, 0)));
        Assert.True(new S1Interval(-Math.PI + kLo, Math.PI - kLo).ApproxEquals(full));
        Assert.False(new S1Interval(-Math.PI, Math.PI - 2 * kHi).ApproxEquals(full));

        // Singleton intervals.
        Assert.True(pi.ApproxEquals(pi) && mipi.ApproxEquals(pi));
        Assert.True(pi.ApproxEquals(new S1Interval(Math.PI - kLo, Math.PI - kLo)));
        Assert.False(pi.ApproxEquals(new S1Interval(Math.PI - kHi, Math.PI - kHi)));
        Assert.True(pi.ApproxEquals(new S1Interval(Math.PI - kLo, -Math.PI + kLo)));
        Assert.False(pi.ApproxEquals(new S1Interval(Math.PI - kHi, -Math.PI)));
        Assert.False(zero.ApproxEquals(pi));
        Assert.True(pi.Union(mid12).Union(zero).ApproxEquals(quad12));
        Assert.True(quad2.Intersection(quad3).ApproxEquals(pi));
        Assert.True(quad3.Intersection(quad2).ApproxEquals(pi));

        // Intervals whose corresponding endpoints are nearly the same but where the
        // endpoints are in opposite order (i.e., inverted intervals).
        Assert.False(new S1Interval(0, kLo).ApproxEquals(new S1Interval(kLo, 0)));
        Assert.False(new S1Interval(Math.PI - 0.5 * kLo, -Math.PI + 0.5 * kLo).
                     ApproxEquals(new S1Interval(-Math.PI + 0.5 * kLo, Math.PI - 0.5 * kLo)));

        // Other intervals.
        Assert.True(new S1Interval(1 - kLo, 2 + kLo).ApproxEquals(new S1Interval(1, 2)));
        Assert.True(new S1Interval(1 + kLo, 2 - kLo).ApproxEquals(new S1Interval(1, 2)));
        Assert.True(new S1Interval(2 - kLo, 1 + kLo).ApproxEquals(new S1Interval(2, 1)));
        Assert.True(new S1Interval(2 + kLo, 1 - kLo).ApproxEquals(new S1Interval(2, 1)));
        Assert.False(new S1Interval(1 - kHi, 2 + kLo).ApproxEquals(new S1Interval(1, 2)));
        Assert.False(new S1Interval(1 + kHi, 2 - kLo).ApproxEquals(new S1Interval(1, 2)));
        Assert.False(new S1Interval(2 - kHi, 1 + kLo).ApproxEquals(new S1Interval(2, 1)));
        Assert.False(new S1Interval(2 + kHi, 1 - kLo).ApproxEquals(new S1Interval(2, 1)));
        Assert.False(new S1Interval(1 - kLo, 2 + kHi).ApproxEquals(new S1Interval(1, 2)));
        Assert.False(new S1Interval(1 + kLo, 2 - kHi).ApproxEquals(new S1Interval(1, 2)));
        Assert.False(new S1Interval(2 - kLo, 1 + kHi).ApproxEquals(new S1Interval(2, 1)));
        Assert.False(new S1Interval(2 + kLo, 1 - kHi).ApproxEquals(new S1Interval(2, 1)));
    }