public void ContainsTest() { Assert.False(Interval.Empty <int>().Contains(-10)); Assert.False(Interval.Empty <int>().Contains(0)); Assert.False(Interval.Empty <int>().Contains(10)); Assert.False(Interval.Single(42).Contains(0)); Assert.False(Interval.Single(42).Contains(50)); Assert.True(Interval.Single(42).Contains(42)); Assert.False(Interval.Open(23, 42).Contains(10)); Assert.False(Interval.Open(23, 42).Contains(23)); Assert.False(Interval.Open(23, 42).Contains(42)); Assert.False(Interval.Open(23, 42).Contains(50)); Assert.True(Interval.Open(23, 42).Contains(30)); Assert.False(Interval.ClosedOpen(23, 42).Contains(10)); Assert.False(Interval.ClosedOpen(23, 42).Contains(42)); Assert.False(Interval.ClosedOpen(23, 42).Contains(50)); Assert.True(Interval.ClosedOpen(23, 42).Contains(23)); Assert.True(Interval.ClosedOpen(23, 42).Contains(30)); Assert.False(Interval.OpenClosed(23, 42).Contains(10)); Assert.False(Interval.OpenClosed(23, 42).Contains(23)); Assert.False(Interval.OpenClosed(23, 42).Contains(50)); Assert.True(Interval.OpenClosed(23, 42).Contains(30)); Assert.True(Interval.OpenClosed(23, 42).Contains(42)); Assert.False(Interval.Closed(23, 42).Contains(10)); Assert.False(Interval.Closed(23, 42).Contains(50)); Assert.True(Interval.Closed(23, 42).Contains(23)); Assert.True(Interval.Closed(23, 42).Contains(30)); Assert.True(Interval.Closed(23, 42).Contains(42)); Assert.False(Interval.LowerOpen(42).Contains(10)); Assert.False(Interval.LowerOpen(42).Contains(42)); Assert.True(Interval.LowerOpen(42).Contains(50)); Assert.True(Interval.LowerOpen(42).Contains(Int32.MaxValue)); Assert.False(Interval.LowerClosed(42).Contains(10)); Assert.True(Interval.LowerClosed(42).Contains(42)); Assert.True(Interval.LowerClosed(42).Contains(50)); Assert.True(Interval.LowerClosed(42).Contains(Int32.MaxValue)); Assert.False(Interval.UpperOpen(42).Contains(50)); Assert.False(Interval.UpperOpen(42).Contains(42)); Assert.True(Interval.UpperOpen(42).Contains(20)); Assert.True(Interval.UpperOpen(42).Contains(Int32.MinValue)); Assert.False(Interval.UpperClosed(42).Contains(50)); Assert.True(Interval.UpperClosed(42).Contains(42)); Assert.True(Interval.UpperClosed(42).Contains(20)); Assert.True(Interval.UpperClosed(42).Contains(Int32.MinValue)); Assert.True(Interval.Unbounded <int>().Contains(-10)); Assert.True(Interval.Unbounded <int>().Contains(0)); Assert.True(Interval.Unbounded <int>().Contains(10)); Assert.True(Interval.Unbounded <int>().Contains(Int32.MinValue)); Assert.True(Interval.Unbounded <int>().Contains(Int32.MaxValue)); }
public void ToStringTests() { var emptyInterval = Interval <int> .Open(0, 0); var openInterval = Interval <int> .Open(1, 10); var closedInterval = Interval <int> .Closed(2, 5); var leftClosedRightOpen = Interval <int> .LeftClosedRightOpen(1, 2); var leftOpenRightClosed = Interval <int> .LeftOpenRightClosed(3, 5); var leftBoundedRightUnbounded = Interval <int> .LeftClosed(1); var leftUnboundedRightBounded = Interval <int> .RightOpen(5); Assert.That(emptyInterval.ToString(), Is.EqualTo("{}")); Assert.That(openInterval.ToString(), Is.EqualTo("(1,10)")); Assert.That(closedInterval.ToString(), Is.EqualTo("[2,5]")); Assert.That(leftClosedRightOpen.ToString(), Is.EqualTo("[1,2)")); Assert.That(leftOpenRightClosed.ToString(), Is.EqualTo("(3,5]")); Assert.That(leftBoundedRightUnbounded.ToString(), Is.EqualTo("[1,∞)")); Assert.That(leftUnboundedRightBounded.ToString(), Is.EqualTo("(-∞,5)")); }
public void IsEmptyTests() { var emptyInterval = Interval <int> .Open(1, 1); var smallOpenInterval = Interval <int> .Open(1, 2); var singleValueInterval = Interval <int> .Closed(1, 1); Assert.That(emptyInterval.IsEmpty, Is.True); Assert.That(smallOpenInterval.IsEmpty, Is.False); Assert.That(singleValueInterval.IsEmpty, Is.False); }
public void IsUnboundedTest() { Assert.False(Interval.Empty <int>().IsUnbounded); Assert.False(Interval.Single(42).IsUnbounded); Assert.False(Interval.Open(23, 42).IsUnbounded); Assert.False(Interval.ClosedOpen(23, 42).IsUnbounded); Assert.False(Interval.OpenClosed(23, 42).IsUnbounded); Assert.False(Interval.Closed(23, 42).IsUnbounded); Assert.True(Interval.LowerOpen(42).IsUnbounded); Assert.True(Interval.LowerClosed(42).IsUnbounded); Assert.True(Interval.UpperOpen(42).IsUnbounded); Assert.True(Interval.UpperClosed(42).IsUnbounded); Assert.True(Interval.Unbounded <int>().IsUnbounded); }
public void ToStringTest() { Assert.Equal("Ø", Interval.Empty <int>().ToString()); Assert.Equal("[42, 42]", Interval.Single(42).ToString()); Assert.Equal("(23, 42)", Interval.Open(23, 42).ToString()); Assert.Equal("[23, 42)", Interval.ClosedOpen(23, 42).ToString()); Assert.Equal("(23, 42]", Interval.OpenClosed(23, 42).ToString()); Assert.Equal("[23, 42]", Interval.Closed(23, 42).ToString()); Assert.Equal("(42, ∞)", Interval.LowerOpen(42).ToString()); Assert.Equal("[42, ∞)", Interval.LowerClosed(42).ToString()); Assert.Equal("(-∞, 42)", Interval.UpperOpen(42).ToString()); Assert.Equal("(-∞, 42]", Interval.UpperClosed(42).ToString()); Assert.Equal("(-∞, ∞)", Interval.Unbounded <int>().ToString()); }
public void IntersectTest() { var e = Interval.Empty <int>(); var s = Interval.Single(20); var o1 = Interval.Open(10, 30); var o2 = Interval.Open(20, 40); var o3 = Interval.Open(30, 50); var c1 = Interval.Closed(10, 30); var c2 = Interval.Closed(20, 40); var c3 = Interval.Closed(30, 50); var u = Interval.Unbounded <int>(); Assert.Equal(e, e.Intersect(e)); Assert.Equal(e, e.Intersect(s)); Assert.Equal(e, e.Intersect(o1)); Assert.Equal(e, e.Intersect(c1)); Assert.Equal(e, e.Intersect(u)); Assert.Equal(s, s.Intersect(s)); Assert.Equal(s, s.Intersect(o1)); Assert.Equal(e, e.Intersect(o2)); Assert.Equal(s, s.Intersect(c1)); Assert.Equal(s, s.Intersect(c2)); Assert.Equal(s, s.Intersect(u)); Assert.Equal(s, o1.Intersect(s)); Assert.Equal(o1, o1.Intersect(o1)); Assert.Equal(o1, o1.Intersect(Interval.Open(0, 100))); Assert.Equal(o1, o1.Intersect(u)); Assert.Equal(Interval.Open(20, 30), o1.Intersect(o2)); Assert.Equal(e, o1.Intersect(o3)); Assert.Equal(o1, o1.Intersect(c1)); Assert.Equal(Interval.ClosedOpen(20, 30), o1.Intersect(c2)); Assert.Equal(e, o1.Intersect(c3)); Assert.Equal(s, c1.Intersect(s)); Assert.Equal(c1, c1.Intersect(c1)); Assert.Equal(c1, c1.Intersect(Interval.Closed(0, 100))); Assert.Equal(c1, c1.Intersect(u)); Assert.Equal(Interval.Closed(20, 30), c1.Intersect(c2)); Assert.Equal(Interval.Single(30), c1.Intersect(c3)); Assert.Equal(o1, c1.Intersect(o1)); Assert.Equal(Interval.OpenClosed(20, 30), c1.Intersect(o2)); Assert.Equal(e, c1.Intersect(o3)); }
public void ContainsTests() { var openInterval = Interval <int> .Open(2, 5); var closedInterval = Interval <int> .Closed(2, 5); var infiniteInterval = Interval <int> .Unbound; var emptyInterval = Interval <int> .Open(5, 5); var leftOpenRightClosed = Interval <int> .LeftOpenRightClosed(3, 5); var leftBoundedRightUnbounded = Interval <int> .LeftClosed(1); Assert.That(openInterval.Contains(1), Is.False); Assert.That(openInterval.Contains(2), Is.False); Assert.That(openInterval.Contains(3), Is.True); Assert.That(openInterval.Contains(4), Is.True); Assert.That(openInterval.Contains(5), Is.False); Assert.That(openInterval.Contains(6), Is.False); Assert.That(closedInterval.Contains(1), Is.False); Assert.That(closedInterval.Contains(2), Is.True); Assert.That(closedInterval.Contains(3), Is.True); Assert.That(closedInterval.Contains(4), Is.True); Assert.That(closedInterval.Contains(5), Is.True); Assert.That(closedInterval.Contains(6), Is.False); Assert.That(infiniteInterval.Contains(int.MinValue), Is.True); Assert.That(infiniteInterval.Contains(0), Is.True); Assert.That(infiniteInterval.Contains(int.MaxValue), Is.True); Assert.That(emptyInterval.Contains(4), Is.False); Assert.That(emptyInterval.Contains(5), Is.False); Assert.That(emptyInterval.Contains(6), Is.False); Assert.That(leftOpenRightClosed.Contains(2), Is.False); Assert.That(leftOpenRightClosed.Contains(3), Is.False); Assert.That(leftOpenRightClosed.Contains(4), Is.True); Assert.That(leftOpenRightClosed.Contains(5), Is.True); Assert.That(leftOpenRightClosed.Contains(6), Is.False); Assert.That(leftBoundedRightUnbounded.Contains(0), Is.False); Assert.That(leftBoundedRightUnbounded.Contains(1), Is.True); Assert.That(leftBoundedRightUnbounded.Contains(int.MaxValue), Is.True); }
public void CreationTest() { Assert.True(Interval.Open(2, 1).IsEmpty); Assert.True(Interval.Open(1, 1).IsEmpty); Assert.True(Interval.OpenClosed(1, 1).IsEmpty); Assert.True(Interval.Closed(2, 1).IsEmpty); Assert.True(Interval.Empty <int>().IsEmpty); Assert.False(Interval.Single(42).IsEmpty); Assert.False(Interval.Open(23, 42).IsEmpty); Assert.False(Interval.ClosedOpen(23, 42).IsEmpty); Assert.False(Interval.OpenClosed(23, 42).IsEmpty); Assert.False(Interval.Closed(23, 42).IsEmpty); Assert.False(Interval.LowerOpen(42).IsEmpty); Assert.False(Interval.LowerClosed(42).IsEmpty); Assert.False(Interval.UpperOpen(42).IsEmpty); Assert.False(Interval.UpperClosed(42).IsEmpty); Assert.False(Interval.Unbounded <int>().IsEmpty); }
public void EqualsTests() { var emptyInterval1 = Interval <int> .Open(0, 0); var emptyInterval2 = Interval <int> .Open(10, 10); var openInterval1 = Interval <int> .Open(5, 10); var openInterval2 = Interval <int> .Open(5, 10); var closedInterval1 = Interval <int> .Closed(5, 10); var closedInterval2 = Interval <int> .Closed(5, 10); Assert.That(emptyInterval1, Is.EqualTo(emptyInterval2)); Assert.That(openInterval1, Is.EqualTo(openInterval2)); Assert.That(closedInterval1, Is.EqualTo(closedInterval2)); }