Студопедия

Главная страница Случайная страница

Разделы сайта

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






Item.Type.SECOND,






Item.Type.REGULAR,

Item.Type.SALE,

Item.Type.DISCOUNT

};

private static final int[][] D_VALUES =

{

{ 0 },

{ 0, 0, 0, 0},

{ 90 },

{ 10, 10, 20, 20}

};

@Parameterized.Parameters

@SuppressWarnings(" unchecked")

Public static Collection getTypeQuantityPairs()

{

Collection pairs = new ArrayList();

for (int q = 0; q < Q_VALUES.length; q++)

for (int t = 0; t < T_VALUES.length; t++)

pairs.add(new Object[] {

T_VALUES[t],

Q_VALUES[q],

(D_VALUES[t].length > q)

? D_VALUES[t][q]

: D_VALUES[t][D_VALUES[t].length - 1]

});

Return pairs;

}

Private Item.Type _type;

Private int _quantity;

Private int _discount;

public DiscountTest(Item.Type type, int quantity, int discount){

_type = type;

_quantity = quantity;

_discount = discount;

}

@Test

public void discountTest(){

assertEquals(" type: " + _type + ", quantity: " + _quantity,

_discount,

ShoppingCart.calculateDiscount(

new Item(" Title", 5.99f, _type, _quantity)

),

F

);

}

}

1) Значення _quantity з масиву {1, 9, 10, 19} перевіряє граничні умови

а) більше одного;

б) повний десяток.

2) Значення _type з масиву { SECOND, REGULAR, SALE, DISCOUNT} переві-ряє всі можливі значення типу товару.

3) Значення _discount містить для кожного типу товару очікувані значення знижок при різних його кількостях.

Нижче приведено програмний код класу ShoppingCart.

import java.util.*;

import java.text.*;

/**

* Containing items and calculating price.

*/

Public class ShoppingCart

{

/**

* Tests all class methods.

*/

public static void main(String[] args)

{

// TODO: add tests here

ShoppingCart cart = new ShoppingCart();

cart.addItem(" Apple", 0.99, 5, Item.Type.REGULAR);

cart.addItem(" Banana", 20.00, 4, Item.Type.DISCOUNT);

cart.addItem(" A long piece of toilet paper", 17.20, 1, Item.Type.SALE);

cart.addItem(" Nails", 2.00, 500, Item.Type.REGULAR);

System.out.println(cart.toString());

}

/**

* Adds new item.

*

* @param title item title 1 to 32 symbols

* @param price item ptice in cents, > 0, < 1000

* @param quantity item quantity, from 1 to 1000

* @param type item type, on enum Item.Type

*

* @throws IndexOutOfBoundsException if total items added over 99

* @throws IllegalArgumentException if some value is wrong

*/

Public void addItem(String title, double price, int quantity, Item.Type type)

{

if (title == null || title.length() == 0 || title.length() > 32)

throw new IllegalArgumentException(" Illegal title");

if (price < 0.01 || price > = 1000.00)

throw new IllegalArgumentException(" Illegal price");

if (quantity < = 0 || quantity > 1000)

throw new IllegalArgumentException(" Illegal quantity");

if (items.size() == 99)

throw new IndexOutOfBoundsException(" No more space in cart");

Item item = new Item();

item.title = title;

item.price = price;

item.quantity = quantity;

item.type = type;






© 2023 :: MyLektsii.ru :: Мои Лекции
Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав.
Копирование текстов разрешено только с указанием индексируемой ссылки на источник.