Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions basic_kotlin_project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ repositories {

dependencies {
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation 'io.kotest:kotest-runner-junit5:5.5.4'
testImplementation 'io.kotest:kotest-assertions-core:5.5.4'
testImplementation 'io.kotest:kotest-runner-junit5-jvm:4.6.0'
}

test {
Expand Down
94 changes: 94 additions & 0 deletions basic_kotlin_project/src/test/kotlin/model/BouncyMapKotest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package model

import io.kotest.core.spec.style.ShouldSpec
import io.kotest.matchers.shouldBe

class BouncyMapKotest: ShouldSpec ({
should("canMoveTo should return true when position is within map boundaries") {
val map = BouncyMap(5, 5)
val position1 = Vector2d(3, 3)
val position2 = Vector2d(0, 0)
val position3 = Vector2d(5, 5)

map.canMoveTo(position1) shouldBe true
map.canMoveTo(position2) shouldBe true
map.canMoveTo(position3) shouldBe true
}

should("canMoveTo should return false when position is outside map boundaries") {
val map = BouncyMap(5, 5)
val position1 = Vector2d(-1, 3)
val position2 = Vector2d(3, -1)
val position3 = Vector2d(6, 3)
val position4 = Vector2d(3, 6)

map.canMoveTo(position1) shouldBe false
map.canMoveTo(position2) shouldBe false
map.canMoveTo(position3) shouldBe false
map.canMoveTo(position4) shouldBe false
}

should("isOccupied should return true when position is occupied by an animal") {
val map = BouncyMap(5, 5)
val animal = Animal(position = Vector2d(3, 3))
map.place(animal)
val position = Vector2d(3, 3)

map.isOccupied(position) shouldBe true
}

should("isOccupied should return false when position is not occupied by any animal") {
val map = BouncyMap(5, 5)
val position = Vector2d(3, 3)

map.isOccupied(position) shouldBe false
}

should("objectAt should return the animal at the given position") {
val map = BouncyMap(5, 5)
val animal = Animal(position = Vector2d(3, 3))
map.place(animal)
val position = Vector2d(3, 3)

map.objectAt(position) shouldBe animal
}
should("objectAt should return null when there is no animal at the given position") {
val map = BouncyMap(5, 5)
val position = Vector2d(3, 3)

map.objectAt(position) shouldBe null
}
should("move should move animal to the given position") {
val map = BouncyMap(5, 5)
val animal = Animal(position = Vector2d(3, 3))
map.place(animal)
val position = Vector2d(3, 4)

map.move(animal, MoveDirection.FORWARD)
animal.getPosition() shouldBe position
map.objectAt(position) shouldBe animal

val position2 = Vector2d(4, 4)
map.move(animal, MoveDirection.RIGHT)
map.move(animal, MoveDirection.FORWARD)
animal.getPosition() shouldBe position2
map.objectAt(position2) shouldBe animal
map.objectAt(position) shouldBe null
}
should("place should place animal at the given position") {
val map = BouncyMap(5, 5)
val animal = Animal(position = Vector2d(3, 3))
map.place(animal)
val position = Vector2d(3, 3)

animal.getPosition() shouldBe position
map.objectAt(position) shouldBe animal

val position2 = Vector2d(4, 4)
animal.setPosition(position2)
map.place(animal)
animal.getPosition() shouldBe position2
map.objectAt(position2) shouldBe animal
map.objectAt(position) shouldBe null
}
})