nhu313 2e79537d56 Update 'README.md' | 6 年之前 | |
---|---|---|
src | 6 年之前 | |
.gitignore | 6 年之前 | |
README.md | 6 年之前 | |
pom.xml | 6 年之前 |
In the test
folder, there is a ProductTest
with most of the tested commented out.
testConstruction_WithNoParams
checks to see if the Product
class has an empty constructor. To test it, I created a new object with no parameter.testGetSetName
checks to see if you can set and get the name of the product. In order to make this pass, I added a String
field called name
(line 5). Then I added a getter method getName
(line 18-20) and a setter method setName(String name)
(line 23-25).testConstruction_WithName
checks if the Product
class has a constructor that takes a String. Notice we can have more than one constructor. When I create a new Product with a string new Product("T-shirt")
, I set that string to the field name
so when I called getName
, I get the string that I passed into the constructor.title (Color: color, Size: size)
Hat (Color: Yellow, Size: LG)
A cart has an array of Product.
CartTest
and uncomment line 9-13. To make the test pass:
Cart
testGetProducts
test passtestGetSetDiscount
test pass:
discount
getProductTotal
tests to pass, you need add all the product prices together and return the result.The goal of this exercise is to know how to create and test a class.
CreditCardTest
CreditCard
cardHolderName
of the type String
CreditCard
classString number
int expiredMonth
int expiredYear
getDescription
getDescription
should return [cardHolderName] [last 4 digit of the number] [expiredMonth]/[expiredYear]
Tia Mowry 4551 10/2019
CreditCard
field to the Cart
class
creditCard
fieldThe goal of this exercise is to change the products
array in the Cart
class to an ArrayList.
In the CartTest
, change the products
array to an ArrayList
ArrayList<Product> products = new ArrayList();
products.add(new Product("Shirt", 15.01));
Add this test to the CartTest
class
@Test
public void testAddToCard(){
// Given
ArrayList<Product> products = new ArrayList();
Cart cart = new Cart(products);
// When
Product shirt = new Product("Shirt", 1.99);
cart.addProduct(shirt);
// Then
double expectedTotal = 1.99;
double actualTotal = cart.getProductTotal();
Assert.assertEquals(expectedTotal, actualTotal, DELTA);
}
addProduct
method to the Cart
class