Exemplo n.º 1
0
        public void 測試_買第一二三四集價錢為320()
        {
            ///Arrange
            var target = new PotterBooks();

            this._dummyBooks.Add(new Book {
                Id = 1, Name = "哈利波特第一集", Price = 100
            });
            this._dummyBooks.Add(new Book {
                Id = 2, Name = "哈利波特第二集", Price = 100
            });
            this._dummyBooks.Add(new Book {
                Id = 3, Name = "哈利波特第三集", Price = 100
            });
            this._dummyBooks.Add(new Book {
                Id = 4, Name = "哈利波特第四集", Price = 100
            });

            decimal expected = 320;

            ///Act
            decimal actual = target.Calculate(this._dummyBooks);

            ///Assert
            Assert.AreEqual(expected, actual);
        }
        public void the_same_book()
        {
            var book1 = PotterBooks.First(1);
            var book2 = PotterBooks.First(2);

            book1.Should().Be(book2);
        }
Exemplo n.º 3
0
        public void 測試_第一集買一本_第二三集買兩本_價錢為_460()
        {
            ///Arrange
            var target = new PotterBooks();

            this._dummyBooks.Add(new Book {
                Id = 1, Name = "哈利波特第一集", Price = 100
            });
            this._dummyBooks.Add(new Book {
                Id = 2, Name = "哈利波特第二集", Price = 100
            });
            this._dummyBooks.Add(new Book {
                Id = 2, Name = "哈利波特第二集", Price = 100
            });
            this._dummyBooks.Add(new Book {
                Id = 3, Name = "哈利波特第三集", Price = 100
            });
            this._dummyBooks.Add(new Book {
                Id = 3, Name = "哈利波特第三集", Price = 100
            });

            var expected = 460;

            ///Actual
            var actual = target.Calculate(this._dummyBooks);

            ///Assert
            Assert.AreEqual(expected, actual);
        }
        public void the_different_books()
        {
            var book1 = PotterBooks.First(1);
            var book2 = PotterBooks.Second(1);

            book1.Should().NotBe(book2);
        }
 public void when_buy_a_book_then_amount_should_be_100()
 {
     BooksAmountShouldBe(
         books: new List <Book>
     {
         PotterBooks.First(1)
     },
         expected: 100m);
 }
 public void when_buy_two_the_same_series_books_then_amount_should_be_200()
 {
     BooksAmountShouldBe(
         books: new List <Book>
     {
         PotterBooks.First(2),
     },
         expected: 200m);
 }
 public void when_buy_two_different_series_books_then_amount_should_be_190()
 {
     BooksAmountShouldBe(
         books: new List <Book>
     {
         PotterBooks.First(1),
         PotterBooks.Second(1),
     },
         expected: 190m);
 }
 public void when_buy_two_the_same_series_books_and_one_different_series_book_then_amount_should_be_290()
 {
     BooksAmountShouldBe(
         books: new List <Book>
     {
         PotterBooks.First(2),
         PotterBooks.Second(1),
     },
         expected: 290m);
 }
 public void when_buy_four_different_series_books_then_amount_should_be_320()
 {
     BooksAmountShouldBe(
         books: new List <Book>
     {
         PotterBooks.First(1),
         PotterBooks.Second(1),
         PotterBooks.Third(1),
         PotterBooks.Fourth(1),
     },
         expected: 320m);
 }
 public void when_buy_five_different_series_books_and_three_different_series_books_then_amount_should_be_640()
 {
     BooksAmountShouldBe(
         books: new List <Book>
     {
         PotterBooks.First(2),
         PotterBooks.Second(2),
         PotterBooks.Third(2),
         PotterBooks.Fourth(1),
         PotterBooks.Fifth(1),
     },
         expected: 640m);
 }
Exemplo n.º 11
0
 public void TestEdgeCases()
 {
     Assert.AreEqual(2 * (8 * 4 * 0.8), PotterBooks.PriceAllBooks(new List <int> {
         1, 1, 2, 2, 3, 3, 4, 5
     }));
     Assert.AreEqual(3 * (8 * 5 * 0.75) + 2 * (8 * 4 * 0.8),
                     PotterBooks.PriceAllBooks(new List <int> {
         1, 1, 1, 1, 1,
         2, 2, 2, 2, 2,
         3, 3, 3, 3,
         4, 4, 4, 4, 4,
         5, 5, 5, 5
     }));
 }
Exemplo n.º 12
0
 public void TestSimpleDiscounts()
 {
     Assert.AreEqual(8 * 2 * 0.95, PotterBooks.PriceAllBooks(new List <int> {
         1, 2
     }));
     Assert.AreEqual(8 * 3 * 0.9, PotterBooks.PriceAllBooks(new List <int> {
         1, 3, 5
     }));
     Assert.AreEqual(8 * 4 * 0.8, PotterBooks.PriceAllBooks(new List <int> {
         1, 2, 3, 5
     }));
     Assert.AreEqual(8 * 5 * 0.75, PotterBooks.PriceAllBooks(new List <int> {
         1, 2, 3, 4, 5
     }));
 }
Exemplo n.º 13
0
 public void TestSeveralDiscounts()
 {
     Assert.AreEqual(8 + (8 * 2 * 0.95), PotterBooks.PriceAllBooks(new List <int> {
         1, 1, 2
     }));
     Assert.AreEqual(2 * (8 * 2 * 0.95), PotterBooks.PriceAllBooks(new List <int> {
         1, 1, 2, 2
     }));
     Assert.AreEqual((8 * 4 * 0.8) + (8 * 2 * 0.95), PotterBooks.PriceAllBooks(new List <int> {
         1, 1, 2, 3, 3, 4
     }));
     Assert.AreEqual(8 + (8 * 5 * 0.75), PotterBooks.PriceAllBooks(new List <int> {
         1, 2, 2, 3, 4, 5
     }));
 }
Exemplo n.º 14
0
        public void 測試_只買第一集價錢為100()
        {
            ///Arrange
            var target = new PotterBooks();

            _dummyBooks.Add(new Book {
                Id = 1, Name = "哈利波特第一集", Price = 100
            });
            decimal expected = 100;

            ///Act
            var actual = target.Calculate(this._dummyBooks);

            ///Assert
            expected.ToExpectedObject().ShouldEqual(actual);
        }
Exemplo n.º 15
0
 public void TestBasics()
 {
     Assert.AreEqual(0, PotterBooks.PriceAllBooks(new List <int>()));
     Assert.AreEqual(8, PotterBooks.PriceAllBooks(new List <int> {
         1
     }));
     Assert.AreEqual(8, PotterBooks.PriceAllBooks(new List <int> {
         2
     }));
     Assert.AreEqual(8, PotterBooks.PriceAllBooks(new List <int> {
         3
     }));
     Assert.AreEqual(8, PotterBooks.PriceAllBooks(new List <int> {
         4
     }));
     Assert.AreEqual(8, PotterBooks.PriceAllBooks(new List <int> {
         5
     }));
     Assert.AreEqual(24, PotterBooks.PriceAllBooks(new List <int> {
         1, 1, 1
     }));
 }
Exemplo n.º 16
0
        public void NoBooksCostZero()
        {
            var price = PotterBooks.CalculatePriceFor(string.Empty);

            AssertPrice(price, 0 * PotterBooks.UnitBookPrice);
        }
Exemplo n.º 17
0
        public void ASingleBookIsPricedCorrectly(string books)
        {
            var price = PotterBooks.CalculatePriceFor(books);

            AssertPrice(price, 1 * PotterBooks.UnitBookPrice);
        }
Exemplo n.º 18
0
        public void SimpleDiscountCombinationsArePricedCorrectly(string books, double expectedPrice)
        {
            var price = PotterBooks.CalculatePriceFor(books);

            AssertPrice(price, expectedPrice);
        }
Exemplo n.º 19
0
        public void MultipleBooksOfDifferentTypesArePricedCorrectly(string books, double expectedPrice)
        {
            var price = PotterBooks.CalculatePriceFor(books);

            AssertPrice(price, expectedPrice);
        }
Exemplo n.º 20
0
        [TestCase("AAAAABBBBBCCCCDDDDDEEEE", (3 * (5 * PotterBooks.UnitBookPrice * 0.75d)) + (2 * (4 * PotterBooks.UnitBookPrice * 0.80d)))] // = ABCDE + ABCDE + ABCDE + ABCD + ABDE
        public void EdgeCaseIsPricedCorrectly(string books, double expectedPrice)
        {
            var price = PotterBooks.CalculatePriceFor(books);

            AssertPrice(price, expectedPrice);
        }