Coder Social home page Coder Social logo

shoppingcart's Introduction

自動測試與 TDD 實務開發(第五梯) 第二週作業

JAVA(JUNIT)

題目

User Story 哈利波特一到五冊熱潮正席捲全球,世界各地的孩子都為之瘋狂。 出版社為了慶祝TDD課程招生順利,決定訂出極大的優惠,來回饋給為了小孩四處奔波買書的父母親們。 定價的方式如下:

  1. 一到五集的哈利波特,每一本都是賣100元
  2. 如果你從這個系列買了兩本不同的書,則會有5%的折扣
  3. 如果你買了三本不同的書,則會有10%的折扣
  4. 如果是四本不同的書,則會有20%的折扣
  5. 如果你一次買了整套一到五集,恭喜你將享有25%的折扣
  6. 需要留意的是,如果你買了四本書,其中三本不同,第四本則是重複的,那麼那三本將享有10%的折扣,但重複的那一本,則仍須100元。

你的任務是,設計一個哈利波特的購物車,能提供最便宜的價格給這些爸爸媽媽。

Feature: PotterShoppingCart
	In order to 提供最便宜的價格給來買書的爸爸媽媽
	As a 佛心的出版社老闆
	I want to 設計一個哈利波特的購物車

Scenario: 第一集買了一本,其他都沒買,價格應為 (100 * 1) = 100 元
	Given 第一集買了 1 本
	And 第二集買了 0 本
	And 第三集買了 0 本
	And 第四集買了 0 本
	And 第五集買了 0 本
	When 結帳
	Then 價格應為 100 元

Scenario: 第一集買了一本,第二集也買了一本,價格應為 (100 * 2 * 0.95) = 190
	Given 第一集買了 1 本
	And 第二集買了 1 本
	And 第三集買了 0 本
	And 第四集買了 0 本
	And 第五集買了 0 本
	When 結帳
	Then 價格應為 190 元

Scenario: 一二三集各買了一本,價格應為 (100 * 3 * 0.9) = 270
	Given 第一集買了 1 本
	And 第二集買了 1 本
	And 第三集買了 1 本
	And 第四集買了 0 本
	And 第五集買了 0 本
	When 結帳
	Then 價格應為 270 元

Scenario: 一二三四集各買了一本,價格應為 (100 * 4 * 0.8) = 320
	Given 第一集買了 1 本
	And 第二集買了 1 本
	And 第三集買了 1 本
	And 第四集買了 1 本
	And 第五集買了 0 本
	When 結帳
	Then 價格應為 320 元

Scenario: 一次買了整套,一二三四五集各買了一本,價格應為 (100 * 5 * 0.75) = 375
	Given 第一集買了 1 本
	And 第二集買了 1 本
	And 第三集買了 1 本
	And 第四集買了 1 本
	And 第五集買了 1 本
	When 結帳
	Then 價格應為 375 元

Scenario: 一二集各買了一本,第三集買了兩本,價格應為 (100 * 3 * 0.9) + 100 = 370
	Given 第一集買了 1 本
	And 第二集買了 1 本
	And 第三集買了 2 本
	And 第四集買了 0 本
	And 第五集買了 0 本
	When 結帳
	Then 價格應為 370 元

Scenario: 第一集買了一本,第二三集各買了兩本,價格應為 (100 * 3 * 0.9) + ( 100 * 2 * 0.95) = 460
	Given 第一集買了 1 本
	And 第二集買了 2 本
	And 第三集買了 2 本
	And 第四集買了 0 本
	And 第五集買了 0 本
	When 結帳
	Then 價格應為 460 元

作業要求:

  1. 先寫測試案例,
  2. 一次只寫一個測試案例
  3. Production code用最簡單的方式通過測試案例,甚至hard code

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.