Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement and write tests for GeneralSkillsRepo #24

Merged
merged 7 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
28 changes: 21 additions & 7 deletions testomania/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ android {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
}

dependencies {
Expand All @@ -58,11 +63,10 @@ dependencies {
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation 'androidx.activity:activity-compose:1.4.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"

// Serialization
implementation("com.squareup.moshi:moshi-kotlin:1.13.0")
kapt("com.squareup.moshi:moshi-kotlin-codegen:1.13.0")

// Compose dependencies
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.4.1"
Expand All @@ -75,14 +79,24 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'

//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.38.1"
kapt "com.google.dagger:hilt-android-compiler:2.37"
implementation "com.google.dagger:hilt-android:2.41"
kapt "com.google.dagger:hilt-android-compiler:2.41"
kapt "androidx.hilt:hilt-compiler:1.0.0"

// Room
implementation "androidx.room:room-runtime:2.4.2"
implementation "androidx.room:room-ktx:2.4.2"
kapt "androidx.room:room-compiler:2.4.2"

// Testing
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.robolectric:robolectric:4.6'
testImplementation group: 'com.google.dagger', name: 'hilt-android-testing', version: '2.41'
kaptTest 'com.google.dagger:hilt-android-compiler:2.41'
testImplementation "com.google.truth:truth:1.1.3"
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
}
42 changes: 41 additions & 1 deletion testomania/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,44 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

# Keep `Companion` object fields of serializable classes.
# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects.
-if @kotlinx.serialization.Serializable class **
-keepclassmembers class <1> {
static <1>$Companion Companion;
}

# Keep `serializer()` on companion objects (both default and named) of serializable classes.
-if @kotlinx.serialization.Serializable class ** {
static **$* *;
}
-keepclassmembers class <2>$<3> {
kotlinx.serialization.KSerializer serializer(...);
}

# Keep `INSTANCE.serializer()` of serializable objects.
-if @kotlinx.serialization.Serializable class ** {
public static ** INSTANCE;
}
-keepclassmembers class <1> {
public static <1> INSTANCE;
kotlinx.serialization.KSerializer serializer(...);
}

# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault

# Serializer for classes with named companion objects are retrieved using `getDeclaredClasses`.
# If you have any, uncomment and replace classes with those containing named companion objects.
#-keepattributes InnerClasses # Needed for `getDeclaredClasses`.
#-if @kotlinx.serialization.Serializable class
#com.example.myapplication.HasNamedCompanion, # <-- List serializable classes with named companions.
#com.example.myapplication.HasNamedCompanion2
#{
# static **$* *;
#}
#-keepnames class <1>$$serializer { # -keepnames suffices; class is kept when serializer() is kept.
# static <1>$$serializer INSTANCE;
#}
11 changes: 11 additions & 0 deletions testomania/src/main/java/com/earth/testomania/di/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package com.earth.testomania.di

import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object AppModule {

//TODO provide DB instance and so on
@Provides
@Singleton
fun jsonSerializer(): Moshi {
return Moshi.Builder()
.addLast(KotlinJsonAdapterFactory())
.build()
}

}
4 changes: 4 additions & 0 deletions testomania/src/main/java/com/earth/testomania/domain/Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.earth.testomania.domain

class Test {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.earth.testomania.tests.general

import android.content.Context
import com.earth.testomania.R
import com.earth.testomania.tests.general.dto.GeneralTestItemDTO
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.adapter
import dagger.hilt.android.qualifiers.ApplicationContext
import okio.buffer
import okio.source
import javax.inject.Inject
import javax.inject.Singleton

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to have some interface for repo and it's implementation

Copy link
Collaborator Author

@shalva97 shalva97 Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know most of the books/blogspots say that, including you, but I disagree... So many interfaces and so many implementations I have seen and almost none used the benefits of having an interface. 99% of those did not had more than one implementation.

Actually, I want to deliberately make a mistake and do it without interfaces. It will be interesting to see how bad is this tight coupling thing.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to create mistakes on our project? :D can you do it in another project? :D
well I agree with @kartlos99 we want to use best practices and implementation of repo is best practice, I know sometimes it seems we are adding a level of complexity and it may never change and be needed, but and I mean BIG BUT what if change will be nececery and interface will not be there? we will be disappointed :( so I also recomd to use best practices and thus use interface and implementation of the interface

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

| sometimes it seems we are adding a level of complexity

ჩემთვის ძალიან ხშირად ასე ჩანს.... რეალურად გვინდა რო მივყვეთ მაგ ბესთ ფრაქთისს? მე ვერ ვხედავ საჭიროებას.

| we will be disappointed

ესეც საკითხავია, მაინც რამდენად იმედგაცრუებული ვიქნებით? ინტელიჯეის უკვე აქვს ძალიან კარგი რეფაქტორის ფუნქციები, თუ მართლა გახდა საჭირო 2 წუთში შეილება დაემატოს ინტერფეისი...

Copy link
Owner

@Nodrex Nodrex Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

რადგან ჩვენი პროექტის ერთერთი მთავარი მიზანია განვითარება და სიახლეების სწავლა, შესაბამისად მისაღებია შენი გადაწყვეტილება, ანუ ნეიტალურს დავიჭერ მე, თუმცა ალბათ სხვების აზრიც უნდა მოვისმინოთ:
@nmgalo @mlkway თქვენ რას ფიქრობთ, დავტოვოთ ასე ინტერფეისის გარეშე?

მაგრამ ჩვენ ხომ შევთახმდით რომ სხვადასხვა ტესტი, თავთავის პაკეტში იქნებოდა, და როგორც მახსოვს უნარების ტესტებს სახელი skills შურჩიეთ, თუ გინდა skills_test დავარქვათ პაკეტს, მხოლოდ tests არა ინფორმატიული და ძაან ჯენერიკია
InkedScreenshot 2022-03-31 112835_LI

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ჩემიაზრით ჯობია სწორ პრაქტიკას მივყვეთ, Clean code ში ეწერა ეგ LeBlanc’s law: Later equals never.
ასერომ არჯობია თავიდანვე გვქონდეს სწორი მიდგომა?

Copy link
Owner

@Nodrex Nodrex Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean code ში ეწერა ეგ LeBlanc’s law: Later equals never
2019 წელს დავაყენე კამერა და ავაწყვე სერვერი windows ზე ვიდეოჩანაწერებეისვის, რათქმაუნდა იმავე წელს გადავწყვიტე რომ linux ზე გადავიყვანდი სერვერს და გაგიკვირდებათ 2022 წელია მაგრამ სერვერი ისევ windows ზეა :D რადგან მუშაობს, მეზარება linux ზე გადაყვანა :D
აგერ ჩემი შპიონი google photo დამემოწმება 2019 შია გადაღებული ფოტო :D
Inked277294242_394637039144992_485374272907831425_n_LI

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nodrex NixOS დააყენე, ძაან მაგარი რაღაცაა

@Singleton
class GeneralSkillsMathematicalRepo @Inject constructor(
@ApplicationContext private val appContext: Context,
private val moshi: Moshi,
) {

@OptIn(ExperimentalStdlibApi::class)
private val tests by lazy {
val rawJson = appContext.resources.openRawResource(R.raw.general_ability_test_data)
val adapter: JsonAdapter<List<GeneralTestItemDTO>> = moshi.adapter()
adapter.fromJson(rawJson.source().buffer()) ?: emptyList()
}

fun getAllTests(): List<GeneralTestItemDTO> {
return tests
}

fun getRandomTests(count: Int): List<GeneralTestItemDTO> {
return List(count) { tests.random() }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.earth.testomania.tests.general.dto

import com.squareup.moshi.JsonClass


@JsonClass(generateAdapter = true)
data class GeneralTestItemDTO(
// val active: Int,
// val creator_id: Any,
// val description: Any,
// val grade: Any,
val id: Int,
val options: List<OptionDTO>,
val ordering: Int,
val question: String,
// val subject_id: Any,
val test_id: Int,
// val text_id: Any,
// val type_id: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.earth.testomania.tests.general.dto

import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class OptionDTO(
val correct: Int,
val id: Int,
val option: String,
val question_id: Int,
// val timeline: Any // what is this
)
Loading