Compare commits
8 Commits
0.0.0
...
b79e701b7a
| Author | SHA256 | Date | |
|---|---|---|---|
| b79e701b7a | |||
| 1228165347 | |||
| be07738fc4 | |||
|
|
c8d8829f83 | ||
|
|
2f25bc7dc4 | ||
|
|
254a55d955 | ||
|
|
959bd7dd66 | ||
|
|
0938645cd0 |
@@ -28,10 +28,9 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// The test classes are compiled with these:
|
compileOnly("org.jetbrains:annotations:26.0.2-1")
|
||||||
implementation("com.r35157.libs:random-api:0.0.0")
|
implementation("com.r35157.libs:random-api:0.1-dev")
|
||||||
implementation("com.r35157.libs:random-impl-ref:0.0.0")
|
implementation("com.r35157.libs:random-impl-ref:0.1-dev")
|
||||||
implementation("org.jetbrains:annotations:26.0.1")
|
|
||||||
|
|
||||||
// The JUnit platform will not be included in the JAR file but are needed for running the tests:
|
// The JUnit platform will not be included in the JAR file but are needed for running the tests:
|
||||||
testImplementation(platform("org.junit:junit-bom:5.11.4"))
|
testImplementation(platform("org.junit:junit-bom:5.11.4"))
|
||||||
@@ -40,11 +39,11 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain { languageVersion.set(JavaLanguageVersion.of(24)) }
|
toolchain { languageVersion.set(JavaLanguageVersion.of(25)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<JavaCompile> {
|
tasks.withType<JavaCompile>().configureEach {
|
||||||
options.release.set(24)
|
options.release.set(25)
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.test {
|
tasks.test {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
org.gradle.java.installations.auto-detect=true
|
org.gradle.java.installations.auto-detect=true
|
||||||
org.gradle.java.installations.fromEnv=JAVA_HOME
|
org.gradle.java.installations.fromEnv=JAVA_HOME
|
||||||
org.gradle.java.installations.paths=/usr/local/software/java/jfx-24
|
org.gradle.java.installations.paths=/usr/local/software/java/jfx-25
|
||||||
org.gradle.java.installations.auto-download=false
|
org.gradle.java.installations.auto-download=false
|
||||||
org.gradle.configuration-cache=true
|
org.gradle.configuration-cache=true
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-all.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
package com.r35157.libs.random.tests;
|
|
||||||
|
|
||||||
import com.r35157.libs.random.SomeInterface;
|
|
||||||
import com.r35157.libs.random.impl.ref.SomeImpl;
|
|
||||||
import org.junit.jupiter.api.*;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
@DisplayName("Happy Initialization Tests")
|
|
||||||
public class HappyInitializationTests {
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
public static void beforeAll() {
|
|
||||||
System.out.println("==== Before All");
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
public void beforeEach() {
|
|
||||||
System.out.println("---- Before Each");
|
|
||||||
}
|
|
||||||
|
|
||||||
@DisplayName("Just a basic test")
|
|
||||||
@Test
|
|
||||||
void someBasicTest() {
|
|
||||||
// Arrange
|
|
||||||
String a = "abc";
|
|
||||||
String b = "def";
|
|
||||||
String expected = "abcdef";
|
|
||||||
SomeInterface sut = new SomeImpl();
|
|
||||||
|
|
||||||
// Act
|
|
||||||
String actual = sut.concat(a, b);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
assertTrue(actual.equals(expected));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Disabled("Test disabled")
|
|
||||||
@Test
|
|
||||||
void dummyTest2() {
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
public void afterEach() {
|
|
||||||
System.out.println("**** After Each");
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterAll
|
|
||||||
public static void afterAll() {
|
|
||||||
System.out.println("==== After All");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package com.r35157.libs.random.tests;
|
|
||||||
|
|
||||||
import com.r35157.libs.random.SomeInterface;
|
|
||||||
import com.r35157.libs.random.impl.ref.SomeImpl;
|
|
||||||
import org.junit.jupiter.api.*;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
@DisplayName("Sad Initialization Tests")
|
|
||||||
public class SadInitializationTests {
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
public static void beforeAll() {
|
|
||||||
System.out.println("==== Before All");
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
public void beforeEach() {
|
|
||||||
System.out.println("---- Before Each");
|
|
||||||
}
|
|
||||||
|
|
||||||
@DisplayName("Just another basic test")
|
|
||||||
@Test
|
|
||||||
void anotherBasicTest() {
|
|
||||||
|
|
||||||
// Arrange + act
|
|
||||||
SomeInterface sut = new SomeImpl();
|
|
||||||
String expectedErrorMsg = "/ by zero";
|
|
||||||
|
|
||||||
ArithmeticException thrown = assertThrows(
|
|
||||||
ArithmeticException.class,
|
|
||||||
sut::divideByZero,
|
|
||||||
"Expected an exception to be thrown while dividing by zero, but it didn't"
|
|
||||||
);
|
|
||||||
String actualErrorMsg = thrown.getMessage();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
assertEquals(expectedErrorMsg, actualErrorMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Disabled("Test disabled")
|
|
||||||
@Test
|
|
||||||
void dummyTest2() {
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
public void afterEach() {
|
|
||||||
System.out.println("**** After Each");
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterAll
|
|
||||||
public static void afterAll() {
|
|
||||||
System.out.println("==== After All");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package com.r35157.libs.random.tests.happy;
|
||||||
|
|
||||||
|
import com.r35157.libs.random.RandomValueGeneratorInt;
|
||||||
|
import com.r35157.libs.random.impl.ref.RandomValueGeneratorIntImpl;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@DisplayName("Happy Random Ints Tests")
|
||||||
|
public class CorrectRandomIntsTests {
|
||||||
|
|
||||||
|
@DisplayName("Extreme narrow band works - always only one value possible")
|
||||||
|
@Test
|
||||||
|
void testThatEqualMinMaxBoundsWorks() {
|
||||||
|
// Arrange
|
||||||
|
int minBound = 7;
|
||||||
|
int maxBound = 7;
|
||||||
|
int expected = 7;
|
||||||
|
RandomValueGeneratorInt sut = new RandomValueGeneratorIntImpl();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
int actual = sut.getSomeInt(minBound, maxBound);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("Produces different values over multiple calls")
|
||||||
|
@Test
|
||||||
|
void producesDifferentValuesOverMultipleCalls() {
|
||||||
|
// Arrange
|
||||||
|
int iterations = 5;
|
||||||
|
RandomValueGeneratorInt sut = new RandomValueGeneratorIntImpl();
|
||||||
|
Set<Integer> seen = new HashSet<>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
for (int i = 0; i < iterations; i++) {
|
||||||
|
seen.add(sut.getSomeInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Arrange
|
||||||
|
assertTrue(seen.size() > 1, "Int generator returned the same value every time");
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("Will never throw")
|
||||||
|
@Test
|
||||||
|
void noArgsMethodNeverThrows() {
|
||||||
|
// Arrange
|
||||||
|
int iterations = 10_000;
|
||||||
|
RandomValueGeneratorIntImpl sut = new RandomValueGeneratorIntImpl();
|
||||||
|
|
||||||
|
// Act + Assert
|
||||||
|
for (int i = 0; i < iterations; i++) {
|
||||||
|
assertDoesNotThrow(() -> sut.getSomeInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void returnsBothPositiveAndNegative() {
|
||||||
|
// Arrange
|
||||||
|
int iterations = 1_000_000;
|
||||||
|
boolean seenPos = false, seenNeg = false;
|
||||||
|
RandomValueGeneratorIntImpl sut = new RandomValueGeneratorIntImpl();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
for (int i = 0; i < iterations; i++) {
|
||||||
|
int v = sut.getSomeInt();
|
||||||
|
if (v > 0) seenPos = true;
|
||||||
|
if (v < 0) seenNeg = true;
|
||||||
|
if (seenPos && seenNeg) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assertTrue(seenPos, "Never saw positive number");
|
||||||
|
assertTrue(seenNeg, "Never saw negative number");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.r35157.libs.random.tests.sad;
|
||||||
|
|
||||||
|
import com.r35157.libs.random.RandomValueGeneratorInt;
|
||||||
|
import com.r35157.libs.random.impl.ref.RandomValueGeneratorIntImpl;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
@DisplayName("Sad Random Ints Tests")
|
||||||
|
public class IncorrectRandomIntTests {
|
||||||
|
|
||||||
|
@DisplayName("Do incorrect range bounds throw?")
|
||||||
|
@Test
|
||||||
|
void testThatItThrowsWhenMinBoundIsGreaterThanMaxBound() {
|
||||||
|
// Arrange
|
||||||
|
int minBound = 10;
|
||||||
|
int maxBound = 5;
|
||||||
|
String expectedErrorMsg = String.format("'minInclusive' (%d) must be less than or equal to 'maxInclusive' (%d)",
|
||||||
|
minBound, maxBound);
|
||||||
|
RandomValueGeneratorInt sut = new RandomValueGeneratorIntImpl();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
IllegalArgumentException thrown = assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> sut.getSomeInt(minBound, maxBound)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
String actualErrorMsg = thrown.getMessage();
|
||||||
|
assertEquals(expectedErrorMsg, actualErrorMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.r35157.libs.random.tests.sad;
|
||||||
|
|
||||||
|
import com.r35157.libs.random.RandomValueGeneratorInt;
|
||||||
|
import com.r35157.libs.random.RandomValueGeneratorString;
|
||||||
|
import com.r35157.libs.random.impl.ref.RandomValueGeneratorIntImpl;
|
||||||
|
import com.r35157.libs.random.impl.ref.RandomValueGeneratorStringImpl;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
@DisplayName("Sad Random Strings Tests")
|
||||||
|
public class IncorrectRandomStringTests {
|
||||||
|
|
||||||
|
@DisplayName("Do initializing with <null> throw NPE?")
|
||||||
|
@Test
|
||||||
|
void testThatInitializingWithNullIntGeneratorThrows() {
|
||||||
|
// Arrange
|
||||||
|
String expectedErrorMsg = "Cannot initialize with <null> RandomValueGeneratorInt!";
|
||||||
|
RandomValueGeneratorInt rvgi = null;
|
||||||
|
|
||||||
|
// Act + Assert
|
||||||
|
NullPointerException thrown = assertThrows(
|
||||||
|
NullPointerException.class,
|
||||||
|
() -> new RandomValueGeneratorStringImpl(rvgi)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
String actualErrorMsg = thrown.getMessage();
|
||||||
|
assertEquals(expectedErrorMsg, actualErrorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("Do generating negative length Strings throw IAE?")
|
||||||
|
@Test
|
||||||
|
void testThatGeneratingStringsOfNegativeLengthThrowsIAE() {
|
||||||
|
// Arrange
|
||||||
|
int length = -1;
|
||||||
|
String expectedErrorMsg = "Cannot generate random Strings of size " + length + "!";
|
||||||
|
RandomValueGeneratorString sut = new RandomValueGeneratorStringImpl(rvgi);
|
||||||
|
|
||||||
|
// Act + Assert
|
||||||
|
IllegalArgumentException thrown = assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> sut.getSomeStringAlphaNumericOnly(length)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
String actualErrorMsg = thrown.getMessage();
|
||||||
|
assertEquals(expectedErrorMsg, actualErrorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final RandomValueGeneratorInt rvgi = new RandomValueGeneratorIntImpl();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user