Exemple #1
0
        static void Main(string[] args)
        {
            var list = (IEnumerable <Product>) new List <Product> {
                new Product {
                    Id = 1, Name = "Basic", CostCalculator = new BasicTariffCalculator()
                },
                new Product {
                    Id = 2, Name = "Packaged", CostCalculator = new PackagedTariffCalculator()
                }
            };

            var tariffСomparer = new TariffСomparer();

            for (int i = 0; i <= 8000; i += 1000)
            {
                Write("Consumption: {0} kWh/year ", i);
                var SortedList = tariffСomparer.SortByAnnualConsumption(list, i);

                var iterator = SortedList.GetEnumerator();
                iterator.MoveNext();

                Write("{0} (Annual cost: {1}) better than ", iterator.Current.Name, iterator.Current.CostCalculator.CalculateAnnualCost(i));
                iterator.MoveNext();
                WriteLine("{0} (Annual cost: {1}) ", iterator.Current.Name, iterator.Current.CostCalculator.CalculateAnnualCost(i));
            }
            ReadLine();
        }
Exemple #2
0
        public void AProfitableThenBHigh()
        {
            var tariffComparison = new TariffСomparer();
            var products         = InitializeProducts();
            var consumption      = 5800;

            var productsList = new List <Product>(
                tariffComparison.SortByAnnualConsumption(products, consumption));

            Assert.AreEqual(productsList[0].Id, 1);
            Assert.AreEqual(productsList[1].Id, 2);
        }