Add unit tests for shapes
Signed-off-by: trivernis <trivernis@protonmail.com>pull/108/head
parent
49b1f8f1c7
commit
dcfd9f11f1
@ -0,0 +1,36 @@
|
||||
name: Gradle Unit Tests
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [ main, develop, actions, feature/unit-tests ]
|
||||
pull_request:
|
||||
branches: [ main, develop, actions, feature/unit-tests ]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
|
||||
- name: Cache build data
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: |
|
||||
~/.gradle/caches
|
||||
~/.gradle/wrapper
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('build.gradle') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-gradle-
|
||||
|
||||
- name: Test
|
||||
run: chmod +x gradlew && ./gradlew test
|
||||
|
||||
- name: Cleanup Gradle Cache
|
||||
run: |
|
||||
rm -f ~/.gradle/caches/modules-2/modules-2.lock
|
||||
rm -f ~/.gradle/caches/modules-2/gc.properties
|
@ -0,0 +1,73 @@
|
||||
package net.trivernis.chunkmaster.lib.shapes
|
||||
|
||||
import io.kotest.matchers.booleans.shouldBeTrue
|
||||
import io.kotest.matchers.collections.shouldContainAll
|
||||
import io.kotest.matchers.doubles.shouldBeBetween
|
||||
import io.kotest.matchers.shouldBe
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
|
||||
class CircleTest {
|
||||
private val circle = Circle(center = Pair(0, 0), radius = 2, start = Pair(0, 0))
|
||||
|
||||
@BeforeEach
|
||||
fun init() {
|
||||
circle.reset()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it generates coordinates`() {
|
||||
circle.next().shouldBe(Pair(0, 0))
|
||||
circle.next().shouldBe(Pair(-1, -1))
|
||||
circle.next().shouldBe(Pair(1, 0))
|
||||
circle.next().shouldBe(Pair(-1, 0))
|
||||
circle.next().shouldBe(Pair(1, -1))
|
||||
circle.next().shouldBe(Pair(-1, 1))
|
||||
circle.next().shouldBe(Pair(0, 1))
|
||||
circle.next().shouldBe(Pair(0, -1))
|
||||
circle.next().shouldBe(Pair(1, 1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it reports when reaching the end`() {
|
||||
for (i in 1..25) {
|
||||
circle.next()
|
||||
}
|
||||
circle.endReached().shouldBeTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it reports the radius`() {
|
||||
for (i in 1..9) {
|
||||
circle.next()
|
||||
}
|
||||
circle.currentRadius().shouldBe(1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it returns the right edges`() {
|
||||
circle.getShapeEdgeLocations().shouldContainAll(listOf(
|
||||
Pair(2, -1),
|
||||
Pair(2, 0),
|
||||
Pair(2, 1),
|
||||
Pair(1, 2),
|
||||
Pair(0, 2),
|
||||
Pair(-1, 2),
|
||||
Pair(-2, 1),
|
||||
Pair(-2, 0),
|
||||
Pair(-2, -1),
|
||||
Pair(-1, -2),
|
||||
Pair(0, -2),
|
||||
Pair(1, -2),
|
||||
))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it returns the progress`() {
|
||||
circle.progress(2).shouldBe(0)
|
||||
for (i in 1..7) {
|
||||
circle.next()
|
||||
}
|
||||
circle.progress(2).shouldBeBetween(.5, .8, .0)
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package net.trivernis.chunkmaster.lib.shapes
|
||||
|
||||
import io.kotest.matchers.booleans.shouldBeTrue
|
||||
import io.kotest.matchers.collections.shouldContainAll
|
||||
import io.kotest.matchers.shouldBe
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
|
||||
class SpiralTest {
|
||||
|
||||
private val spiral = Spiral(center = Pair(0, 0), radius = 2, start = Pair(0, 0))
|
||||
|
||||
@BeforeEach
|
||||
fun init() {
|
||||
spiral.reset()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it generates coordinates`() {
|
||||
spiral.next().shouldBe(Pair(0, 0))
|
||||
spiral.next().shouldBe(Pair(0, 1))
|
||||
spiral.next().shouldBe(Pair(1, 1))
|
||||
spiral.next().shouldBe(Pair(1, 0))
|
||||
spiral.next().shouldBe(Pair(1, -1))
|
||||
spiral.next().shouldBe(Pair(0, -1))
|
||||
spiral.next().shouldBe(Pair(-1, -1))
|
||||
spiral.next().shouldBe(Pair(-1, 0))
|
||||
spiral.next().shouldBe(Pair(-1, 1))
|
||||
spiral.next().shouldBe(Pair(-1, 2))
|
||||
spiral.next().shouldBe(Pair(0, 2))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it reports when reaching the end`() {
|
||||
for (i in 1..25) {
|
||||
spiral.next()
|
||||
}
|
||||
spiral.endReached().shouldBeTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it reports the radius`() {
|
||||
for (i in 1..9) {
|
||||
spiral.next()
|
||||
}
|
||||
spiral.currentRadius().shouldBe(1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it returns the right edges`() {
|
||||
spiral.getShapeEdgeLocations().shouldContainAll(listOf(Pair(2, 2), Pair(-2, 2), Pair(2, -2), Pair(-2, -2)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it returns the progress`() {
|
||||
spiral.progress(2).shouldBe(0)
|
||||
for (i in 1..8) {
|
||||
spiral.next()
|
||||
}
|
||||
spiral.progress(2).shouldBe(0.5)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue