public static void IsInBounds(int low, int value, int high)
    {
        value.IsInBounds(low, high)
        .Should().BeTrue();

        Range.Above(low).Below(high).Contains(value)
        .Should().BeTrue();
        Range.Between(low, high).Contains(value)
        .Should().BeTrue();

        ((float)value).IsInBounds(low, high)
        .Should().BeTrue();
        Range.Above((float)low).Below(high).Contains(value)
        .Should().BeTrue();

        ((double)value).IsInBounds(low, high)
        .Should().BeTrue();
        Range.Above((double)low).Below(high).Contains(value)
        .Should().BeTrue();

        float.NaN.IsInBounds(low, high)
        .Should().BeFalse();
        double.NaN.IsInBounds(low, high)
        .Should().BeFalse();
    }
    public static void IsNotInBounds(int low, int value, int high)
    {
        value.IsInBounds(low, high)
        .Should().BeFalse();

        Range.Above(low).Below(high).Contains(value)
        .Should().BeFalse();

        ((float)value).IsInBounds(low, high)
        .Should().BeFalse();

        ((double)value).IsInBounds(low, high)
        .Should().BeFalse();
    }
Exemplo n.º 3
0
    public static void IsEqual(double low, double high)
    {
        {
            var a = Range.From(low).To(high);
            var b = Range.Include(low, high);
            (a == b).Should().BeTrue();
            (a != b).Should().BeFalse();
            a.Equals((object)b).Should().BeTrue();
            a.Equals(null).Should().BeFalse();
            a.GetHashCode().Equals(b.GetHashCode())
            .Should().BeTrue();

            if (low < high)
            {
                a = Range.Above(low).Below(high);
                b = Range.Above(low).Below(high);
                a.Equals(b).Should().BeTrue();

                a = Range.From(low).Below(high);
                b = Range.From(low).Below(high);
                a.Equals(b).Should().BeTrue();

                a = Range.Above(low).To(high);
                b = Range.Above(low).To(high);
                a.Equals(b).Should().BeTrue();
            }
            else
            {
                Assert.Throws <ArgumentException>(
                    () => Range.Above(low).Below(high));
                Assert.Throws <ArgumentException>(
                    () => Range.From(low).Below(high));
                Assert.Throws <ArgumentException>(
                    () => Range.Above(low).To(high));
            }
        }

        {
            var a = Range.WithValue(low, high, 1);
            var b = Range.WithValue(low, high, 1);
            a.Equals(b).Should().BeTrue();
        }
    }