Skip to content

Commit 8514750

Browse files
authored
Update privacy grade so a score of 2 or 3 is now a C
Also add unit tests for letter grade now that the mapping contains logic (score is already tested)
1 parent 44a017d commit 8514750

File tree

5 files changed

+71
-14
lines changed

5 files changed

+71
-14
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2018 DuckDuckGo
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.duckduckgo.app.privacymonitor.model
18+
19+
import org.junit.Assert.assertEquals
20+
import org.junit.Test
21+
22+
class PrivacyGradeTest {
23+
24+
@Test
25+
fun whenScoreIs0ThenGradeIsA() {
26+
assertEquals(PrivacyGrade.A, PrivacyGrade.gradeForScore(0))
27+
}
28+
29+
@Test
30+
fun whenScoreIs1ThenGradeIsB() {
31+
assertEquals(PrivacyGrade.B, PrivacyGrade.gradeForScore(1))
32+
}
33+
34+
@Test
35+
fun whenScoreIs2ThenGradeIsC() {
36+
assertEquals(PrivacyGrade.C, PrivacyGrade.gradeForScore(2))
37+
}
38+
39+
@Test
40+
fun whenScoreIs3ThenGradeIsC() {
41+
assertEquals(PrivacyGrade.C, PrivacyGrade.gradeForScore(3))
42+
}
43+
44+
@Test
45+
fun whenScoreIs4ThenGradeIsD() {
46+
assertEquals(PrivacyGrade.D, PrivacyGrade.gradeForScore(4))
47+
}
48+
49+
@Test
50+
fun whenScoreIsAbove4ThenGradeIsD() {
51+
assertEquals(PrivacyGrade.D, PrivacyGrade.gradeForScore(5))
52+
}
53+
54+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import com.duckduckgo.app.privacymonitor.model.HttpsStatus
2323
import org.junit.Assert.assertEquals
2424
import org.junit.Test
2525

26-
class HttpsStatusRendererExtenstionTest {
26+
class HttpsStatusRendererExtensionTest {
2727

2828
private val context: Context = InstrumentationRegistry.getTargetContext()
2929

app/src/main/java/com/duckduckgo/app/privacymonitor/model/PrivacyGrade.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,18 @@ enum class PrivacyGrade {
2222
B,
2323
C,
2424
D,
25-
UNKNOWN
25+
UNKNOWN;
26+
27+
companion object {
28+
29+
fun gradeForScore(score: Int): PrivacyGrade {
30+
return when (score) {
31+
0 -> PrivacyGrade.A
32+
1 -> PrivacyGrade.B
33+
2, 3 -> PrivacyGrade.C
34+
else -> PrivacyGrade.D
35+
}
36+
}
37+
38+
}
2639
}

app/src/main/java/com/duckduckgo/app/privacymonitor/model/PrivacyMonitorGradeExtension.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,10 @@ val PrivacyMonitor.improvedScore: Int
5656
}
5757

5858
val PrivacyMonitor.grade: PrivacyGrade
59-
get() = calculateGrade(score)
59+
get() = PrivacyGrade.gradeForScore(score)
6060

6161
val PrivacyMonitor.improvedGrade: PrivacyGrade
62-
get() = calculateGrade(improvedScore)
63-
64-
65-
private fun calculateGrade(score: Int): PrivacyGrade {
66-
return when {
67-
score <= 0 -> PrivacyGrade.A
68-
score == 1 -> PrivacyGrade.B
69-
score == 2 -> PrivacyGrade.C
70-
else -> PrivacyGrade.D
71-
}
72-
}
62+
get() = PrivacyGrade.gradeForScore(improvedScore)
7363

7464
val TermsOfService.gradingScore: Int
7565
get() {

0 commit comments

Comments
 (0)