コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please input your orders like '10 IMG'");
            Console.WriteLine("Input 'OK' in a new line to complete");
            List <string> orders  = new List <string>();
            string        oneLine = Console.ReadLine();

            while (oneLine.ToUpper() != "OK")
            {
                orders.Add(oneLine.ToUpper());
                oneLine = Console.ReadLine();
            }

            ClientOrder clientOrder = new ClientOrder();

            foreach (var one in orders)
            {
                string[] strOrders = one.Split(' ');
                if (strOrders.Length < 2)
                {
                    continue;
                }
                int posts = 0;
                int.TryParse(strOrders[0], out posts);
                if (posts > 0)
                {
                    MediaOrder mediaOrder = new MediaOrder(strOrders[1].ToUpper(), posts);
                    clientOrder.AddMediaOrder(mediaOrder);
                }
            }
            InitAllMediaBundleItem.Run();
            FilledClientOrder filledClientOrder = ClientOrderCalculator.CalClientOrder(clientOrder);

            Console.WriteLine("\nThe result is......\n");
            Console.WriteLine(filledClientOrder.GetResutlStr());

            Console.ReadKey();
        }
コード例 #2
0
        public void CalClientOrderTest()
        {
            InitAllMediaBundleItem.Run();
            ClientOrder cli = new ClientOrder();

            cli.AddMediaOrder(new MediaOrder("IMG", 28));
            cli.AddMediaOrder(new MediaOrder("FLAC", 28));
            cli.AddMediaOrder(new MediaOrder("VID", 28));
            FilledClientOrder actual = ClientOrderCalculator.CalClientOrder(cli);

            Assert.IsTrue(actual.GetBundles(0).SequenceEqual(new List <int> {
                3, 0
            }));
            Assert.IsTrue(actual.GetBundles(1).SequenceEqual(new List <int> {
                3, 0, 1
            }));
            Assert.IsTrue(actual.GetBundles(2).SequenceEqual(new List <int> {
                2, 2, 0
            }));

            Assert.AreEqual(actual.GetList()[0].offset, 2);
            Assert.AreEqual(actual.GetList()[1].offset, 2);
            Assert.AreEqual(actual.GetList()[2].offset, 0);
        }