-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ad57b45
added DTO
shalva97 f9482b5
add serialization for tests
shalva97 e8dd766
remove Kotlin Serialization and add Moshi
shalva97 f1a5a7c
fix crash
shalva97 f89af6d
return json instead of emptylist
shalva97 0b851b6
added truth lib
shalva97 0733363
change folder name
shalva97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
testomania/src/main/java/com/earth/testomania/di/AppModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.earth.testomania.domain | ||
|
||
class Test { | ||
} |
35 changes: 35 additions & 0 deletions
35
testomania/src/main/java/com/earth/testomania/tests/general/GeneralSkillsMathematicalRepo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
@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() } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
testomania/src/main/java/com/earth/testomania/tests/general/dto/GeneralTestItemDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
12 changes: 12 additions & 0 deletions
12
testomania/src/main/java/com/earth/testomania/tests/general/dto/OptionDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 წუთში შეილება დაემატოს ინტერფეისი...
There was a problem hiding this comment.
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](https://user-images.githubusercontent.com/6556678/161001774-f977a641-f7c0-49a0-9a87-6c8512ea3c92.jpg)
There was a problem hiding this comment.
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.
ასერომ არჯობია თავიდანვე გვქონდეს სწორი მიდგომა?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Nodrex NixOS დააყენე, ძაან მაგარი რაღაცაა