diff --git a/build.gradle b/build.gradle index 105cc481..23dbfb1d 100644 --- a/build.gradle +++ b/build.gradle @@ -61,6 +61,10 @@ allprojects { annotationProcessor 'org.projectlombok:lombok:1.18.20' testCompileOnly 'org.projectlombok:lombok:1.18.20' testAnnotationProcessor 'org.projectlombok:lombok:1.18.20' + + // Test + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1' } tasks.withType(JavaCompile) { @@ -96,6 +100,18 @@ allprojects { withSourcesJar() } + test { + useJUnitPlatform() + + // Always run tests, even when nothing changed. + dependsOn cleanTest + + // Show test results. + testLogging { + events "passed", "skipped", "failed" + } + } + compileJava.options.encoding = 'UTF-8' compileJava.dependsOn clean diff --git a/eco-api/src/test/java/NumberUtilsTest.java b/eco-api/src/test/java/NumberUtilsTest.java new file mode 100644 index 00000000..22fc23d4 --- /dev/null +++ b/eco-api/src/test/java/NumberUtilsTest.java @@ -0,0 +1,24 @@ +import com.willfp.eco.util.NumberUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class NumberUtilsTest { + @Test + public void testFormatDouble() { + Assertions.assertEquals(NumberUtils.format(3.0D), "3"); + Assertions.assertEquals(NumberUtils.format(3.2D), "3.20"); + } + + @Test + public void testLog2() { + Assertions.assertEquals(NumberUtils.log2(2), 1); + } + + @Test + public void testNumerals() { + Assertions.assertEquals(NumberUtils.fromNumeral("IV"), 4); + Assertions.assertEquals(NumberUtils.fromNumeral("IX"), 9); + Assertions.assertEquals(NumberUtils.toNumeral(14), "XIV"); + Assertions.assertEquals(NumberUtils.toNumeral(21), "XXI"); + } +}