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 with 0.0d for edu/ucsb/cs156/happiercows/services/AverageCowHealthService::getAverageCowHealth → KILLED
|
return totalCows == 0 ? 0 :totalHealth / totalCows; |
31
|
|
} |
32
|
|
} |
| | 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()] 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()] 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 with 0.0d for edu/ucsb/cs156/happiercows/services/AverageCowHealthService::getAverageCowHealth → KILLED
|