Exemplo n.º 1
0
        public void ToNotifications_should_parse_observable_never()
        {
            var expected = Enumerable.Empty <Recorded <Notification <char> > >();
            var actual   = Marbles.ToNotifications("");

            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
            public void PlaceMarble(Player player)
            {
                if (++CurrentMarble % 23 == 0)
                {
                    Index -= 7;
                    if (CounterClockwiseFromEndOfCircle)
                    {
                        Index += MarbleCount;
                    }
                    player.Score += (Marbles[Index] + CurrentMarble);
                    Marbles.RemoveAt(Index);
                    MarbleCount--;
                }
                else
                {
                    Index += 2;
                    if (CountFromBeginningOfCircle)
                    {
                        Index -= MarbleCount;
                    }

                    //TODO refactor
                    Marbles.Insert(Index, CurrentMarble);
                    MarbleCount++;
                }
            }
        public void ToSubscription_should_allow_unsubscription_before_subscription()
        {
            var result = Marbles.ToSubscription("!-^");

            result.Subscribe.Should().Be(20);
            result.Unsubscribe.Should().Be(0);
        }
        private void ToSubscription_should_parse_marbles_with_instant_unsubscription()
        {
            var result = Marbles.ToSubscription("---(^!)-");

            result.Subscribe.Should().Be(30);
            result.Unsubscribe.Should().Be(30);
        }
        public void ToSubscription_should_allow_marbles_without_both_subscription_nor_unsubscription()
        {
            var result = Marbles.ToSubscription("-");

            result.Subscribe.Should().Be(Subscription.Infinite);
            result.Unsubscribe.Should().Be(Subscription.Infinite);
        }
        private void ToSubscription_should_parse_subscription_marbles()
        {
            var result = Marbles.ToSubscription("---^---!-");

            result.Subscribe.Should().Be(30);
            result.Unsubscribe.Should().Be(70);
        }
        public void empty_is_parsed_correctly()
        {
            var n      = new List <Recorded <Notification <char> > >();
            var actual = Marbles.FromNotifications(n);

            Assert.Equal("", actual);
        }
        // TODO FIX NAME IN JS
        private void ToSubscription_should_parse_marbles_without_unsubscription()
        {
            var result = Marbles.ToSubscription("---^-");

            result.Subscribe.Should().Be(30);
            result.Unsubscribe.Should().Be(Subscription.Infinite);
        }
Exemplo n.º 9
0
        public void AddNegativeInt()
        {
            Marbles <int> marbInt = new Marbles <int>();
            int           input   = -5;

            marbInt.Add(input);
            //assert
            Assert.AreEqual(marbInt[0], input);
        }
Exemplo n.º 10
0
        public void AddString()
        {
            Marbles <string> marbInt = new Marbles <string>();
            string           input   = "5";

            marbInt.Add(input);
            //assert
            Assert.AreEqual(marbInt[0], input);
        }
Exemplo n.º 11
0
        public void CountList()
        {
            Marbles <int> list = new Marbles <int>()
            {
                1, 2, 3, 4, 5, 6
            };

            int howManyElements = list.Count;
        }
Exemplo n.º 12
0
        public void AddNegativeDouble()
        {
            Marbles <double> marbInt = new Marbles <double>();
            double           input   = -5.55;

            marbInt.Add(input);
            //assert
            Assert.AreEqual(marbInt[0], input);
        }
Exemplo n.º 13
0
        public void AddList()
        {
            Marbles <int>            intList = new Marbles <int>();
            Marbles <Marbles <int> > marbInt = new Marbles <Marbles <int> >();

            marbInt.Add(intList);
            //assert
            Assert.AreEqual(intList, marbInt[0]);
        }
Exemplo n.º 14
0
        public void AddBool()
        {
            Marbles <bool> marbInt = new Marbles <bool>();
            bool           input   = true;

            marbInt.Add(input);
            //assert
            Assert.AreEqual(marbInt[0], input);
        }
Exemplo n.º 15
0
        public void ToNotifications_should_parse_observable_empty()
        {
            var expected = new List <Recorded <Notification <char> > >
            {
                OnCompleted <char>(0),
            };
            var actual = Marbles.ToNotifications("|");

            Assert.Equal(expected, actual);
        }
        public void parsing_notifications_with_unexpected_timestamps_throws()
        {
            var n = new List <Recorded <Notification <char> > >
            {
                OnNext(1, 'X')
            };
            Action action = () => Marbles.FromNotifications(n);

            Assert.Throws <ArgumentException>(action);
        }
        public void OnNext_is_parsed_correctly()
        {
            var n = new List <Recorded <Notification <char> > >
            {
                OnNext(0, 'a')
            };
            var actual = Marbles.FromNotifications(n);

            Assert.Equal("a", actual);
        }
        public void OnError_is_parsed_correctly()
        {
            var n = new List <Recorded <Notification <char> > >
            {
                OnError <char>(0, new Exception())
            };
            var actual = Marbles.FromNotifications(n);

            Assert.Equal("#", actual);
        }
        public void OnCompleted_is_parsed_correctly()
        {
            var n = new List <Recorded <Notification <char> > >
            {
                OnCompleted <char>(0)
            };
            var actual = Marbles.FromNotifications(n);

            Assert.Equal("|", actual);
        }
Exemplo n.º 20
0
        public void ToNotifications_should_parse_observable_return()
        {
            var expected = new List <Recorded <Notification <char> > >
            {
                OnNext(0, 'a'),
                OnCompleted <char>(0)
            };
            var actual = Marbles.ToNotifications("(a|)");

            Assert.Equal(expected, actual);
        }
Exemplo n.º 21
0
        public void ToNotifications_should_parse_observable_throw()
        {
            var ex       = new Exception();
            var expected = new List <Recorded <Notification <char> > >
            {
                OnError <char>(0, ex),
            };
            var actual = Marbles.ToNotifications("#", ex);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 22
0
        public static ITestableObservable <char> CreateHotObservable(
            this TestScheduler scheduler,
            string marbles,
            Exception error = null)
        {
            Ensure.NotNull(scheduler, nameof(scheduler));
            Ensure.NotNull(marbles, nameof(marbles));
            var events = Marbles.ToNotifications(marbles, error).ToArray();

            return(scheduler.CreateHotObservable(events));
        }
Exemplo n.º 23
0
        public void Do(Move move)
        {
            var marbleMoveDirection    = Marble.OppositeDirections[move.Direction];
            var marbleOrderingComparer = new MarbleOrderingComparer(marbleMoveDirection);

            Marbles.Sort(marbleOrderingComparer);
            for (int i = 0; i < Marbles.Count; i++)
            {
                var marble         = Marbles[i];
                var squiresToVisit = GetSquiresForMarbleMoveByDirection(marble, marbleMoveDirection);
                var currentSquire  = squiresToVisit[0];
                squiresToVisit.Remove(currentSquire);
                if (currentSquire.HasWall(marbleMoveDirection))
                {
                    continue;
                }

                foreach (var nextSquire in squiresToVisit)
                {
                    if (currentSquire.HasWall(marbleMoveDirection))
                    {
                        break;
                    }
                    if (nextSquire.HasMarble &&
                        nextSquire.Marble.Number != marble.Number)
                    {
                        break;
                    }

                    var nextLocation = marble.NextLocation(marbleMoveDirection);

                    if (nextSquire.HasEmptyHole &&
                        nextSquire.Hole.CanLocateMarbleAt(nextLocation) &&
                        nextSquire.Hole.HasSameNumberAs(marble.Number))
                    {
                        marble.Location        = nextLocation;
                        currentSquire.Marble   = null;
                        nextSquire.Hole.Marble = marble;
                        Marbles.Remove(marble);
                        i--;
                        move.IsInRightDirection = true;
                        break;
                    }
                    else if (nextSquire.CanLocateMarbleAt(nextLocation))
                    {
                        marble.Location      = nextLocation;
                        currentSquire.Marble = null;
                        nextSquire.Marble    = marble;
                        currentSquire        = nextSquire;
                    }
                }
            }
            Moves.Add(move);
        }
Exemplo n.º 24
0
        public void RemoveString()
        {
            Marbles <string> list = new Marbles <string>()
            {
                "apple", "banana", "mango"
            };
            string input = "banana";

            list.Remove(input);
            //assert
            Assert.AreEqual(list[1], "mango");
        }
Exemplo n.º 25
0
        public void RemoveDouble()
        {
            Marbles <double> list = new Marbles <double>()
            {
                1.1, 2.2, 3.3
            };
            double input = 2.2;

            list.Remove(input);
            //assert
            Assert.AreEqual(list[1], 3.3);
        }
Exemplo n.º 26
0
        public void RemoveNegativeint()
        {
            Marbles <int> list = new Marbles <int>()
            {
                -1, -2, -3
            };
            int input = -2;

            list.Remove(input);
            //assert
            Assert.AreEqual(list[1], -3);
        }
Exemplo n.º 27
0
        public void RemoveBool()
        {
            Marbles <bool> list = new Marbles <bool>()
            {
                true, false, true
            };
            bool input = false;

            list.Remove(input);
            //assert
            Assert.AreEqual(list[1], true);
        }
Exemplo n.º 28
0
        public void ToStringInt()
        {
            Marbles <int> list = new Marbles <int>();

            list.Add(4);
            list.Add(5);
            int input = 5;

            list.ToString();
            //assert
            Assert.AreEqual(list[1], input);
        }
Exemplo n.º 29
0
        public void ToStringString()
        {
            Marbles <string> list = new Marbles <string>();

            list.Add("banana");
            list.Add("mango");
            string input = "mango";

            list.ToString();
            //assert
            Assert.AreEqual(list[1], input);
        }
Exemplo n.º 30
0
        public void ToStringBool()
        {
            Marbles <bool> list = new Marbles <bool>();

            list.Add(false);
            list.Add(false);
            bool input = false;

            list.ToString();
            //assert
            Assert.AreEqual(list[0], input);
        }