add diffGrades() to GradesController
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
* implement unit tests for diffGrades()
This commit is contained in:
parent
f12873fe00
commit
95362d5ab8
|
@ -2,6 +2,11 @@ kind: pipeline
|
|||
name: default
|
||||
|
||||
steps:
|
||||
- name: test
|
||||
image: gradle:jre11
|
||||
commands:
|
||||
- ./gradlew test
|
||||
|
||||
- name: assembleRelease
|
||||
image: nextcloudci/android10:android-56
|
||||
commands:
|
||||
|
|
|
@ -5,6 +5,7 @@ apply plugin: 'kotlin-android-extensions'
|
|||
android {
|
||||
signingConfigs {
|
||||
}
|
||||
|
||||
compileSdkVersion 29
|
||||
defaultConfig {
|
||||
applicationId "org.mosad.seil0.projectlaogai"
|
||||
|
@ -42,6 +43,14 @@ android {
|
|||
]
|
||||
}
|
||||
}
|
||||
|
||||
testOptions.unitTests.all {
|
||||
useJUnitPlatform()
|
||||
|
||||
testLogging {
|
||||
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -65,7 +74,7 @@ dependencies {
|
|||
implementation 'org.apache.commons:commons-lang3:3.11'
|
||||
implementation 'org.jsoup:jsoup:1.13.1'
|
||||
|
||||
testImplementation 'junit:junit:4.13'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
|
||||
androidTestImplementation 'androidx.test:core:1.3.0'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
}
|
||||
|
|
|
@ -29,11 +29,29 @@ class GradesController {
|
|||
/**
|
||||
* show the difference between 2 grades sets
|
||||
*/
|
||||
fun diffGrades(mapA: HashMap<String, ArrayList<GradeSubject>>, mapB: HashMap<String, ArrayList<GradeSubject>>): Int {
|
||||
// TODO compare
|
||||
// TODO return diff
|
||||
fun diffGrades(origMap: HashMap<String, ArrayList<GradeSubject>>, diffMap: HashMap<String, ArrayList<GradeSubject>>): ArrayList<GradeSubject> {
|
||||
val diff = ArrayList<GradeSubject>()
|
||||
|
||||
return 1
|
||||
diffMap.values.forEach { semester ->
|
||||
// if it's the same, no need to compare
|
||||
if (!origMap.containsValue(semester)) {
|
||||
semester.forEach { gradeSubject ->
|
||||
// for each of the grades, check if it differs from the origMap
|
||||
|
||||
if (origMap.containsKey(gradeSubject.semester)) {
|
||||
// a new or changed subject
|
||||
if (gradeSubject !in origMap[gradeSubject.semester]!!) {
|
||||
diff.add(gradeSubject)
|
||||
}
|
||||
} else {
|
||||
// a new semester
|
||||
diff.add(gradeSubject)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return diff
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package org.mosad.seil0.projectlaogai
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
|
@ -24,8 +24,8 @@ package org.mosad.seil0.projectlaogai
|
|||
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mosad.seil0.projectlaogai.controller.GradesController
|
||||
import org.mosad.seil0.projectlaogai.util.GradeSubject
|
||||
import java.io.File
|
||||
|
@ -34,9 +34,9 @@ import java.io.FileReader
|
|||
class GradesControllerTest {
|
||||
|
||||
@Test
|
||||
fun diffGrades_isCorrect() {
|
||||
fun diffGrades_noDiff() {
|
||||
val origFile = File(GradesControllerTest::class.java.getResource("/grades_orig.json")?.path!!)
|
||||
val diffFile = File(GradesControllerTest::class.java.getResource("/grades_diff.json")?.path!!)
|
||||
val diffFile = File(GradesControllerTest::class.java.getResource("/grades_orig.json")?.path!!)
|
||||
|
||||
val mapA: HashMap<String, ArrayList<GradeSubject>> = FileReader(origFile).use {
|
||||
GsonBuilder().create().fromJson(it, object : TypeToken<HashMap<String, ArrayList<GradeSubject>>>() {}.type)
|
||||
|
@ -46,8 +46,54 @@ class GradesControllerTest {
|
|||
GsonBuilder().create().fromJson(it, object : TypeToken<HashMap<String, ArrayList<GradeSubject>>>() {}.type)
|
||||
}
|
||||
|
||||
val exp = ArrayList<GradeSubject>()
|
||||
val ret = GradesController().diffGrades(mapA, mapB)
|
||||
|
||||
Assert.assertEquals(1, ret)
|
||||
Assertions.assertEquals(exp, ret)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun diffGrades_diffSubject() {
|
||||
val origFile = File(GradesControllerTest::class.java.getResource("/grades_orig.json")?.path!!)
|
||||
val diffFile = File(GradesControllerTest::class.java.getResource("/grades_diff_subject.json")?.path!!)
|
||||
|
||||
val mapA: HashMap<String, ArrayList<GradeSubject>> = FileReader(origFile).use {
|
||||
GsonBuilder().create().fromJson(it, object : TypeToken<HashMap<String, ArrayList<GradeSubject>>>() {}.type)
|
||||
}
|
||||
|
||||
val mapB: HashMap<String, ArrayList<GradeSubject>> = FileReader(diffFile).use {
|
||||
GsonBuilder().create().fromJson(it, object : TypeToken<HashMap<String, ArrayList<GradeSubject>>>() {}.type)
|
||||
}
|
||||
|
||||
val exp = arrayListOf(
|
||||
GradeSubject("AI-3010", "Computernetze", "WiSe 18/19", "0,7", "2,0"),
|
||||
GradeSubject("AI-3020", "Datenbanksysteme 1", "WiSe 18/19", "1,7", "2,0"),
|
||||
GradeSubject("AI-3025", "Praktikum Datenbanksysteme", "WiSe 18/19", "bestanden", "3,0")
|
||||
)
|
||||
val ret = GradesController().diffGrades(mapA, mapB)
|
||||
|
||||
Assertions.assertEquals(exp, ret)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun diffGrades_diffSemester() {
|
||||
val origFile = File(GradesControllerTest::class.java.getResource("/grades_orig.json")?.path!!)
|
||||
val diffFile = File(GradesControllerTest::class.java.getResource("/grades_diff_semester.json")?.path!!)
|
||||
|
||||
val mapA: HashMap<String, ArrayList<GradeSubject>> = FileReader(origFile).use {
|
||||
GsonBuilder().create().fromJson(it, object : TypeToken<HashMap<String, ArrayList<GradeSubject>>>() {}.type)
|
||||
}
|
||||
|
||||
val mapB: HashMap<String, ArrayList<GradeSubject>> = FileReader(diffFile).use {
|
||||
GsonBuilder().create().fromJson(it, object : TypeToken<HashMap<String, ArrayList<GradeSubject>>>() {}.type)
|
||||
}
|
||||
|
||||
val exp = arrayListOf(
|
||||
GradeSubject("AI-2010", "Mathemaik 7", "SoSe 19", "1,7", "4,0"),
|
||||
GradeSubject("AI-2015", "Praktikum Mathemaik 7", "SoSe 19", "bestanden", "1,0")
|
||||
)
|
||||
val ret = GradesController().diffGrades(mapA, mapB)
|
||||
|
||||
Assertions.assertEquals(exp, ret)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"WiSe 17/18":[
|
||||
{"credits":"4,0","grade":"1,0","id":"AI-1020","name":"Grundlagen der Elektronik","semester":"WiSe 17/18"},
|
||||
{"credits":"2,0","grade":"2,3","id":"AI-1040","name":"Prozedurale Programmierung","semester":"WiSe 17/18"}
|
||||
],
|
||||
"SoSe 18":[
|
||||
{"credits":"4,0","grade":"1,7","id":"AI-2010","name":"Technische Informatik","semester":"SoSe 18"},
|
||||
{"credits":"1,0","grade":"bestanden","id":"AI-2015","name":"Praktikum Technische Informatik","semester":"SoSe 18"}
|
||||
],
|
||||
"WiSe 18/19":[
|
||||
{"credits":"2,0","grade":"2,7","id":"AI-3010","name":"Computernetze","semester":"WiSe 18/19"},
|
||||
{"credits":"3,0","grade":"bestanden","id":"AI-3015","name":"Praktikum Computernetze","semester":"WiSe 18/19"}
|
||||
],
|
||||
"SoSe 19":[
|
||||
{"credits":"4,0","grade":"1,7","id":"AI-2010","name":"Mathemaik 7","semester":"SoSe 19"},
|
||||
{"credits":"1,0","grade":"bestanden","id":"AI-2015","name":"Praktikum Mathemaik 7","semester":"SoSe 19"}
|
||||
]
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
{"credits":"1,0","grade":"bestanden","id":"AI-2015","name":"Praktikum Technische Informatik","semester":"SoSe 18"}
|
||||
],
|
||||
"WiSe 18/19":[
|
||||
{"credits":"2,0","grade":"2,7","id":"AI-3010","name":"Computernetze","semester":"WiSe 18/19"},
|
||||
{"credits":"2,0","grade":"0,7","id":"AI-3010","name":"Computernetze","semester":"WiSe 18/19"},
|
||||
{"credits":"3,0","grade":"bestanden","id":"AI-3015","name":"Praktikum Computernetze","semester":"WiSe 18/19"},
|
||||
{"credits":"2,0","grade":"1,7","id":"AI-3020","name":"Datenbanksysteme 1","semester":"WiSe 18/19"},
|
||||
{"credits":"3,0","grade":"bestanden","id":"AI-3025","name":"Praktikum Datenbanksysteme","semester":"WiSe 18/19"}
|
Loading…
Reference in New Issue