-
Notifications
You must be signed in to change notification settings - Fork 0
/
computation.test.js
160 lines (146 loc) · 4.29 KB
/
computation.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
const { computeResult } = require('./computation');
describe('computeResult', () => {
test('Compute result failure', () => {
// given
const mutations = [
{ status: 'KILLED' },
{ status: 'KILLED' },
{ status: 'KILLED' },
{ status: 'NO_COVERAGE' },
{ status: 'NO_COVERAGE' },
{ status: 'SURVIVED' },
{ status: 'SURVIVED' },
{ status: 'SURVIVED' },
{ status: 'SURVIVED' },
{ status: 'SURVIVED' },
];
const threshold = 80;
// when
const result = computeResult(mutations, threshold);
// then
expect(result).toBeTruthy();
expect(result.count).toBe(10);
expect(result.killed).toBe(3);
expect(result.survived).toBe(5);
expect(result.noCoverage).toBe(2);
expect(result.testStrength).toBe(38);
expect(result.threshold).toBe(threshold);
expect(result.pass).toBe(false);
});
test('Compute result success', () => {
// given
const mutations = [
{ status: 'KILLED' },
{ status: 'KILLED' },
{ status: 'KILLED' },
{ status: 'NO_COVERAGE' },
{ status: 'NO_COVERAGE' },
{ status: 'SURVIVED' },
{ status: 'SURVIVED' },
];
const threshold = 60;
// when
const result = computeResult(mutations, threshold);
// then
expect(result).toBeTruthy();
expect(result.count).toBe(7);
expect(result.killed).toBe(3);
expect(result.survived).toBe(2);
expect(result.noCoverage).toBe(2);
expect(result.testStrength).toBe(60);
expect(result.threshold).toBe(threshold);
expect(result.pass).toBe(true);
});
test('Compute result empty (failure)', () => {
// given
const mutations = [];
const threshold = 50;
// when
const result = computeResult(mutations, threshold);
// then
expect(result).toBeTruthy();
expect(result.count).toBe(0);
expect(result.killed).toBe(0);
expect(result.survived).toBe(0);
expect(result.noCoverage).toBe(0);
expect(result.testStrength).toBe(0);
expect(result.threshold).toBe(threshold);
expect(result.pass).toBe(false);
});
test('Compute result with rounding', () => {
// given
const mutations = [
{ status: 'KILLED' },
{ status: 'SURVIVED' },
{ status: 'SURVIVED' },
];
const threshold = 80;
// when
const result = computeResult(mutations, threshold);
// then
expect(result).toBeTruthy();
expect(result.count).toBe(3);
expect(result.killed).toBe(1);
expect(result.survived).toBe(2);
expect(result.noCoverage).toBe(0);
expect(result.testStrength).toBe(33);
expect(result.threshold).toBe(threshold);
expect(result.pass).toBe(false);
});
test('Compute result with mutations details', () => {
// given
const mutations = [
{
sourceFile: 'Service1.java',
mutatedClass: 'com.test.Service1',
mutatedMethod: 'count',
lineNumber: 17,
description:
'replaced boolean return with true for com/test/Service1::count',
detected: true,
status: 'KILLED',
},
{
sourceFile: 'Service2.java',
mutatedClass: 'com.test.Service2',
mutatedMethod: 'accept',
lineNumber: 24,
description:
'replaced return value with null for com/test/Service2::accept',
detected: false,
status: 'NO_COVERAGE',
},
{
sourceFile: 'Service3.java',
mutatedClass: 'com.test.Service3',
mutatedMethod: 'apply',
lineNumber: 33,
description: 'Replaced integer multiplication with division',
detected: false,
status: 'SURVIVED',
},
];
const threshold = 50;
// when
const result = computeResult(mutations, threshold);
// then
expect(result).toBeTruthy();
expect(result.mutations).toHaveLength(2);
expect(result.mutations).toContainEqual({
file: 'Service2.java',
class: 'com.test.Service2',
method: 'accept',
line: 24,
status: 'NO_COVERAGE',
info: 'replaced return value with null for com/test/Service2::accept',
});
expect(result.mutations).toContainEqual({
file: 'Service3.java',
class: 'com.test.Service3',
method: 'apply',
line: 33,
status: 'SURVIVED',
info: 'Replaced integer multiplication with division',
});
});
});