Fix app tests
This commit is contained in:
parent
a1bf70c563
commit
dec946e1f3
10 changed files with 54 additions and 94 deletions
|
@ -11,16 +11,16 @@ import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository
|
|||
import dev.lucasnlm.antimine.common.level.repository.IMinefieldRepository
|
||||
import dev.lucasnlm.antimine.common.level.repository.ISavesRepository
|
||||
import dev.lucasnlm.antimine.common.level.repository.IStatsRepository
|
||||
import dev.lucasnlm.antimine.common.level.repository.MemorySavesRepository
|
||||
import dev.lucasnlm.antimine.common.level.repository.MemoryStatsRepository
|
||||
import dev.lucasnlm.antimine.common.level.utils.Clock
|
||||
import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackInteractor
|
||||
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory
|
||||
import dev.lucasnlm.antimine.core.analytics.AnalyticsManager
|
||||
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
|
||||
import dev.lucasnlm.antimine.mocks.MockDimensionRepository
|
||||
import dev.lucasnlm.antimine.mocks.MockHapticFeedbackInteractor
|
||||
import dev.lucasnlm.antimine.mocks.MockMinefieldRepository
|
||||
import dev.lucasnlm.antimine.mocks.MockSavesRepository
|
||||
import dev.lucasnlm.antimine.mocks.MockStatsRepository
|
||||
import dev.lucasnlm.antimine.mocks.DisabledHapticFeedbackInteractor
|
||||
import dev.lucasnlm.antimine.mocks.FixedDimensionRepository
|
||||
import dev.lucasnlm.antimine.mocks.FixedMinefieldRepository
|
||||
|
||||
@Module
|
||||
class TestLevelModule(
|
||||
|
@ -61,20 +61,20 @@ class TestLevelModule(
|
|||
override fun provideDimensionRepository(
|
||||
context: Context,
|
||||
preferencesRepository: IPreferencesRepository
|
||||
): IDimensionRepository = MockDimensionRepository()
|
||||
): IDimensionRepository = FixedDimensionRepository()
|
||||
|
||||
@Provides
|
||||
override fun provideSavesRepository(): ISavesRepository = MockSavesRepository()
|
||||
override fun provideSavesRepository(): ISavesRepository = MemorySavesRepository()
|
||||
|
||||
@Provides
|
||||
override fun provideStatsRepository(): IStatsRepository = MockStatsRepository(listOf())
|
||||
override fun provideStatsRepository(): IStatsRepository = MemoryStatsRepository()
|
||||
|
||||
@Provides
|
||||
override fun provideMinefieldRepository(): IMinefieldRepository = MockMinefieldRepository()
|
||||
override fun provideMinefieldRepository(): IMinefieldRepository = FixedMinefieldRepository()
|
||||
|
||||
@Provides
|
||||
override fun provideHapticFeedbackInteractor(
|
||||
application: Application,
|
||||
preferencesRepository: IPreferencesRepository
|
||||
): IHapticFeedbackInteractor = MockHapticFeedbackInteractor()
|
||||
): IHapticFeedbackInteractor = DisabledHapticFeedbackInteractor()
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package dev.lucasnlm.antimine.mocks
|
||||
|
||||
import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackInteractor
|
||||
|
||||
class DisabledHapticFeedbackInteractor : IHapticFeedbackInteractor {
|
||||
override fun toggleFlagFeedback() { }
|
||||
|
||||
override fun explosionFeedback() { }
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package dev.lucasnlm.antimine.mocks
|
||||
|
||||
import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository
|
||||
import dev.lucasnlm.antimine.common.level.repository.Size
|
||||
|
||||
class FixedDimensionRepository : IDimensionRepository {
|
||||
override fun areaSize(): Float = 50.0f
|
||||
|
||||
override fun areaSizeWithPadding(): Float {
|
||||
return areaSize() + 2 * areaSeparator()
|
||||
}
|
||||
|
||||
override fun areaSeparator(): Float = 1.0f
|
||||
|
||||
override fun displaySize(): Size = Size(50 * 15, 50 * 30)
|
||||
|
||||
override fun actionBarSize(): Int = 50
|
||||
}
|
|
@ -6,7 +6,7 @@ import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository
|
|||
import dev.lucasnlm.antimine.common.level.repository.IMinefieldRepository
|
||||
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
|
||||
|
||||
class MockMinefieldRepository : IMinefieldRepository {
|
||||
class FixedMinefieldRepository : IMinefieldRepository {
|
||||
override fun fromDifficulty(
|
||||
difficulty: Difficulty,
|
||||
dimensionRepository: IDimensionRepository,
|
|
@ -1,14 +0,0 @@
|
|||
package dev.lucasnlm.antimine.mocks
|
||||
|
||||
import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository
|
||||
import dev.lucasnlm.antimine.common.level.repository.Size
|
||||
|
||||
class MockDimensionRepository : IDimensionRepository {
|
||||
override fun areaSize(): Float = 50.0f
|
||||
|
||||
override fun areaSizeWithPadding(): Float = 52.0f
|
||||
|
||||
override fun displaySize(): Size = Size(50 * 20, 50 * 30)
|
||||
|
||||
override fun actionBarSize(): Int = 50
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package dev.lucasnlm.antimine.mocks
|
||||
|
||||
import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackInteractor
|
||||
|
||||
class MockHapticFeedbackInteractor : IHapticFeedbackInteractor {
|
||||
override fun toggleFlagFeedback() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
override fun explosionFeedback() {
|
||||
// Empty
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package dev.lucasnlm.antimine.mocks
|
||||
|
||||
import dev.lucasnlm.antimine.common.level.database.models.Save
|
||||
import dev.lucasnlm.antimine.common.level.repository.ISavesRepository
|
||||
|
||||
class MockSavesRepository : ISavesRepository {
|
||||
override suspend fun getAllSaves(): List<Save> {
|
||||
return listOf()
|
||||
}
|
||||
|
||||
override suspend fun fetchCurrentSave(): Save? {
|
||||
return null
|
||||
}
|
||||
|
||||
override suspend fun loadFromId(id: Int): Save? {
|
||||
return null
|
||||
}
|
||||
|
||||
override suspend fun saveGame(save: Save): Long? {
|
||||
return 1
|
||||
}
|
||||
|
||||
override fun setLimit(maxSavesStorage: Int) {
|
||||
// Empty
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package dev.lucasnlm.antimine.mocks
|
||||
|
||||
import dev.lucasnlm.antimine.common.level.database.models.Stats
|
||||
import dev.lucasnlm.antimine.common.level.repository.IStatsRepository
|
||||
|
||||
class MockStatsRepository(
|
||||
private val list: List<Stats>
|
||||
) : IStatsRepository {
|
||||
override suspend fun getAllStats(): List<Stats> = list
|
||||
|
||||
override suspend fun addStats(stats: Stats): Long? {
|
||||
return null
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package dev.lucasnlm.antimine.stats.viewmodel
|
||||
|
||||
import dev.lucasnlm.antimine.common.level.database.models.Stats
|
||||
import dev.lucasnlm.antimine.mocks.MockStatsRepository
|
||||
import dev.lucasnlm.antimine.common.level.repository.MemoryStatsRepository
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.runBlockingTest
|
||||
import org.junit.Assert.assertEquals
|
||||
|
@ -17,60 +17,60 @@ class StatsViewModelTest {
|
|||
@Test
|
||||
fun testStatsTotalGames() = runBlockingTest {
|
||||
val viewModel = StatsViewModel()
|
||||
val statsModel = viewModel.getStatsModel(MockStatsRepository(listOfStats))
|
||||
val statsModel = viewModel.getStatsModel(MemoryStatsRepository(listOfStats.toMutableList()))
|
||||
assertEquals(2, statsModel?.totalGames)
|
||||
|
||||
val emptyStatsModel = viewModel.getStatsModel(MockStatsRepository(listOf()))
|
||||
val emptyStatsModel = viewModel.getStatsModel(MemoryStatsRepository())
|
||||
assertEquals(0, emptyStatsModel?.totalGames)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStatsDuration() = runBlockingTest {
|
||||
val viewModel = StatsViewModel()
|
||||
val statsModel = viewModel.getStatsModel(MockStatsRepository(listOfStats))
|
||||
val statsModel = viewModel.getStatsModel(MemoryStatsRepository(listOfStats.toMutableList()))
|
||||
assertEquals(2200L, statsModel?.duration)
|
||||
|
||||
val emptyStatsModel = viewModel.getStatsModel(MockStatsRepository(listOf()))
|
||||
val emptyStatsModel = viewModel.getStatsModel(MemoryStatsRepository())
|
||||
assertEquals(0L, emptyStatsModel?.duration)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStatsAverageDuration() = runBlockingTest {
|
||||
val viewModel = StatsViewModel()
|
||||
val statsModel = viewModel.getStatsModel(MockStatsRepository(listOfStats))
|
||||
val statsModel = viewModel.getStatsModel(MemoryStatsRepository(listOfStats.toMutableList()))
|
||||
assertEquals(1100L, statsModel?.averageDuration)
|
||||
|
||||
val emptyStatsModel = viewModel.getStatsModel(MockStatsRepository(listOf()))
|
||||
val emptyStatsModel = viewModel.getStatsModel(MemoryStatsRepository(mutableListOf()))
|
||||
assertEquals(0L, emptyStatsModel?.averageDuration)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStatsMines() = runBlockingTest {
|
||||
val viewModel = StatsViewModel()
|
||||
val statsModel = viewModel.getStatsModel(MockStatsRepository(listOfStats))
|
||||
val statsModel = viewModel.getStatsModel(MemoryStatsRepository(listOfStats.toMutableList()))
|
||||
assertEquals(34, statsModel?.mines)
|
||||
|
||||
val emptyStatsModel = viewModel.getStatsModel(MockStatsRepository(listOf()))
|
||||
val emptyStatsModel = viewModel.getStatsModel(MemoryStatsRepository(mutableListOf()))
|
||||
assertEquals(0, emptyStatsModel?.mines)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testVictory() = runBlockingTest {
|
||||
val viewModel = StatsViewModel()
|
||||
val statsModel = viewModel.getStatsModel(MockStatsRepository(listOfStats))
|
||||
val statsModel = viewModel.getStatsModel(MemoryStatsRepository(listOfStats.toMutableList()))
|
||||
assertEquals(1, statsModel?.victory)
|
||||
|
||||
val emptyStatsModel = viewModel.getStatsModel(MockStatsRepository(listOf()))
|
||||
val emptyStatsModel = viewModel.getStatsModel(MemoryStatsRepository(mutableListOf()))
|
||||
assertEquals(0, emptyStatsModel?.victory)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOpenArea() = runBlockingTest {
|
||||
val viewModel = StatsViewModel()
|
||||
val statsModel = viewModel.getStatsModel(MockStatsRepository(listOfStats))
|
||||
val statsModel = viewModel.getStatsModel(MemoryStatsRepository(listOfStats.toMutableList()))
|
||||
assertEquals(110, statsModel?.openArea)
|
||||
|
||||
val emptyStatsModel = viewModel.getStatsModel(MockStatsRepository(listOf()))
|
||||
val emptyStatsModel = viewModel.getStatsModel(MemoryStatsRepository(mutableListOf()))
|
||||
assertEquals(0, emptyStatsModel?.openArea)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,9 +20,9 @@ class StatsRepository(
|
|||
}
|
||||
}
|
||||
|
||||
class MemoryStatsRepository : IStatsRepository {
|
||||
private val memoryStats = mutableListOf<Stats>()
|
||||
|
||||
class MemoryStatsRepository(
|
||||
private val memoryStats: MutableList<Stats> = mutableListOf()
|
||||
) : IStatsRepository {
|
||||
override suspend fun getAllStats(): List<Stats> = memoryStats.toList()
|
||||
|
||||
override suspend fun addStats(stats: Stats): Long? {
|
||||
|
|
Loading…
Reference in a new issue