public void TestRemoveSpecialOffer()
 {
     Supermarket.Item item = new Supermarket.Item("Cheese", 5, 4, 18);
     Assert.IsTrue(item.HasSpecialOffer());
     item.RemoveSpecialOffer();
     Assert.IsFalse(item.HasSpecialOffer());
     Assert.AreEqual(0, item.GetSpecialOfferMultiple());
     Assert.AreEqual(0, item.GetSpecialOfferPrice());
 }
        public void TestConstructorWithSpecialOffer()
        {
            Supermarket.Item item = new Supermarket.Item("Bob", 123, 2, 210);

            Assert.AreEqual(item.GetSku(), "Bob");
            Assert.AreEqual(item.GetPrice(), 123);
            Assert.IsTrue(item.HasSpecialOffer());
            Assert.AreEqual(item.GetSpecialOfferMultiple(), 2);
            Assert.AreEqual(item.GetSpecialOfferPrice(), 210);
        }
        public void TestConstructorWithoutSpecialOffer()
        {
            Supermarket.Item item = new Supermarket.Item("Rob", 456);

            Assert.AreEqual(item.GetSku(), "Rob");
            Assert.AreEqual(item.GetPrice(), 456);
            Assert.IsFalse(item.HasSpecialOffer());
            Assert.AreEqual(item.GetSpecialOfferMultiple(), 0);
            Assert.AreEqual(item.GetSpecialOfferPrice(), 0);
        }
        public void TestSetValidSpecialOffer()
        {
            Supermarket.Item item = new Supermarket.Item("Andy", 789);
            Assert.IsFalse(item.HasSpecialOffer());

            item.SetSpecialOffer(4, 2800);

            Assert.IsTrue(item.HasSpecialOffer());
            Assert.AreEqual(item.GetSpecialOfferMultiple(), 4);
            Assert.AreEqual(item.GetSpecialOfferPrice(), 2800);
        }
Example #5
0
        /**
         * Given an item and a number of units, work out the cost.
         */
        private double GetSubtotalForItem(Item item, int itemCount)
        {
            if (!item.HasSpecialOffer())
            {
                return(item.GetPrice() * itemCount);
            }
            else
            {
                int numberOfSpecials = itemCount / item.GetSpecialOfferMultiple();
                int numberOfRegulars = itemCount % item.GetSpecialOfferMultiple();

                return(numberOfSpecials * item.GetSpecialOfferPrice() +
                       numberOfRegulars * item.GetPrice());
            }
        }