Skip to content

Commit

Permalink
Added test groups to app and ui modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Martomate committed Sep 7, 2024
1 parent 742a031 commit 1f5752c
Show file tree
Hide file tree
Showing 6 changed files with 481 additions and 445 deletions.
146 changes: 75 additions & 71 deletions app/src/test/kotlin/tripaint/app/ActionsTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tripaint.app

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Nested
import tripaint.color.Color
import tripaint.coords.GridCoords
import tripaint.coords.StorageCoords
Expand All @@ -16,77 +17,80 @@ import kotlin.test.Test
class ActionsTest {
private val storageFormat: StorageFormat = SimpleStorageFormat

@Test
fun `openImage should do nothing if loading failed`() {
val location = ImagePool.SaveLocation(File(""))
val imageSize = 16

val model = TriPaintModel.createNull(imageSize, FileSystem.NullArgs(initialImages = mapOf()))
val pool = model.imagePool

Actions.openImage(
model,
location.file,
FileOpenSettings(location.offset, storageFormat),
GridCoords.from(0, 0)
)

assertEquals(null, pool.imageAt(location))
}

@Test
fun `openImage should store the loaded image in the image pool`() {
val file = File("path/to/image.png")
val location = ImagePool.SaveLocation(file)
val imageSize = 16

val image = ImageStorage.fill(imageSize, Color.Yellow)
val regularImage = image.toRegularImage(storageFormat)

val model =
TriPaintModel.createNull(
@Nested
inner class OpenImage {
@Test
fun `does nothing if loading fails`() {
val location = ImagePool.SaveLocation(File("a.png"))
val imageSize = 16

val model = TriPaintModel.createNull(imageSize, FileSystem.NullArgs(initialImages = mapOf()))
val pool = model.imagePool

Actions.openImage(
model,
location.file,
FileOpenSettings(location.offset, storageFormat),
GridCoords.from(0, 0)
)

assertEquals(null, pool.imageAt(location))
}

@Test
fun `stores the loaded image in the image pool`() {
val file = File("path/to/image.png")
val location = ImagePool.SaveLocation(file)
val imageSize = 16

val image = ImageStorage.fill(imageSize, Color.Yellow)
val regularImage = image.toRegularImage(storageFormat)

val model =
TriPaintModel.createNull(
imageSize,
FileSystem.NullArgs(initialImages = mapOf(Pair(file, regularImage)))
)

Actions.openImage(
model,
location.file,
FileOpenSettings(location.offset, storageFormat),
GridCoords.from(0, 0)
)
val loadedImage = model.imagePool.imageAt(location)!!

assertEquals(regularImage, loadedImage.toRegularImage(storageFormat))
}

@Test
fun `loads image with offset`() {
val file = File("path/to/image.png")
val offset = StorageCoords.from(2, 3)
val location = ImagePool.SaveLocation(file, offset)
val imageSize = 16

val image = ImageStorage.fill(imageSize, Color.Yellow)
val regularImage = image.toRegularImage(storageFormat)

val storedImage = RegularImage.ofSize(imageSize + offset.x, imageSize + offset.y)
storedImage.pasteImage(offset, regularImage)

val model = TriPaintModel.createNull(
imageSize,
FileSystem.NullArgs(initialImages = mapOf(Pair(file, regularImage)))
)

Actions.openImage(
model,
location.file,
FileOpenSettings(location.offset, storageFormat),
GridCoords.from(0, 0)
)
val loadedImage = model.imagePool.imageAt(location)!!

assertEquals(regularImage, loadedImage.toRegularImage(storageFormat))
}

@Test
fun `openImage should load image with offset`() {
val file = File("path/to/image.png")
val offset = StorageCoords.from(2, 3)
val location = ImagePool.SaveLocation(file, offset)
val imageSize = 16

val image = ImageStorage.fill(imageSize, Color.Yellow)
val regularImage = image.toRegularImage(storageFormat)

val storedImage = RegularImage.ofSize(imageSize + offset.x, imageSize + offset.y)
storedImage.pasteImage(offset, regularImage)

val model = TriPaintModel.createNull(
imageSize,
FileSystem.NullArgs(initialImages = mapOf(Pair(file, storedImage)))
)
val pool = model.imagePool

Actions.openImage(
model,
location.file,
FileOpenSettings(location.offset, storageFormat),
GridCoords.from(0, 0)
)
val loadedImage = pool.imageAt(location)!!

assertEquals(regularImage, loadedImage.toRegularImage(storageFormat))
FileSystem.NullArgs(initialImages = mapOf(Pair(file, storedImage)))
)
val pool = model.imagePool

Actions.openImage(
model,
location.file,
FileOpenSettings(location.offset, storageFormat),
GridCoords.from(0, 0)
)
val loadedImage = pool.imageAt(location)!!

assertEquals(regularImage, loadedImage.toRegularImage(storageFormat))
}
}
}
Loading

0 comments on commit 1f5752c

Please sign in to comment.