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
import edu.ucsb.cs156.happiercows.repositories.CommonsRepository;
8
import edu.ucsb.cs156.happiercows.repositories.UserCommonsRepository;
9
10
@Service("AverageCowHealthService")
11
public class AverageCowHealthService {
12
13
    @Autowired
14
    CommonsRepository commonsRepository;
15
16
    @Autowired
17
    UserCommonsRepository userCommonsRepository;
18
19
    public int getTotalNumCows(Long commonsId) {
20 1 1. lambda$getTotalNumCows$0 : replaced return value with null for edu/ucsb/cs156/happiercows/services/AverageCowHealthService::lambda$getTotalNumCows$0 → KILLED
        commonsRepository.findById(commonsId).orElseThrow(() -> new IllegalArgumentException(String.format("Commons with id %d not found", commonsId)));
21
22
        Iterable<UserCommons> allUserCommons = userCommonsRepository.findByCommonsId(commonsId);
23
24
        int totalNumCows = 0;
25
26
        for (UserCommons userCommons : allUserCommons) {
27 1 1. getTotalNumCows : Replaced integer addition with subtraction → KILLED
            totalNumCows += userCommons.getNumOfCows();
28
        }
29
30 1 1. getTotalNumCows : replaced int return with 0 for edu/ucsb/cs156/happiercows/services/AverageCowHealthService::getTotalNumCows → KILLED
        return totalNumCows;
31
    }
32
33
    public double getAverageCowHealth(Long commonsId) {
34 1 1. lambda$getAverageCowHealth$1 : replaced return value with null for edu/ucsb/cs156/happiercows/services/AverageCowHealthService::lambda$getAverageCowHealth$1 → KILLED
        commonsRepository.findById(commonsId).orElseThrow(() -> new IllegalArgumentException(String.format("Commons with id %d not found", commonsId)));
35
36
        Iterable<UserCommons> allUserCommons = userCommonsRepository.findByCommonsId(commonsId);
37
38
        double totalHealth = 0;
39
40
        for (UserCommons userCommons : allUserCommons) {
41 2 1. getAverageCowHealth : Replaced double multiplication with division → KILLED
2. getAverageCowHealth : Replaced double addition with subtraction → KILLED
            totalHealth += userCommons.getCowHealth() * userCommons.getNumOfCows();
42
        }
43
44 2 1. getAverageCowHealth : Replaced double division with multiplication → KILLED
2. getAverageCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/services/AverageCowHealthService::getAverageCowHealth → KILLED
        return totalHealth / getTotalNumCows(commonsId);
45
    }
46
47
    
48
}

Mutations

20

1.1
Location : lambda$getTotalNumCows$0
Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTests]/[method:test_getTotalNumCowsThrowsException()]
replaced return value with null for edu/ucsb/cs156/happiercows/services/AverageCowHealthService::lambda$getTotalNumCows$0 → KILLED

27

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

30

1.1
Location : getTotalNumCows
Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTests]/[method:test_getAverageCowHealthOneUser()]
replaced int return with 0 for edu/ucsb/cs156/happiercows/services/AverageCowHealthService::getTotalNumCows → KILLED

34

1.1
Location : lambda$getAverageCowHealth$1
Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTests]/[method:test_getAverageCowHealthThrowsException()]
replaced return value with null for edu/ucsb/cs156/happiercows/services/AverageCowHealthService::lambda$getAverageCowHealth$1 → KILLED

41

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

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

44

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

2.2
Location : getAverageCowHealth
Killed by : edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.AverageCowHealthServiceTests]/[method:test_getAverageCowHealthOneUser()]
replaced double return with 0.0d for edu/ucsb/cs156/happiercows/services/AverageCowHealthService::getAverageCowHealth → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3