Added tests for NumberUtilsTest

This commit is contained in:
Auxilor
2021-08-06 22:22:18 +01:00
parent 2dda34097e
commit 56234e6c83
2 changed files with 40 additions and 0 deletions

View File

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

View File

@@ -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");
}
}