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
|
|
import edu.ucsb.cs156.happiercows.repositories.UserCommonsRepository; |
8
|
|
|
9
|
|
@Service |
10
|
|
public class AverageCowHealthService { |
11
|
|
|
12
|
|
@Autowired |
13
|
|
private UserCommonsRepository userCommonsRepository; |
14
|
|
|
15
|
|
public Double getAverageCowHealth(Long commonsId) { |
16
|
|
Iterable<UserCommons> userCommonsList = userCommonsRepository.findByCommonsId(commonsId); |
17
|
|
Double totalHealth = 0.0; |
18
|
|
int totalCows = 0; |
19
|
|
|
20
|
|
for(UserCommons userCommons: userCommonsList){ |
21
|
2
1. getAverageCowHealth : Replaced double multiplication with division → KILLED
2. getAverageCowHealth : Replaced double addition with subtraction → KILLED
|
totalHealth += userCommons.getCowHealth() * userCommons.getNumOfCows(); |
22
|
1
1. getAverageCowHealth : Replaced integer addition with subtraction → KILLED
|
totalCows += userCommons.getNumOfCows(); |
23
|
|
} |
24
|
|
|
25
|
1
1. getAverageCowHealth : negated conditional → KILLED
|
if(!userCommonsList.iterator().hasNext()){ |
26
|
|
throw new IllegalArgumentException("Unable to get average cow health"); |
27
|
|
} |
28
|
|
|
29
|
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; |
30
|
|
} |
31
|
|
} |
| | Mutations |
21 |
|
1.1 Location : getAverageCowHealth Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest]/[method:testGetAverageCowHealth_PositiveHealthZeroCows()] 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_PositiveHealthZeroCows()] Replaced double addition with subtraction → KILLED
|
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_PositiveHealthZeroCows()] Replaced integer addition with subtraction → KILLED
|
25 |
|
1.1 Location : getAverageCowHealth Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest]/[method:testGetAverageCowHealth_NoUserCommons()] negated conditional → KILLED
|
29 |
|
1.1 Location : getAverageCowHealth Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTest]/[method:testGetAverageCowHealth_PositiveHealthZeroCows()] 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_AllCowsZero()] 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_PositiveHealthZeroCows()] replaced Double return value with 0 for edu/ucsb/cs156/happiercows/services/AverageCowHealthService::getAverageCowHealth → KILLED
|