0% found this document useful (0 votes)
4 views

đáp-án-fall2024-1

The document outlines various defects in code, including naming convention errors and logical errors, along with proposed fixing solutions. It also details multiple test cases for a calculator application that calculates total prices for different customer types and discount codes. Additionally, it includes test cases for order processing scenarios, covering successful and failed transactions based on discount codes and payment details.

Uploaded by

Lê Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

đáp-án-fall2024-1

The document outlines various defects in code, including naming convention errors and logical errors, along with proposed fixing solutions. It also details multiple test cases for a calculator application that calculates total prices for different customer types and discount codes. Additionally, it includes test cases for order processing scenarios, covering successful and failed transactions based on discount codes and payment details.

Uploaded by

Lê Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Q1:

Defect Defect Name Line Description Fixing Solution


ID
DF001 Naming 1 Class name should be Replace class name from ” fileProcessor” to
convention error in PascalCase “FileProcessor”
DF002 Naming 3 Variable name should Replace the variable name from “FilePath”
convention error be in camelCase to “filePath”
DF003 Logical error 7 Validation for reader, Replace condition to
not for filePath “if (reader != null || reader.isEmpty())”
DF004 Logical error 7 Incorrect condition Replace condition “reader.isEmpty()” to “!
when checking open reader.isEmpty()”
file process
DF005 Logical error 27 -> Validate filePath after Check the condition for “filePath == null”
32 open file is before processing openFile()
unecessary
DF006 Accessibility 27 + 33 Access non static Add static keyword when define method
error methods openFile() and readFile()

Q2:

ID TC1
Test for VIP customer with no discount code
Input itemPrices = {100, 200}
parameter customerType = “VIP”
isVip = true
discountCode = null
Expected 240
result
Test code @Test
public void testVIPCustomerWithNoDiscountCode() {
double total = calculator.calculateTotalPrice(new double[] {100, 200}, "VIP", true,
null);
assertEquals(240, total, 0.01);
}

ID TC2
Test for VIP customer with discount code “SALE10”
Input itemPrices = {100, 200}
parameter customerType = “VIP”
isVip = true
discountCode = “SALE10”
Expected 210
result
Test code @Test
public void testVIPCustomerWithDiscountCodeSale10() {
double total = calculator.calculateTotalPrice(new double[] {100, 200}, "VIP", true,
"SALE10");
assertEquals(210, total, 0.01);
}

ID TC3
Test for VIP customer with discount code “WELCOME5”
Input itemPrices = {100, 200}
parameter customerType = “VIP”
isVip = true
discountCode = “WELCOME5”
Expected 225
result
Test code @Test
public void testVIPCustomerWithDiscountCodeWelcome5() {
double total = calculator.calculateTotalPrice(new double[] {100, 200}, "VIP", true,
"WELCOME5");
assertEquals(225, total, 0.01);
}

ID TC4
Test for Regular customer with no discount code
Input itemPrices = {100, 200}
parameter customerType = “Regular”
isVip = false
discountCode = null
Expected 285
result
Test code @Test
public void testRegularCustomerWithNoDiscountCode() {
double total = calculator.calculateTotalPrice(new double[] {100, 200}, "Regular",
false, null);
assertEquals(285, total, 0.01);
}

ID TC5
Test for Regular customer with discount code “SALE10”
Input itemPrices = {100, 200}
parameter customerType = “Regular”
isVip = false
discountCode = “SALE10”
Expected 255
result
Test code @Test
public void testRegularCustomerWithDiscountCodeSale10() {
double total = calculator.calculateTotalPrice(new double[] {100, 200}, "Regular",
false, "SALE10");
assertEquals(255, total, 0.01);
}

ID TC6
Test for Regular customer with discount code “WELCOME5”
Input itemPrices = {100, 200}
parameter customerType = “Regular”
isVip = false
discountCode = “WELCOME5”
Expected 270
result
Test code @Test
public void testRegularCustomerWithDiscountCodeWelcome5() {
double total = calculator.calculateTotalPrice(new double[] {100, 200}, "Regular",
false, "WELCOME5");
assertEquals(270, total, 0.01);
}

ID TC7
Test for Normal customer (non-VIP and non-regular) with no discount code
Input itemPrices = {100, 200}
parameter customerType = “Normal”
isVip = false
discountCode = null
Expected 300
result
Test code @Test
public void testNormalCustomerWithNoDiscountCode() {
double total = calculator.calculateTotalPrice(new double[] {100, 200}, "Normal",
false, null);
assertEquals(300, total, 0.01);
}

ID TC8
Test for Normal customer (non-VIP and non-regular) with discount code “SALE10”
Input itemPrices = {100, 200}
parameter customerType = “Normal”
isVip = false
discountCode = “SALE10”
Expected 270
result
Test code @Test
public void testNormalCustomerWithDiscountCodeSale10() {
double total = calculator.calculateTotalPrice(new double[] {100, 200}, "Normal",
false, "SALE10");
assertEquals(270, total, 0.01);
}

ID TC9
Test for Normal customer (non-VIP and non-regular) with discount code “WELCOME5”
Input itemPrices = {100, 200}
parameter customerType = “Normal”
isVip = false
discountCode = “WELCOME5”
Expected 285
result
Test code @Test
public void testNormalCustomerWithDiscountCodeWelcome5() {
double total = calculator.calculateTotalPrice(new double[] {100, 200}, "Normal",
false, "WELCOME5");
assertEquals(285, total, 0.01);
}

Q3:
ID: TC001
Description: Test order success with discount code
Precondition:
- The customer id logged in
- The shopping cart contains at least item (Eg: a tea cup for 2$)
Test steps:
- Customer add a tea cup to their shopping cart
- Customer applies discount code “SAVE10”
- System validates the discount code “SAVE10”
- The customer proceeds to checkout
- The system displays the bill: Total Amount = 1.8$, Discount = 10%
- Customer select a credit card payment
- Customer provide card number “1234 5678 9101 1121”
- System processes the payment
- The system confirms the order and generates an order confirmation
Expected results:
- The customer receives an order confirmation and an estimated delivery time.
- The system updates the inventory base on the order
Notes: Normal Flow (NF)

ID: TC002
Description: Test order fail due to empty cart
Precondition:
- The customer id logged in
- The shopping cart does not contain any item
Test steps:
- Customer view an empty cart
- The customer proceeds to checkout
- The system displays: “Cart is empty, please add items to the cart to proceed checkout.”
Expected results:
- The customer receives a notification message about empty cart from the system
Notes: Alternative Flow (A1)

ID: TC003
Description: Test order fail due to invalid discount code
Precondition:
- The customer id logged in
- The shopping cart contains at least item (Eg: a tea cup for 2$)
Test steps:
- Customer add a tea cup to their shopping cart
- Customer applies discount code “SAVE50”
- System validates the discount code “SAVE50”
- The customer proceeds to checkout
- The system displays a warning notification: “Discount code is invalid”
- The system ask customer to refill the discount code
Expected results:
- The customer receives a notification message about invalid discount code from the
system
- The system asks the customer to refill the discount code
Notes: Alternative Flow (A2)
ID: TC004
Description: Test order fail due to invalid card detail
Precondition:
- The customer id logged in
- The shopping cart contains at least item (Eg: a tea cup for 2$)
Test steps:
- Customer add a tea cup to their shopping cart
- The customer proceeds to checkout
- The system displays the bill: Total Amount = 2$, Discount = 0
- Customer select a credit card payment
- Customer provide card number “1234 5678 9101 1121”
- System displays a warning notification: “Card number is invalid”
- System asks customer to refill card detail
Expected results:
- The customer receives a notification message about invalid card detail from the system
- The system asks the customer to refill the card detail
Notes: Alternative Flow (A3)

You might also like