Calculator.java

1
package rs.etf.ts.calculator;
2
import rs.etf.ts.storage.*;
3
4
public class Calculator {
5
6
    private final ResultStorage storage;
7
8
    public Calculator(ResultStorage storage) {
9
        this.storage = storage;
10
    }
11
12
    public void add(int n) {
13
        int result = storage.get();
14 1 1. add : Replaced integer addition with subtraction → KILLED
        result = result + n;
15 1 1. add : removed call to rs/etf/ts/storage/ResultStorage::set → KILLED
        storage.set(result);
16
    }
17
18
    public void substract(int n) {
19
        int result = storage.get();
20 1 1. substract : Replaced integer subtraction with addition → NO_COVERAGE
        result = result - 1;        // BUG: should subtract n
21 1 1. substract : removed call to rs/etf/ts/storage/ResultStorage::set → NO_COVERAGE
        storage.set(result);
22
    }
23
24
    public void substract2(int x, int y) {
25 1 1. substract2 : Replaced integer subtraction with addition → KILLED
        int result = x - y;
26 1 1. substract2 : removed call to rs/etf/ts/storage/ResultStorage::set → KILLED
        storage.set(result);
27
    }
28
29
    public void multiply(int n) {
30
        int result = storage.get();
31 1 1. multiply : Replaced integer multiplication with division → KILLED
        result = result * n;
32 1 1. multiply : removed call to rs/etf/ts/storage/ResultStorage::set → KILLED
        storage.set(result);
33
    }
34
35
    public void divide(int n) {
36
        int result = storage.get();
37 1 1. divide : Replaced integer division with multiplication → KILLED
        result = result / n;
38 1 1. divide : removed call to rs/etf/ts/storage/ResultStorage::set → KILLED
        storage.set(result);
39
    }
40
41
    public void square(int n) {
42 1 1. square : Replaced integer multiplication with division → NO_COVERAGE
        int result = n * n;
43 1 1. square : removed call to rs/etf/ts/storage/ResultStorage::set → NO_COVERAGE
        storage.set(result);
44
    }
45
46
    public void squareRoot(int n) {
47
        n = storage.get();      // BUG: value of n is ignored
48 2 1. squareRoot : negated conditional → NO_COVERAGE
2. squareRoot : changed conditional boundary → NO_COVERAGE
        if (n < 0) {
49 1 1. squareRoot : removed call to rs/etf/ts/storage/ResultStorage::set → NO_COVERAGE
            storage.set(0);
50
        } else {
51 1 1. squareRoot : removed call to rs/etf/ts/storage/ResultStorage::set → NO_COVERAGE
            storage.set((int) Math.sqrt(n));
52
        }
53
    }
54
55
    public void clear() {
56 1 1. clear : removed call to rs/etf/ts/storage/ResultStorage::set → KILLED
        storage.set(0);
57
    }
58
59
    public void switchOn() {
60 1 1. switchOn : removed call to rs/etf/ts/storage/ResultStorage::set → SURVIVED
        storage.set(0);
61
    }
62
63
    public void switchOff() {
64 1 1. switchOff : removed call to rs/etf/ts/storage/ResultStorage::set → SURVIVED
        storage.set(0);
65
    }
66
67
    public int getResult() {
68 1 1. getResult : replaced int return with 0 for rs/etf/ts/calculator/Calculator::getResult → KILLED
        return storage.get();
69
    }
70
71
    public void setResult(int n) {
72 1 1. setResult : removed call to rs/etf/ts/storage/ResultStorage::set → KILLED
        storage.set(n);
73
    }
74
75
    public boolean isPositive() {
76 3 1. isPositive : changed conditional boundary → KILLED
2. isPositive : negated conditional → KILLED
3. isPositive : replaced boolean return with true for rs/etf/ts/calculator/Calculator::isPositive → KILLED
        return storage.get() > 0;
77
    }
78
}

Mutations

14

1.1
Location : add
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:additionTest()]
Replaced integer addition with subtraction → KILLED

15

1.1
Location : add
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:additionTest()]
removed call to rs/etf/ts/storage/ResultStorage::set → KILLED

20

1.1
Location : substract
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

21

1.1
Location : substract
Killed by : none
removed call to rs/etf/ts/storage/ResultStorage::set → NO_COVERAGE

25

1.1
Location : substract2
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:subtraction2Test()]
Replaced integer subtraction with addition → KILLED

26

1.1
Location : substract2
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:subtraction2Test()]
removed call to rs/etf/ts/storage/ResultStorage::set → KILLED

31

1.1
Location : multiply
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:multiplicationTest()]
Replaced integer multiplication with division → KILLED

32

1.1
Location : multiply
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:multiplicationTest()]
removed call to rs/etf/ts/storage/ResultStorage::set → KILLED

37

1.1
Location : divide
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:divisionTest()]
Replaced integer division with multiplication → KILLED

38

1.1
Location : divide
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:divisionTest()]
removed call to rs/etf/ts/storage/ResultStorage::set → KILLED

42

1.1
Location : square
Killed by : none
Replaced integer multiplication with division → NO_COVERAGE

43

1.1
Location : square
Killed by : none
removed call to rs/etf/ts/storage/ResultStorage::set → NO_COVERAGE

48

1.1
Location : squareRoot
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : squareRoot
Killed by : none
changed conditional boundary → NO_COVERAGE

49

1.1
Location : squareRoot
Killed by : none
removed call to rs/etf/ts/storage/ResultStorage::set → NO_COVERAGE

51

1.1
Location : squareRoot
Killed by : none
removed call to rs/etf/ts/storage/ResultStorage::set → NO_COVERAGE

56

1.1
Location : clear
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:divisionTest()]
removed call to rs/etf/ts/storage/ResultStorage::set → KILLED

60

1.1
Location : switchOn
Killed by : none
removed call to rs/etf/ts/storage/ResultStorage::set → SURVIVED
Covering tests

64

1.1
Location : switchOff
Killed by : none
removed call to rs/etf/ts/storage/ResultStorage::set → SURVIVED
Covering tests

68

1.1
Location : getResult
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:subtraction2Test()]
replaced int return with 0 for rs/etf/ts/calculator/Calculator::getResult → KILLED

72

1.1
Location : setResult
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:isPositive()]
removed call to rs/etf/ts/storage/ResultStorage::set → KILLED

76

1.1
Location : isPositive
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:isNegative()]
changed conditional boundary → KILLED

2.2
Location : isPositive
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:isNegative()]
negated conditional → KILLED

3.3
Location : isPositive
Killed by : rs.etf.ts.calculator.CalculatorTests.[engine:junit-jupiter]/[class:rs.etf.ts.calculator.CalculatorTests]/[method:isNegative()]
replaced boolean return with true for rs/etf/ts/calculator/Calculator::isPositive → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.0