Add unit tests for shapes

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/108/head
trivernis 4 years ago
parent 49b1f8f1c7
commit dcfd9f11f1
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -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

@ -48,6 +48,10 @@ repositories {
name 'mikeprimm'
url 'https://repo.mikeprimm.com'
}
maven {
url 'https://jitpack.io'
}
}
dependencies {
@ -90,6 +94,8 @@ compileTestKotlin {
jvmTarget = "1.8"
}
dependencies {
compileOnly group: 'junit', name: 'junit', version: '4.12'
implementation group: 'junit', name: 'junit', version: '4.12'
implementation 'com.github.seeseemelk:MockBukkit:v1.16-SNAPSHOT'
implementation 'io.kotest:kotest-runner-junit5:4.3.2'
}
}

@ -10,7 +10,6 @@ import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.scheduler.BukkitTask
import org.dynmap.DynmapAPI
import java.lang.IllegalStateException
import java.lang.NullPointerException
class Chunkmaster : JavaPlugin() {
lateinit var sqliteManager: SqliteManager
@ -32,7 +31,7 @@ class Chunkmaster : JavaPlugin() {
logger.finest("LogLevel: FINEST")
configure()
val metrics = Metrics(this)
Metrics(this)
langManager = LanguageManager(this)
langManager.loadProperties()

@ -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…
Cancel
Save