using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnitTestSharp;
using Azimuth;
namespace Azimuth.UnitTests
{
public class IntervalTests : UnitTestSharp.TestFixture
{
#region Constructors
public void IntervalConstructorTest_LessThenGreater()
{
Scalar valueA = 10;
Scalar valueB = 20;
Interval target = new Interval(valueA, valueB);
CheckEqual(valueA, target.Min);
CheckEqual(valueB, target.Max);
}
public void IntervalConstructorTest_GreaterThenLess()
{
Scalar valueA = 20;
Scalar valueB = 10;
Interval target = new Interval(valueA, valueB);
CheckEqual(valueB, target.Min);
CheckEqual(valueA, target.Max);
}
public void IntervalConstructorTest_BinaryEqual()
{
Scalar valueA = 20;
Scalar valueB = 20;
Interval target = new Interval(valueA, valueB);
CheckEqual(valueA, target.Min);
CheckEqual(valueB, target.Max);
}
public void IntervalConstructorTest_UnaryEquals()
{
Scalar value = 10;
Interval target = new Interval(value);
CheckEqual(value, target.Min);
CheckEqual(value, target.Max);
}
#endregion
public void ToStringTest()
{
Interval target = new Interval(10, 20);
string expected = "[10, 20]";
string actual = target.ToString();
CheckEqual(expected, actual);
}
#region AddPoint
public void AddPointTest_InRangeNoAdd()
{
Interval actual = new Interval(10, 20); // TODO: Initialize to an appropriate value
Interval expected = actual;
actual.AddPoint(15);
CheckEqual(expected, actual);
}
public void AddPointTest_OutsideRangeHigh()
{
Interval actual = new Interval(10, 20); // TODO: Initialize to an appropriate value
Interval expected = new Interval(10, 25);
actual.AddPoint(25);
CheckEqual(expected, actual);
}
public void AddPointTest_OutsideRangeLo()
{
Interval actual = new Interval(10, 20); // TODO: Initialize to an appropriate value
Interval expected = new Interval(5, 20);
actual.AddPoint(5);
CheckEqual(expected, actual);
}
public void AddPointTest_OutsideRangeLoInfinity()
{
Interval actual = new Interval(10, 20);
Interval expected = new Interval(Scalar.NegativeInfinity, 20);
actual.AddPoint(Scalar.NegativeInfinity);
CheckEqual(expected, actual);
}
public void AddPointTest_OutsideRangeHighInfinity()
{
Interval actual = new Interval(10, 20);
Interval expected = new Interval(10, Scalar.PositiveInfinity);
actual.AddPoint(Scalar.PositiveInfinity);
CheckEqual(expected, actual);
}
#endregion
#region Combonation tests
private static Scalar inf = Scalar.PositiveInfinity;
private static Scalar lo = -10;
private static Scalar med = 0;
private static Scalar high = 10;
/// Helps us describe the containment states two intervals can have
public enum Containment
{
none,
AInsideB,
BInsideA,
congruent,
};
private struct Configuration
{
public Interval A, B;
public bool intersects;
public bool touches;
public Containment containment;
}
private IList binaryConfigurations = new List {
// disjoint
// <------)
// [-------->
new Configuration { A = new Interval(-inf, lo),
B = new Interval(high, inf),
intersects = false,
touches = false,
containment = Containment.none},
// touching
// <------)
// (-------->
new Configuration { A = new Interval(-inf, med),
B = new Interval(med, inf),
intersects = false,
touches = true,
containment = Containment.none},
// intersecting
// <--------)
// (--------->
new Configuration { A = new Interval(-inf, high),
B = new Interval(lo, inf),
intersects = true,
touches = false,
containment = Containment.none},
// containment
// (---)
// <-------------->
new Configuration { A = new Interval(lo, high),
B = new Interval(-inf, inf),
intersects = true,
touches = false,
containment = Containment.AInsideB},
// touching containment
// (----)
// (----------)
new Configuration { A = new Interval(lo, med),
B = new Interval(lo, high),
intersects = true,
touches = true,
containment = Containment.AInsideB},
// congruent
// (-----)
// (-----)
new Configuration { A = new Interval(lo, high),
B = new Interval(lo, high),
intersects = true,
touches = true,
containment = Containment.congruent},
// quadruple infinity
// <---->
// <---->
new Configuration { A = new Interval(-inf, inf),
B = new Interval(-inf, inf),
intersects = true,
touches = false,
containment = Containment.congruent},
};
#region IsIntersecting
#endregion
#region IsBarelyTouching
#endregion
#region IsContainingOther
#endregion
#region IsCongruent
#endregion
#endregion
}
}