Ejemplo n.º 1
0
        public void ToyOrder_240Brackets_ShouldCreate241Lists()
        {
            ToyOrderBook.orderBracketsCount = 240;

            ToyOrderBook.SetupOrderLists();
            int listCount = ToyOrderBook.orderLists.Count;

            Assert.AreEqual(241, listCount);
        }
Ejemplo n.º 2
0
        public void AddNewOrdersToOrderBook_VariousBracketsWithVariousOrderLengths_AddToCorrectBracket(string newOrderString, int correctBracket, int numberOfBrackets)
        {
            ToyOrderBook.orderBracketsCount = numberOfBrackets;
            ToyOrderBook.SetupOrderLists();
            List <string> newOrderStrings = new List <string> ();

            newOrderStrings.Add(newOrderString);

            ToyOrderBook.AddNewOrdersToOrderBook(newOrderStrings);
            int bracketOrderCount = ToyOrderBook.orderLists [correctBracket].Count;

            Assert.AreEqual(1, bracketOrderCount, TestContext.CurrentContext.Test.Name);
        }
Ejemplo n.º 3
0
        public void AddNewOrdersToOrderBook_SingleOrder_AddOneOrder()
        {
            ToyOrderBook.SetupOrderLists();
            string        newOrderString  = "2,2014 1 1 0 1,5";
            List <string> newOrderStrings = new List <string> ();

            newOrderStrings.Add(newOrderString);

            int ordersAdded   = ToyOrderBook.AddNewOrdersToOrderBook(newOrderStrings);
            int ordersPresent = ToyOrderBook.CountAllOrdersInBook();

            Assert.AreEqual(1, ordersAdded);
            Assert.AreEqual(1, ordersPresent);
        }
Ejemplo n.º 4
0
        public void ChooseToy_ToysWithDifferentDurationsAndStartTimes_PickEarliestToy()
        {
            List <string> orders = new List <string> ();

            orders.Add("1, 2014 1 4 8 0, 20");
            orders.Add("2, 2014 1 5 7 0, 40");
            orders.Add("3, 2014 1 4 9 0, 60");
            orders.Add("4, 2014 1 2 9 0, 601");
            orders.Add("5, 2014 1 2 12 0, 600");
            ToyOrderBook.SetupOrderLists();
            ToyOrderBook.AddNewOrdersToOrderBook(orders);

            ToyOrder shouldChooseToy = new ToyOrder("5, 2014 1 2 12 0, 600");

            Elf elf = new Elf(1);

            ToyOrder chosenToy = elf.ChooseToy();

            Assert.AreEqual(shouldChooseToy.iD, chosenToy.iD);
        }
Ejemplo n.º 5
0
        public void ChooseToy_ToysWithDifferentDurationsAndStartTimes_PickQuickestAvailableToy()
        {
            List <string> orders = new List <string> ();

            orders.Add("1, 2014 1 1 8 0, 20");
            orders.Add("2, 2014 1 1 7 0, 40");
            orders.Add("3, 2014 1 1 9 0, 60");
            orders.Add("4, 2014 1 1 12 0, 10");
            orders.Add("5, 2014 1 1 9 0, 599");
            ToyOrderBook.SetupOrderLists();
            ToyOrderBook.AddNewOrdersToOrderBook(orders);

            ToyOrder shouldChooseToy;

            shouldChooseToy = new ToyOrder("1, 2014 1 1 8 0, 20");

            Elf elf = new Elf(1);

            ToyOrder chosenToy = elf.ChooseToy();

            Assert.AreEqual(shouldChooseToy.iD, chosenToy.iD);
        }
Ejemplo n.º 6
0
        public void RemoveOrder_SingleOrder_ShouldHaveNoOrderAfter(int toAdd, int toRemove, int resultingCount)
        {
            ToyOrderBook.SetupOrderLists();
            string        newOrderString  = "2,2014 1 1 0 1,5";
            List <string> newOrderStrings = new List <string> ();

            for (int i = 0; i < toAdd; i++)
            {
                newOrderStrings.Add(newOrderString);
            }

            ToyOrderBook.AddNewOrdersToOrderBook(newOrderStrings);

            for (int j = 0; j < toRemove; j++)
            {
                ToyOrder toyOrder = ToyOrderBook.orderLists [0] [0];
                ToyOrderBook.RemoveOrderFromBooks(toyOrder);
            }

            int ordersPresent = ToyOrderBook.CountAllOrdersInBook();

            Assert.AreEqual(resultingCount, ordersPresent);
        }