TicketPriceCalculator.java

1
// TicketPriceCalculator.java
2
package tpcalc;
3
import java.util.List;
4
5
public class TicketPriceCalculator {
6
7
    private static int ADULT_AGE = 18;
8
    private static int FREE_TICKET_AGE_BELOW = 3;
9
    public static double FAMILY_DISCOUNT = 0.05;
10
11
    public double calculatePrice(List<Passenger> passengers, int adultTicketPrice, int childTicketPrice) {
12
        int totalPrice = 0;
13
        int childrenCounter = 0;
14
        int adultCounter = 0;
15
        double result;
16
        for (Passenger passenger : passengers) {
17 2 1. calculatePrice : changed conditional boundary → KILLED
2. calculatePrice : negated conditional → KILLED
            if (passenger.getAge() > ADULT_AGE) {
18 1 1. calculatePrice : Replaced integer addition with subtraction → KILLED
                totalPrice += adultTicketPrice;
19 1 1. calculatePrice : Changed increment from 1 to -1 → KILLED
                adultCounter++;
20 2 1. calculatePrice : changed conditional boundary → KILLED
2. calculatePrice : negated conditional → KILLED
            } else if (passenger.getAge() > FREE_TICKET_AGE_BELOW) {
21 1 1. calculatePrice : Replaced integer addition with subtraction → KILLED
                totalPrice += childTicketPrice;
22 1 1. calculatePrice : Changed increment from 1 to -1 → KILLED
                childrenCounter++;
23
            }
24
        }
25
26 4 1. calculatePrice : changed conditional boundary → SURVIVED
2. calculatePrice : changed conditional boundary → SURVIVED
3. calculatePrice : negated conditional → KILLED
4. calculatePrice : negated conditional → KILLED
        if (childrenCounter > 1 && adultCounter > 1) {
27 2 1. calculatePrice : Replaced double subtraction with addition → KILLED
2. calculatePrice : Replaced double multiplication with division → KILLED
            result = (1 - FAMILY_DISCOUNT) * totalPrice;
28
        } else {
29
            result = totalPrice;
30
        }
31
32 1 1. calculatePrice : replaced return of double value with -(x + 1) for tpcalc/TicketPriceCalculator::calculatePrice → KILLED
        return result;
33
    }
34
}

Mutations

17

1.1
Location : calculatePrice
Killed by : tpcalc.TicketPriceCalculatorTest.calculatePriceForChildNarrowCase(tpcalc.TicketPriceCalculatorTest)
changed conditional boundary → KILLED

2.2
Location : calculatePrice
Killed by : tpcalc.TicketPriceCalculatorTest.calculatePriceForChild(tpcalc.TicketPriceCalculatorTest)
negated conditional → KILLED

18

1.1
Location : calculatePrice
Killed by : tpcalc.TicketPriceCalculatorTest.calculatePriceForFamily(tpcalc.TicketPriceCalculatorTest)
Replaced integer addition with subtraction → KILLED

19

1.1
Location : calculatePrice
Killed by : tpcalc.TicketPriceCalculatorTest.calculatePriceForFamily(tpcalc.TicketPriceCalculatorTest)
Changed increment from 1 to -1 → KILLED

20

1.1
Location : calculatePrice
Killed by : tpcalc.TicketPriceCalculatorTest.calculatePriceForFreeTicketNarrowCase(tpcalc.TicketPriceCalculatorTest)
changed conditional boundary → KILLED

2.2
Location : calculatePrice
Killed by : tpcalc.TicketPriceCalculatorTest.calculatePriceForChild(tpcalc.TicketPriceCalculatorTest)
negated conditional → KILLED

21

1.1
Location : calculatePrice
Killed by : tpcalc.TicketPriceCalculatorTest.calculatePriceForChild(tpcalc.TicketPriceCalculatorTest)
Replaced integer addition with subtraction → KILLED

22

1.1
Location : calculatePrice
Killed by : tpcalc.TicketPriceCalculatorTest.calculatePriceForFamily(tpcalc.TicketPriceCalculatorTest)
Changed increment from 1 to -1 → KILLED

26

1.1
Location : calculatePrice
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : calculatePrice
Killed by : none
changed conditional boundary → SURVIVED

3.3
Location : calculatePrice
Killed by : tpcalc.TicketPriceCalculatorTest.calculatePriceForFamily(tpcalc.TicketPriceCalculatorTest)
negated conditional → KILLED

4.4
Location : calculatePrice
Killed by : tpcalc.TicketPriceCalculatorTest.calculatePriceForFamily(tpcalc.TicketPriceCalculatorTest)
negated conditional → KILLED

27

1.1
Location : calculatePrice
Killed by : tpcalc.TicketPriceCalculatorTest.calculatePriceForFamily(tpcalc.TicketPriceCalculatorTest)
Replaced double subtraction with addition → KILLED

2.2
Location : calculatePrice
Killed by : tpcalc.TicketPriceCalculatorTest.calculatePriceForFamily(tpcalc.TicketPriceCalculatorTest)
Replaced double multiplication with division → KILLED

32

1.1
Location : calculatePrice
Killed by : tpcalc.TicketPriceCalculatorTest.calculatePriceForChild(tpcalc.TicketPriceCalculatorTest)
replaced return of double value with -(x + 1) for tpcalc/TicketPriceCalculator::calculatePrice → KILLED

Active mutators

Tests examined


Report generated by PIT 1.2.5