Skip to content

Commit

Permalink
Merge pull request #234 from braille-systems/release/1.1.0
Browse files Browse the repository at this point in the history
Release/1.1.0
  • Loading branch information
zuevval authored Aug 1, 2020
2 parents 1909b1c + f9aeefa commit ce655f1
Show file tree
Hide file tree
Showing 54 changed files with 1,557 additions and 249 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
applicationId "com.github.braillesystems.learnbraille"
minSdkVersion 19
targetSdkVersion 29
versionCode 8
versionName "1.0.2"
versionCode 13
versionName "1.1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.github.braillesystems.learnbraille.data.repository

import androidx.room.Room
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.github.braillesystems.learnbraille.data.db.LearnBrailleDatabase
import com.github.braillesystems.learnbraille.data.entities.Action
import com.github.braillesystems.learnbraille.data.entities.PracticeHintAction
import com.github.braillesystems.learnbraille.data.entities.TheoryPassStep
import com.github.braillesystems.learnbraille.utils.Days
import com.github.braillesystems.learnbraille.utils.minus
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.io.IOException
import java.util.*

@RunWith(AndroidJUnit4::class)
class ActionsRepositoryTest {

private lateinit var db: LearnBrailleDatabase
private lateinit var repo: MutableActionsRepository
private val currDate = Date()
private val actions = arrayOf(
Action(id = 1, type = TheoryPassStep(isInput = false)),
Action(id = 2, type = PracticeHintAction, date = currDate - Days(50))
)

@Before
fun createDB() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
db = Room
.inMemoryDatabaseBuilder(context, LearnBrailleDatabase::class.java)
.allowMainThreadQueries()
.build().apply {
runBlocking {
actionDao.insert(*actions)
}
}
repo = ActionsRepositoryImpl(
db.actionDao,
getCurrDate = { currDate },
keepActionsTime = Days(100)
)
}

@After
@Throws(IOException::class)
fun closeDB() {
db.close()
}

@Test
fun getAll() = runBlocking {
assertEquals(actions.toList(), repo.getActionsFrom(Days(100)))
}

@Test
fun rejectLast() = runBlocking {
assertEquals(listOf(actions.first()), repo.getActionsFrom(Days(10)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class PracticeRepositoryTest {

@Test
fun practiceRepo() {
TODO()
// TODO
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class TheoryRepositoryTest {

@Test
fun theoryRepo() {
TODO()
// TODO
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class DotsCheckerTest {

@Test
fun dotsChecker() {
TODO()
// TODO
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.braillesystems.learnbraille.utils

import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith


@RunWith(AndroidJUnit4::class)
class KotlinTest {

private fun getNextNumber(currentNumber: Int, nextNumbers: Array<Int>, repeat: Int): Int? {
var i = 0
fun getNextNumber(): Int {
return nextNumbers[i++]
}

fun ifNumberSameAsCurrent(number: Int) = number == currentNumber

return tryN(repeat, { !ifNumberSameAsCurrent(it) }, { getNextNumber() })
}

@Test
fun tryNTest() {
// testing how tryN helps to find first number in a sequence different from specified number
assertEquals(1, getNextNumber(0, arrayOf(1, 1, 1), 2))
assertEquals(2, getNextNumber(1, arrayOf(1, 2, 3), 2))
assertEquals(2, getNextNumber(1, arrayOf(1, 2, 3), 3))
assertEquals(null, getNextNumber(1, arrayOf(1, 2, 3), 1))
assertEquals(5, getNextNumber(0, arrayOf(0, 0, 0, 5, 1, 0, 4), 4))

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.github.braillesystems.learnbraille

import android.app.Application
import com.github.braillesystems.learnbraille.data.db.LearnBrailleDatabase
import com.github.braillesystems.learnbraille.data.dsl.UsersCourse
import com.github.braillesystems.learnbraille.data.entities.BrailleDots
import com.github.braillesystems.learnbraille.data.repository.*
import com.github.braillesystems.learnbraille.ui.screens.practice.CardViewModelFactory
import org.koin.android.ext.android.get
import org.koin.android.ext.koin.androidContext
import org.koin.core.Koin
import org.koin.core.context.startKoin
import org.koin.dsl.module
import timber.log.Timber
Expand All @@ -19,7 +20,16 @@ class LearnBrailleApplication : Application() {
Timber.i("onCreate")

val koinModule = module {

single { LearnBrailleDatabase.buildDatabase(this@LearnBrailleApplication) }

factory<ActionsRepository> {
ActionsRepositoryImpl(get<LearnBrailleDatabase>().actionDao)
}
factory<MutableActionsRepository> {
ActionsRepositoryImpl(get<LearnBrailleDatabase>().actionDao)
}

factory<PreferenceRepository> {
PreferenceRepositoryImpl(
this@LearnBrailleApplication,
Expand All @@ -32,6 +42,7 @@ class LearnBrailleApplication : Application() {
get<LearnBrailleDatabase>().userDao
)
}

factory<PracticeRepository> {
val db = get<LearnBrailleDatabase>()
PracticeRepositoryImpl(
Expand All @@ -46,12 +57,28 @@ class LearnBrailleApplication : Application() {
db.deckDao, db.cardDao, get()
)
}

factory<BrowserRepository> {
val db = get<LearnBrailleDatabase>()
BrowserRepositoryImpl(
this@LearnBrailleApplication,
get(), db.deckDao, db.cardDao
)
}
factory<MutableBrowserRepository> {
val db = get<LearnBrailleDatabase>()
BrowserRepositoryImpl(
this@LearnBrailleApplication,
get(), db.deckDao, db.cardDao
)
}

factory<TheoryRepository> {
get<LearnBrailleDatabase>().run {
TheoryRepositoryImpl(
lessonDao, stepDao,
currentStepDao, lastCourseStepDao, lastLessonStepDao, knownMaterialDao,
get()
get(), get()
)
}
}
Expand All @@ -60,28 +87,28 @@ class LearnBrailleApplication : Application() {
TheoryRepositoryImpl(
lessonDao, stepDao,
currentStepDao, lastCourseStepDao, lastLessonStepDao, knownMaterialDao,
get()
get(), get()
)
}
}

factory { (getEnteredDots: () -> BrailleDots) ->
CardViewModelFactory(
get(),
get(), get(),
this@LearnBrailleApplication,
getEnteredDots
)
}
}
startKoin {

koin = startKoin {
androidContext(this@LearnBrailleApplication)
modules(koinModule)
}

get<LearnBrailleDatabase>().init()
}.koin
}
}

/**
* First always stands for test developers course
*/
const val COURSE_ID = 2L
lateinit var koin: Koin
private set

val COURSE = UsersCourse(2L)
Loading

0 comments on commit ce655f1

Please sign in to comment.