Remove deprecated safeZone propertie

This commit is contained in:
Lucas Lima 2020-07-04 12:30:12 -03:00
parent d29fc528c9
commit 64fbc89d05
No known key found for this signature in database
GPG key ID: 0259A3F43EC1027A
7 changed files with 57 additions and 34 deletions

View file

@ -4,7 +4,7 @@ import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import dev.lucasnlm.antimine.common.level.database.converters.DifficultyConverter
import dev.lucasnlm.antimine.common.level.database.converters.FieldConverter
import dev.lucasnlm.antimine.common.level.database.converters.AreaConverter
import dev.lucasnlm.antimine.common.level.database.converters.FirstOpenConverter
import dev.lucasnlm.antimine.common.level.database.converters.MinefieldConverter
import dev.lucasnlm.antimine.common.level.database.converters.SaveStatusConverter
@ -18,10 +18,10 @@ import dev.lucasnlm.antimine.common.level.database.models.Stats
Save::class,
Stats::class
],
version = 4, exportSchema = false
version = 5, exportSchema = false
)
@TypeConverters(
FieldConverter::class,
AreaConverter::class,
SaveStatusConverter::class,
MinefieldConverter::class,
DifficultyConverter::class,

View file

@ -8,7 +8,7 @@ import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import dev.lucasnlm.antimine.common.level.models.Area
import java.lang.reflect.Type
class FieldConverter {
class AreaConverter {
private val moshi: Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
private val jsonAdapter: JsonAdapter<List<Area>>

View file

@ -7,7 +7,7 @@ import androidx.room.TypeConverters
import dev.lucasnlm.antimine.common.level.models.Area
import dev.lucasnlm.antimine.common.level.models.Difficulty
import dev.lucasnlm.antimine.common.level.models.Minefield
import dev.lucasnlm.antimine.common.level.database.converters.FieldConverter
import dev.lucasnlm.antimine.common.level.database.converters.AreaConverter
import dev.lucasnlm.antimine.common.level.database.converters.FirstOpenConverter
import dev.lucasnlm.antimine.common.level.database.converters.SaveStatusConverter
@ -39,7 +39,7 @@ data class Save(
@ColumnInfo(name = "status")
val status: SaveStatus,
@TypeConverters(FieldConverter::class)
@TypeConverters(AreaConverter::class)
@ColumnInfo(name = "field")
val field: List<Area>
)

View file

@ -22,7 +22,6 @@ class MinefieldCreator(
xPosition,
yPosition,
0,
safeZone = false,
hasMine = false
)
}.toMutableList()

View file

@ -5,7 +5,6 @@ data class Area(
val posX: Int,
val posY: Int,
var minesAround: Int = 0,
var safeZone: Boolean = false,
var hasMine: Boolean = false,
var mistake: Boolean = false,
var isCovered: Boolean = true,

View file

@ -81,16 +81,6 @@ class GameControllerTest {
}
}
@Test
fun testPlantMinesWithSafeArea() {
gameControllerOf(9, 9, 12, 200L).run {
plantMinesExcept(3)
field.filter { it.safeZone }.forEach {
assertFalse(it.hasMine)
}
}
}
@Test
fun testLevelRandomness() {
assertTrue(

View file

@ -6,22 +6,60 @@ import org.junit.Test
import org.junit.Assert.assertEquals
class FieldConverterTest {
private val expectedJson =
"[{\"id\":1,\"posX\":2,\"posY\":3,\"minesAround\":5,\"safeZone\":false,\"hasMine\":false,\"mistake\":false," +
"\"isCovered\":true,\"mark\":\"None\",\"highlighted\":true},{\"id\":2,\"posX\":5,\"posY\":3," +
"\"minesAround\":0,\"safeZone\":true,\"hasMine\":true,\"mistake\":true,\"isCovered\":false," +
"\"mark\":\"PurposefulNone\",\"highlighted\":false},{\"id\":3,\"posX\":1,\"posY\":1," +
"\"minesAround\":3,\"safeZone\":true,\"hasMine\":true,\"mistake\":false,\"isCovered\":true," +
"\"mark\":\"Flag\",\"highlighted\":true},{\"id\":4,\"posX\":0,\"posY\":0,\"minesAround\":6," +
"\"safeZone\":false,\"hasMine\":false,\"mistake\":false,\"isCovered\":true," +
"\"mark\":\"Question\",\"highlighted\":true}]"
class AreaConverterTest {
private val expectedJson = """
[
{
"id":1,
"posX":2,
"posY":3,
"minesAround":5,
"hasMine":false,
"mistake":false,
"isCovered":true,
"mark":"None",
"highlighted":true
},
{
"id":2,
"posX":5,
"posY":3,
"minesAround":0,
"hasMine":true,
"mistake":true,
"isCovered":false,
"mark":"PurposefulNone",
"highlighted":false
},
{
"id":3,
"posX":1,
"posY":1,
"minesAround":3,
"hasMine":true,
"mistake":false,
"isCovered":true,
"mark":"Flag",
"highlighted":true
},
{
"id":4,
"posX":0,
"posY":0,
"minesAround":6,
"hasMine":false,
"mistake":false,
"isCovered":true,
"mark":"Question",
"highlighted":true
}
]
""".trimIndent().replace(" ", "").replace("\n", "")
private val areaList =
listOf(
Area(
1, 2, 3, 5,
safeZone = false,
hasMine = false,
mistake = false,
isCovered = true,
@ -30,7 +68,6 @@ class FieldConverterTest {
),
Area(
2, 5, 3, 0,
safeZone = true,
hasMine = true,
mistake = true,
isCovered = false,
@ -39,7 +76,6 @@ class FieldConverterTest {
),
Area(
3, 1, 1, 3,
safeZone = true,
hasMine = true,
mistake = false,
isCovered = true,
@ -48,7 +84,6 @@ class FieldConverterTest {
),
Area(
4, 0, 0, 6,
safeZone = false,
hasMine = false,
mistake = false,
isCovered = true,
@ -59,7 +94,7 @@ class FieldConverterTest {
@Test
fun toAreaList() {
val fieldConverter = FieldConverter()
val fieldConverter = AreaConverter()
val list = fieldConverter.toAreaList(expectedJson)
assertEquals(
areaList, list
@ -68,7 +103,7 @@ class FieldConverterTest {
@Test
fun toJsonString() {
val fieldConverter = FieldConverter()
val fieldConverter = AreaConverter()
val result = fieldConverter.toJsonString(areaList)
assertEquals(expectedJson, result)
}