예제 #1
0
        public void Observer_Where_Update_Parameter_Message_Properties_WindowWidth_LessThan_X_And_WindowHeight_LessThan_Y()
        {
            Avoidant observer = new Avoidant(50, 100, 3, 1);

            Assert.ThrowsException <ArgumentOutOfRangeException>(
                () => observer.Update(new ThreatMessage(10, 10, 49, 99, 5)));
        }
예제 #2
0
        public void Observer_Where_Observable_Is_UpperAndOnLeft_And_IsNotIn_Observer_ThreatRadius()
        {
            Avoidant observer = new Avoidant(50, 100, 5, 30);

            observer.Update(new ThreatMessage(20, 69, 1000, 500, 5));

            Assert.IsTrue(observer.X == 50 && observer.Y == 100);
        }
예제 #3
0
        public void Observer_Where_Observable_Is_BelowAndOnRight_And_IsNotIn_Observer_ThreatRadius()
        {
            Avoidant observer = new Avoidant(50, 100, 5, 30);

            observer.Update(new ThreatMessage(80, 131, 1000, 500, 5));

            Assert.IsTrue(observer.X == 50 && observer.Y == 100);
        }
예제 #4
0
        public void Observer_Where_Observable_Is_UpperAndOnLeft_And_Observer_IsNotIn_Observable_ActionRadius()
        {
            Avoidant observer = new Avoidant(50, 100, 3, 1);

            observer.Update(new ThreatMessage(44, 95, 1000, 500, 5));

            Assert.IsFalse(observer.GaveUp);
        }
예제 #5
0
        public void Observer_Where_Observable_Is_OnLeft_And_Observer_IsIn_Observable_ActionRadius()
        {
            Avoidant observer = new Avoidant(50, 100, 3, 1);

            observer.Update(new ThreatMessage(45, 100, 1000, 500, 5));

            Assert.IsTrue(observer.GaveUp);
        }
예제 #6
0
        public void Observer_Where_GaveUp_Property_IsFalse()
        {
            Avoidant observer = new Avoidant(50, 100, 5, 50);

            observer.Update(new ThreatMessage(80, 70, 1000, 500, 5));

            Assert.IsTrue((observer.X == 45 && observer.Y == 100) ||
                          (observer.X == 50 && observer.Y == 105));
        }
예제 #7
0
        public void Observer_Where_GaveUp_Property_IsTrue()
        {
            Avoidant observer = new Avoidant(50, 100, 3, 1);

            observer.Update(new ThreatMessage(50, 95, 1000, 500, 5));
            observer.Update(new ThreatMessage(60, 95, 1000, 500, 5));

            Assert.IsTrue(observer.X == 50 && observer.Y == 100);
        }
예제 #8
0
 public void Observer_Where_Constructor_Parameter_ThreatRadius_MoreThan_Zero()
 {
     try {
         Avoidant observer = new Avoidant(50, 100, 3, 1);
     }
     catch (Exception ex) {
         Assert.Fail("Expected no exception, but got: " + ex.Message);
     }
 }
예제 #9
0
        public void Observer_Where_Observable_Is_BelowAndOnLeft_And_IsIn_Observer_ThreatRadius()
        {
            Avoidant observer = new Avoidant(50, 100, 5, 30);

            observer.Update(new ThreatMessage(20, 130, 1000, 500, 5));

            Assert.IsTrue((observer.X == 55 && observer.Y == 100) ||
                          (observer.X == 50 && observer.Y == 95));
        }
예제 #10
0
 public void Observer_Where_Constructor_Parameter_Y_MoreOrEqualTo_Zero()
 {
     try {
         Avoidant observer = new Avoidant(50, 0, 3, 30);
     }
     catch (Exception ex) {
         Assert.Fail("Expected no exception, but got: " + ex.Message);
     }
 }
예제 #11
0
        public void Observer_Where_Observable_Is_UpperAndOnRight_And_IsIn_Observer_ThreatRadius()
        {
            Avoidant observer = new Avoidant(50, 100, 5, 30);

            observer.Update(new ThreatMessage(80, 70, 1000, 500, 5));

            Assert.IsTrue((observer.X == 45 && observer.Y == 100) ||
                          (observer.X == 50 && observer.Y == 105));
        }
예제 #12
0
        public void Observer_Where_Update_Parameter_Message_Properties_WindowWidth_MoreOrEqualTo_X_And_WindowHeight_MoreOrEqualTo_Y()
        {
            Avoidant observer = new Avoidant(50, 100, 3, 1);

            try {
                observer.Update(new ThreatMessage(10, 10, 1000, 500, 5));
            }
            catch (Exception ex) {
                Assert.Fail("Expected no exception, but got: " + ex.Message);
            }
        }
예제 #13
0
        public void Publisher_Where_NotifyObservers_Parameter_WindowHeight_LessThan_Y_OfSome_Observers()
        {
            Publisher publisher = new Publisher();
            IAvoidant observer1 = new Avoidant(100, 50, 1, 30);
            IAvoidant observer2 = new Avoidant(50, 100, 3, 40);
            IAvoidant observer3 = new Avoidant(10, 110, 3, 40);

            publisher.AddObserver(observer1);
            publisher.AddObserver(observer2);
            publisher.AddObserver(observer3);

            Assert.ThrowsException <ArgumentOutOfRangeException>(
                () => publisher.NotifyObservers(new ThreatMessage(5, 5, 200, 70, 5)));
        }
예제 #14
0
        public void Publisher_Where_RemoveObserver_Parameter_Observer_IsNot_Null()
        {
            Publisher publisher = new Publisher();
            IAvoidant observer1 = new Avoidant(0, 0, 1, 30);
            IAvoidant observer2 = new Avoidant(0, 0, 3, 40);

            publisher.AddObserver(observer1);
            publisher.AddObserver(observer1);
            publisher.AddObserver(observer2);
            publisher.AddObserver(observer1);
            publisher.AddObserver(observer1);

            publisher.RemoveObserver(observer1);

            Assert.AreEqual(1, publisher.ObserverList.Count);
        }
예제 #15
0
        public void Publisher_Where_NotifyObservers_Parameters_WindowWidth_And_WindowHeight_MoreOrEqualTo_X_And_Y_OfAllThe_Observers_Respectively()
        {
            Publisher publisher = new Publisher();
            IAvoidant observer1 = new Avoidant(50, 100, 5, 30);
            IAvoidant observer2 = new Avoidant(50, 100, 5, 30);
            IAvoidant observer3 = new Avoidant(50, 100, 5, 30);

            publisher.AddObserver(observer1);
            publisher.AddObserver(observer2);
            publisher.AddObserver(observer3);

            publisher.NotifyObservers(new ThreatMessage(25, 75, 500, 1000, 5));

            Assert.IsTrue(((observer1.X == 55 && observer1.Y == 100) ||
                           (observer1.X == 50 && observer1.Y == 105)) &&
                          ((observer2.X == 55 && observer2.Y == 100) ||
                           (observer2.X == 50 && observer2.Y == 105)) &&
                          ((observer3.X == 55 && observer3.Y == 100) ||
                           (observer3.X == 50 && observer3.Y == 105)));
        }