AverageCowHealthService.java

1
package edu.ucsb.cs156.happiercows.services;
2
3
import org.springframework.beans.factory.annotation.Autowired;
4
import org.springframework.stereotype.Service;
5
6
import edu.ucsb.cs156.happiercows.entities.UserCommons;
7
8
import edu.ucsb.cs156.happiercows.repositories.UserCommonsRepository;
9
10
@Service
11
public class AverageCowHealthService {
12
13
    @Autowired
14
    UserCommonsRepository userCommonsRepository;
15
16
    public Double getAverageCowHealth(Long commonsId) {
17
        Iterable<UserCommons> userCommonsList = userCommonsRepository.findByCommonsId(commonsId);
18
        Double totalHealth = 0.0;
19
        int totalCows = 0;
20
21
        for(UserCommons userCommons: userCommonsList){
22 2 1. getAverageCowHealth : Replaced double multiplication with division → KILLED
2. getAverageCowHealth : Replaced double addition with subtraction → KILLED
            totalHealth += userCommons.getCowHealth() * userCommons.getNumOfCows();
23 1 1. getAverageCowHealth : Replaced integer addition with subtraction → KILLED
            totalCows += userCommons.getNumOfCows();
24
        }
25
26 1 1. getAverageCowHealth : negated conditional → KILLED
        if(!userCommonsList.iterator().hasNext()){
27
            throw new IllegalArgumentException("Unable to get average cow health");
28
        }
29
30 3 1. getAverageCowHealth : Replaced double division with multiplication → KILLED
2. getAverageCowHealth : negated conditional → KILLED
3. getAverageCowHealth : replaced Double return value with 0 for edu/ucsb/cs156/happiercows/services/AverageCowHealthService::getAverageCowHealth → KILLED
        return totalCows == 0 ? 0 :totalHealth / totalCows;
31
32
33
    }
34
35
    
36
}

Mutations

22

1.1
Location : getAverageCowHealth
Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest]/[method:testGetAverageCowHealth()]
Replaced double multiplication with division → KILLED

2.2
Location : getAverageCowHealth
Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest]/[method:testGetAverageCowHealth()]
Replaced double addition with subtraction → KILLED

23

1.1
Location : getAverageCowHealth
Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest]/[method:testGetAverageCowHealth()]
Replaced integer addition with subtraction → KILLED

26

1.1
Location : getAverageCowHealth
Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest]/[method:testGetAverageCowHealth_throwException()]
negated conditional → KILLED

30

1.1
Location : getAverageCowHealth
Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest]/[method:testGetAverageCowHealth()]
Replaced double division with multiplication → KILLED

2.2
Location : getAverageCowHealth
Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest]/[method:testGetAverageCowHealth_zeroCows()]
negated conditional → KILLED

3.3
Location : getAverageCowHealth
Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest]/[method:testGetAverageCowHealth()]
replaced Double return value with 0 for edu/ucsb/cs156/happiercows/services/AverageCowHealthService::getAverageCowHealth → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3