using System; using UnitTestSharp; namespace Susurrus.UnitTests { public class VoiceTests : TestFixture { public class CtorTests : TestFixture { public void KeepsTheSlotAndGeneration() { Voice voice = new Voice(slot: 3, generation: 7); CheckEqual(3, voice.Slot); CheckEqual(7, voice.Generation); } public void NegativeSlot_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new Voice(slot: -1, generation: 1); } public void ZeroGeneration_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new Voice(slot: 0, generation: 0); } public void NegativeGeneration_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new Voice(slot: 0, generation: -1); } } public class NoneTests : TestFixture { public void IsTheDefaultVoice() { CheckEqual(default(Voice), Voice.None); } } public class IsNoneTests : TestFixture { public void None_IsNone() { CheckTrue(Voice.None.IsNone); } public void AStartedVoice_IsNotNone() { CheckFalse(new Voice(slot: 0, generation: 1).IsNone); } } public class ToStringTests : TestFixture { public void NamesTheSlotAndGeneration() { CheckEqual("Voice(slot 3, generation 7)", new Voice(3, 7).ToString()); } public void NamesNone() { CheckEqual("Voice.None", Voice.None.ToString()); } } public class EqualityTests : TestFixture { public void SameSlotAndGeneration_AreEqual() { CheckTrue(new Voice(3, 7) == new Voice(3, 7)); CheckFalse(new Voice(3, 7) != new Voice(3, 7)); CheckTrue(new Voice(3, 7).Equals((object)new Voice(3, 7))); CheckEqual(new Voice(3, 7).GetHashCode(), new Voice(3, 7).GetHashCode()); } public void ADifferentSlot_IsNotEqual() { CheckFalse(new Voice(3, 7) == new Voice(4, 7)); CheckTrue(new Voice(3, 7) != new Voice(4, 7)); } public void ADifferentGeneration_IsNotEqual() { CheckFalse(new Voice(3, 7) == new Voice(3, 8)); CheckTrue(new Voice(3, 7) != new Voice(3, 8)); } public void ANonVoice_IsNotEqual() { CheckFalse(new Voice(3, 7).Equals("a voice")); } } } }