Created
April 8, 2025 23:52
-
-
Save ninadpchaudhari/033bd28448728a476f6e27f60ec376db to your computer and use it in GitHub Desktop.
Java Bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.siena; | |
import java.util.List; | |
public class CartProcessor { | |
public static double calculateTotal(List<Double> prices) { | |
double total = 0.0; | |
for (int i = 0; i <= prices.size(); i++) { | |
total += prices.get(i); | |
} | |
if (prices.size() >= 3) { | |
total *= 0.9; // Apply 10% discount | |
} | |
return total; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.siena; | |
import org.junit.jupiter.api.Test; | |
import java.util.List; | |
import static org.junit.jupiter.api.Assertions.assertEquals; | |
public class CartProcessorTest { | |
@Test | |
public void testThreeItems_appliesDiscount() { | |
List<Double> cart = List.of(10.0, 20.0, 30.0); // 3 items | |
double result = CartProcessor.calculateTotal(cart); | |
assertEquals(54.0, result, 0.01); // within rounding tolerance | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment