mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-23 17:46:14 -06:00
Change grade weightValue type to double (#285)
This commit is contained in:
parent
4b0f0de52c
commit
040857ba20
@ -11,9 +11,9 @@ cache:
|
||||
- $HOME/.gradle/caches/
|
||||
- $HOME/.gradle/wrapper/
|
||||
|
||||
#branches:
|
||||
# only:
|
||||
# - master
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
android:
|
||||
licenses:
|
||||
|
@ -77,7 +77,7 @@ play {
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
implementation('io.github.wulkanowy:api:0.7.0') { exclude module: "threetenbp" }
|
||||
implementation('com.github.wulkanowy:api:0aea843800') { exclude module: "threetenbp" }
|
||||
|
||||
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
||||
implementation "androidx.appcompat:appcompat:1.0.2"
|
||||
|
@ -34,9 +34,9 @@ class GradeLocalTest {
|
||||
@Test
|
||||
fun saveAndReadTest() {
|
||||
gradeLocal.saveGrades(listOf(
|
||||
createGradeLocal(5, 3, LocalDate.of(2018, 9, 10), "", 1),
|
||||
createGradeLocal(4, 4, LocalDate.of(2019, 2, 27), "", 2),
|
||||
createGradeLocal(3, 5, LocalDate.of(2019, 2, 28), "", 2)
|
||||
createGradeLocal(5, 3.0, LocalDate.of(2018, 9, 10), "", 1),
|
||||
createGradeLocal(4, 4.0, LocalDate.of(2019, 2, 27), "", 2),
|
||||
createGradeLocal(3, 5.0, LocalDate.of(2019, 2, 28), "", 2)
|
||||
))
|
||||
|
||||
val grades = gradeLocal
|
||||
|
@ -71,10 +71,10 @@ class GradeRepositoryTest {
|
||||
@Test
|
||||
fun markOlderThanRegisterDateAsRead() {
|
||||
every { mockApi.getGrades(1) } returns Single.just(listOf(
|
||||
createGradeApi(5, 4, of(2019, 2, 25), "Ocena pojawiła się"),
|
||||
createGradeApi(5, 4, of(2019, 2, 26), "przed zalogowanie w aplikacji"),
|
||||
createGradeApi(5, 4, of(2019, 2, 27), "Ocena z dnia logowania"),
|
||||
createGradeApi(5, 4, of(2019, 2, 28), "Ocena jeszcze nowsza")
|
||||
createGradeApi(5, 4.0, of(2019, 2, 25), "Ocena pojawiła się"),
|
||||
createGradeApi(5, 4.0, of(2019, 2, 26), "przed zalogowanie w aplikacji"),
|
||||
createGradeApi(5, 4.0, of(2019, 2, 27), "Ocena z dnia logowania"),
|
||||
createGradeApi(5, 4.0, of(2019, 2, 28), "Ocena jeszcze nowsza")
|
||||
))
|
||||
|
||||
val grades = GradeRepository(settings, gradeLocal, gradeRemote)
|
||||
@ -89,16 +89,16 @@ class GradeRepositoryTest {
|
||||
@Test
|
||||
fun mitigateOldGradesNotifications() {
|
||||
gradeLocal.saveGrades(listOf(
|
||||
createGradeLocal(5, 3, of(2019, 2, 25), "Jedna ocena"),
|
||||
createGradeLocal(4, 4, of(2019, 2, 26), "Druga"),
|
||||
createGradeLocal(3, 5, of(2019, 2, 27), "Trzecia")
|
||||
createGradeLocal(5, 3.0, of(2019, 2, 25), "Jedna ocena"),
|
||||
createGradeLocal(4, 4.0, of(2019, 2, 26), "Druga"),
|
||||
createGradeLocal(3, 5.0, of(2019, 2, 27), "Trzecia")
|
||||
))
|
||||
|
||||
every { mockApi.getGrades(1) } returns Single.just(listOf(
|
||||
createGradeApi(5, 2, of(2019, 2, 25), "Ocena ma datę, jest inna, ale nie zostanie powiadomiona"),
|
||||
createGradeApi(4, 3, of(2019, 2, 26), "starszą niż ostatnia lokalnie"),
|
||||
createGradeApi(3, 4, of(2019, 2, 27), "Ta jest z tego samego dnia co ostatnia lokalnie"),
|
||||
createGradeApi(2, 5, of(2019, 2, 28), "Ta jest już w ogóle nowa")
|
||||
createGradeApi(5, 2.0, of(2019, 2, 25), "Ocena ma datę, jest inna, ale nie zostanie powiadomiona"),
|
||||
createGradeApi(4, 3.0, of(2019, 2, 26), "starszą niż ostatnia lokalnie"),
|
||||
createGradeApi(3, 4.0, of(2019, 2, 27), "Ta jest z tego samego dnia co ostatnia lokalnie"),
|
||||
createGradeApi(2, 5.0, of(2019, 2, 28), "Ta jest już w ogóle nowa")
|
||||
))
|
||||
|
||||
val grades = GradeRepository(settings, gradeLocal, gradeRemote)
|
||||
|
@ -5,7 +5,7 @@ import org.threeten.bp.LocalDate
|
||||
import io.github.wulkanowy.api.grades.Grade as GradeRemote
|
||||
import io.github.wulkanowy.data.db.entities.Grade as GradeLocal
|
||||
|
||||
fun createGradeLocal(value: Int, weight: Int, date: LocalDate, desc: String, semesterId: Int = 1): GradeLocal {
|
||||
fun createGradeLocal(value: Int, weight: Double, date: LocalDate, desc: String, semesterId: Int = 1): GradeLocal {
|
||||
return GradeLocal(
|
||||
semesterId = semesterId,
|
||||
studentId = 1,
|
||||
@ -24,7 +24,7 @@ fun createGradeLocal(value: Int, weight: Int, date: LocalDate, desc: String, sem
|
||||
)
|
||||
}
|
||||
|
||||
fun createGradeApi(value: Int, weight: Int, date: LocalDate, desc: String): GradeRemote {
|
||||
fun createGradeApi(value: Int, weight: Double, date: LocalDate, desc: String): GradeRemote {
|
||||
return GradeRemote().apply {
|
||||
this.value = value
|
||||
this.weightValue = weight
|
||||
|
@ -41,6 +41,7 @@ import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.db.entities.Subject
|
||||
import io.github.wulkanowy.data.db.entities.Timetable
|
||||
import io.github.wulkanowy.data.db.migrations.Migration10
|
||||
import io.github.wulkanowy.data.db.migrations.Migration11
|
||||
import io.github.wulkanowy.data.db.migrations.Migration2
|
||||
import io.github.wulkanowy.data.db.migrations.Migration3
|
||||
import io.github.wulkanowy.data.db.migrations.Migration4
|
||||
@ -79,7 +80,7 @@ import javax.inject.Singleton
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
companion object {
|
||||
const val VERSION_SCHEMA = 10
|
||||
const val VERSION_SCHEMA = 11
|
||||
|
||||
fun newInstance(context: Context): AppDatabase {
|
||||
return Room.databaseBuilder(context, AppDatabase::class.java, "wulkanowy_database")
|
||||
@ -95,7 +96,8 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
Migration7(),
|
||||
Migration8(),
|
||||
Migration9(),
|
||||
Migration10()
|
||||
Migration10(),
|
||||
Migration11()
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ data class Grade(
|
||||
|
||||
val weight: String,
|
||||
|
||||
val weightValue: Int,
|
||||
val weightValue: Double,
|
||||
|
||||
val date: LocalDate,
|
||||
|
||||
|
@ -0,0 +1,34 @@
|
||||
package io.github.wulkanowy.data.db.migrations
|
||||
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration11 : Migration(10, 11) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
CREATE TABLE IF NOT EXISTS Grades_temp (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
is_read INTEGER NOT NULL,
|
||||
is_notified INTEGER NOT NULL,
|
||||
semester_id INTEGER NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
subject TEXT NOT NULL,
|
||||
entry TEXT NOT NULL,
|
||||
value INTEGER NOT NULL,
|
||||
modifier REAL NOT NULL,
|
||||
comment TEXT NOT NULL,
|
||||
color TEXT NOT NULL,
|
||||
grade_symbol TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
weight TEXT NOT NULL,
|
||||
weightValue REAL NOT NULL,
|
||||
date INTEGER NOT NULL,
|
||||
teacher TEXT NOT NULL
|
||||
)
|
||||
""")
|
||||
database.execSQL("INSERT INTO Grades_temp SELECT * FROM Grades")
|
||||
database.execSQL("DROP TABLE Grades")
|
||||
database.execSQL("ALTER TABLE Grades_temp RENAME TO Grades")
|
||||
}
|
||||
}
|
@ -22,11 +22,11 @@ class GradeExtensionTest {
|
||||
@Test
|
||||
fun calcWeightedAverage() {
|
||||
assertEquals(3.47, listOf(
|
||||
createGrade(5, 6, 0.33),
|
||||
createGrade(5, 5, -0.33),
|
||||
createGrade(4, 1, 0.0),
|
||||
createGrade(1, 9, 0.5),
|
||||
createGrade(0, 0, 0.0)
|
||||
createGrade(5, 6.0, 0.33),
|
||||
createGrade(5, 5.0, -0.33),
|
||||
createGrade(4, 1.0, 0.0),
|
||||
createGrade(1, 9.0, 0.5),
|
||||
createGrade(0, .0, 0.0)
|
||||
).calcAverage(), 0.005)
|
||||
}
|
||||
|
||||
@ -42,23 +42,23 @@ class GradeExtensionTest {
|
||||
|
||||
@Test
|
||||
fun changeModifier_default() {
|
||||
assertEquals(.33, createGrade(5, 0, .33).changeModifier(.0, .0).modifier, .0)
|
||||
assertEquals(-.33, createGrade(5, 0, -.33).changeModifier(.0, .0).modifier, .0)
|
||||
assertEquals(.33, createGrade(5, .0, .33).changeModifier(.0, .0).modifier, .0)
|
||||
assertEquals(-.33, createGrade(5, .0, -.33).changeModifier(.0, .0).modifier, .0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun changeModifier_plus() {
|
||||
assertEquals(.33, createGrade(5, 0, .25).changeModifier(.33, .50).modifier, .0)
|
||||
assertEquals(.25, createGrade(5, 0, .33).changeModifier(.25, .0).modifier, .0)
|
||||
assertEquals(.33, createGrade(5, .0, .25).changeModifier(.33, .50).modifier, .0)
|
||||
assertEquals(.25, createGrade(5, .0, .33).changeModifier(.25, .0).modifier, .0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun changeModifier_minus() {
|
||||
assertEquals(-.33, createGrade(5, 0, -.25).changeModifier(.25, .33).modifier, .0)
|
||||
assertEquals(-.25, createGrade(5, 0, -.33).changeModifier(.0, .25).modifier, .0)
|
||||
assertEquals(-.33, createGrade(5, .0, -.25).changeModifier(.25, .33).modifier, .0)
|
||||
assertEquals(-.25, createGrade(5, .0, -.33).changeModifier(.0, .25).modifier, .0)
|
||||
}
|
||||
|
||||
private fun createGrade(value: Int, weightValue: Int = 0, modifier: Double = 0.25): Grade {
|
||||
private fun createGrade(value: Int, weightValue: Double = .0, modifier: Double = 0.25): Grade {
|
||||
return Grade(
|
||||
semesterId = 1,
|
||||
studentId = 1,
|
||||
|
Loading…
Reference in New Issue
Block a user