using System; namespace Prism.UnitTests { public class ExactStopTests : UnitTestSharp.TestFixture { private static readonly StopColor Gray = StopColor.FromHsv(new Hsv(0.6, 0, 0.5)); private static readonly StopColor Red = StopColor.FromHsv(new Hsv(0, 1, 1)); public class CtorTests : UnitTestSharp.TestFixture { public void AssignsTheOffsetAndColor() { var stop = new ExactStop(0.25, Gray); CheckEqual(0.25, stop.Offset); CheckEqual(Gray, stop.Color); } public void OffsetsAtTheEnds_AreAllowed() { CheckEqual(0.0, new ExactStop(0, Gray).Offset); CheckEqual(1.0, new ExactStop(1, Gray).Offset); } public void OffsetBelowZero_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new ExactStop(-0.1, Gray); } public void OffsetAboveOne_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new ExactStop(1.1, Gray); } public void NaNOffset_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new ExactStop(double.NaN, Gray); } } public class EqualityTests : UnitTestSharp.TestFixture { public void SameOffsetAndColor_AreEqual() { var first = new ExactStop(0.5, Gray); var second = new ExactStop(0.5, Gray); CheckTrue(first.Equals(second)); CheckTrue(first == second); CheckFalse(first != second); } public void ADifferentOffset_IsNotEqual() { CheckFalse(new ExactStop(0.5, Gray).Equals(new ExactStop(0.25, Gray))); CheckTrue(new ExactStop(0.5, Gray) != new ExactStop(0.25, Gray)); } public void ADifferentColor_IsNotEqual() { CheckFalse(new ExactStop(0.5, Gray).Equals(new ExactStop(0.5, Red))); } public void BoxedStop_IsEqualToTheSameStop() { CheckTrue(new ExactStop(0.5, Gray).Equals((object)new ExactStop(0.5, Gray))); } public void ANonStop_IsNotEqual() { CheckFalse(new ExactStop(0.5, Gray).Equals("stop")); } public void EqualStops_HaveTheSameHashCode() { CheckEqual(new ExactStop(0.5, Gray).GetHashCode(), new ExactStop(0.5, Gray).GetHashCode()); } } } }