Пример #1
0
        public void Test_CK_einProduktZweiMal()
        {
            var sut = new Solution();

            var products = new Products { { "Apfel", 10 } };

            var success = false;

            sut.Setup(products, new ProductPackages());

            var price = 0;
            sut.SendPrice += p =>
            {
                price = p;
                Debug.WriteLine("{0},", price);
            };

            sut.Order("Apfel");
            price.Should().Be(10);
            sut.Order("Apfel");
            price.Should().Be(20);
        }
Пример #2
0
        public void Test_CK_einProduktZweiMal_InsPaket()
        {
            var sut = new Solution();

            var products = new Products { { "Apfel", 10 } };

            var success = false;

            var productPackages = new ProductPackages
            {
                new ProductPackage(){ Price = 15, Products = { "Apfel", "Apfel" }},

            };

            sut.Setup(products, productPackages);

            var price = 0;
            sut.SendPrice += p =>
            {
                price = p;
                Debug.WriteLine("{0},", price);
            };

            sut.Order("Apfel");
            price.Should().Be(10);
            sut.Order("Apfel");
            price.Should().Be(15);
        }
Пример #3
0
        public void Test_switch_to_another_package()
        {
            var sut = new Solution();

            var products = new Products {{"A", 10}, {"B", 20}, {"C", 30}};
            var productPackages = new ProductPackages
            {
                new ProductPackage {Price = 29, Products = new List<string> {"A", "B"}},
                new ProductPackage {Price = 48, Products = new List<string> {"B", "C"}},
            };

            sut.Setup(products, productPackages);

            var price = 0;
            sut.SendPrice += p => price = p;

            sut.Order("A");
            sut.Order("B");
            price.Should().Be(29, "there is a package for A and B with price 29.");

            sut.Order("C");

            price.Should().Be(10 + 48, "it is cheaper to take package B & C");
        }
Пример #4
0
        public void Test_quantity_discount()
        {
            var sut = new Solution();

            var products = new Products {{"A", 10}};
            var productPackages = new ProductPackages
            {
                new ProductPackage {Price = 19, Products = new List<string> {"A", "A"}},
                new ProductPackage {Price = 27, Products = new List<string> {"A", "A", "A"}},
            };

            sut.Setup(products, productPackages);

            var price = 0;
            sut.SendPrice += p => price = p;

            sut.Order("A");
            price.Should().Be(10);

            sut.Order("A");
            price.Should().Be(19);

            sut.Order("A");
            price.Should().Be(27);

            sut.Order("A");
            price.Should().Be(27 + 10);

            sut.Order("A");
            price.Should().Be(27 + 19);

            sut.Order("A");
            price.Should().Be(2 * 27);
        }
Пример #5
0
        public void Test_order_single_product_twice()
        {
            var sut = new Solution();

            var products = new Products {{"A", 10}};
            var price = 0;

            sut.Setup(products, new ProductPackages());

            sut.SendPrice += p => price = p;

            sut.Order("A");
            sut.Order("A");

            price.Should().Be(20);
        }
Пример #6
0
        public void Test_impossible_product()
        {
            var sut = new Solution();

            var products = new Products {{"A", 10}, {"B", 20}, {"C", 30}};

            var success = false;

            sut.Setup(products, new ProductPackages());

            sut.SendPrice += p => success = true;

            sut.Order("D");

            success.Should().BeFalse();
        }
Пример #7
0
        public void Test_if_pitfall_package_is_ignored()
        {
            var sut = new Solution();

            var products = new Products {{"A", 10}};
            var productPackages = new ProductPackages
            {
                new ProductPackage {Price = 21, Products = new List<string> {"A", "A"}}
            };

            sut.Setup(products, productPackages);

            var price = 0;
            sut.SendPrice += p => price = p;

            sut.Order("A");
            price.Should().Be(10);

            sut.Order("A");
            price.Should().Be(2 * 10, "package is a pitfall");
        }
Пример #8
0
        public void Test_Forum()
        {
            var sut = new Solution();

            var products = new Products {
                { "VegMac", 4 },
                { "BurgerMac", 1 },
                { "WoodMac", 3 },
                { "MacMac", 5 },
                { "PommesPommes", 2 },
                { "Pommes", 1 },
                { "PommesGr", 1 },
                { "Cola", 3 }
            };

            var productPackages = new ProductPackages
            {
                new ProductPackage(){ Price = 1, Products = { "MacMac", "Cola" }},
                new ProductPackage(){ Price = 10, Products = { "BurgerMac", "WoodMac", "Pommes", "Cola" }},
                new ProductPackage(){ Price = 7, Products = { "VegMac", "Cola", "Pommes" }},
                new ProductPackage(){ Price = 7, Products = { "VegMac", "Cola", "PommesGr" }},
                new ProductPackage(){ Price = 2, Products = { "Cola", "PommesGr" }},
                new ProductPackage(){ Price = 1, Products = { "VegMac", "Cola", "Pommes", "Pommes" }}
            };

            sut.Setup(products, productPackages);

            var price = 0;
            sut.SendPrice += p =>
            {
                price = p;
                Debug.WriteLine("{0},",price);
            };

            sut.Order("VegMac");
            price.Should().Be(4);
            sut.Order("VegMac");
            price.Should().Be(8);
            sut.Order("VegMac");
            price.Should().Be(12);
            sut.Order("Pommes");
            price.Should().Be(13);
            sut.Order("Cola");
            price.Should().Be(15); // P3 + 2xVegMac
            sut.Order("Pommes");
            price.Should().Be(9); // P3 + P6 + 1xVegMac
            sut.Order("PommesGr");
            price.Should().Be(10); // P4 + P6 + 1xPommes
            sut.Order("MacMac");
            price.Should().Be(15); // P4 + P6 + 1xPommes + 1xMacMac
            sut.Order("WoodMac");
            price.Should().Be(18); // P4 + P6 + 1xPommes + 1xMacMac + 1xWoodMac
            sut.Order("BurgerMac");
            price.Should().Be(19); // P4 + P6 + 1xPommes + 1xMacMac + 1xWoodMac + 1xBurgeMac
            sut.Order("MacMac");
            price.Should().Be(24); // P4 + P6 + 1xPommes + 2xMacMac + 1xWoodMac + 1xBurgeMac
            sut.Order("PommesPommes");
            price.Should().Be(26); // P4 + P6 + 1xPommes + 2xMacMac + 1xWoodMac + 1xBurgeMac + PommesPommes
            sut.Order("Pommes");
            price.Should().Be(27); // P4 + P6 + 2xPommes + 2xMacMac + 1xWoodMac + 1xBurgeMac + PommesPommes
            sut.Order("Cola");
            price.Should().Be(23); // P1 + P4 + P6 + 2xPommes + 1xMacMac + 1xWoodMac + 1xBurgeMac + PommesPommes
        }