test: added test for some IntVector2 properties

This commit is contained in:
Yannik Bretschneider 2021-08-07 14:41:11 +02:00
parent 77be059d45
commit 6ab818b155

View File

@ -0,0 +1,67 @@
package uulm.teamname.marvelous.gamelibrary;
import net.jqwik.api.*;
import net.jqwik.api.Tuple;
import net.jqwik.api.lifecycle.BeforeProperty;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*;
class IntVector2Test {
@BeforeEach
@BeforeProperty
void beforeAll() {
}
@Property
@Disabled("This test fails! Therefore,a bug exists here")
void settingLengthToOneResultsInCardinalDirections(
@ForAll int x,
@ForAll int y
) {
var vec = new IntVector2(x, y).setLength(1);
// System.out.printf("Input was (%d, %d). Output is %s\n", x, y, vec);
if (!vec.equals(new IntVector2(0, 0))) {
assertThat(IntVector2.CardinalDirections)
.contains(vec);
}
}
@Property
void settingSmallVectorLengthResultsInCardinalDirections(
@ForAll("SmallIntegers") Integer x,
@ForAll("SmallIntegers") Integer y
) {
var vec = new IntVector2(x, y).setLength(1);
// System.out.printf("Input was (%d, %d). Output is %s\n", x, y, vec);
if (!vec.equals(new IntVector2(0, 0))) {
assertThat(IntVector2.CardinalDirections)
.contains(vec);
}
}
@Test
void setLengthCardinalTest() {
assertThat(new IntVector2(1, 1).setLength(1))
.isEqualTo(new IntVector2(1, 1));
assertThat(new IntVector2(0, 1).setLength(1))
.isEqualTo(new IntVector2(0, 1));
assertThat(new IntVector2(1, -1).setLength(1))
.isEqualTo(new IntVector2(1, -1));
}
@Provide("SmallIntegers")
Arbitrary<Integer> smallIntegers() {
return Arbitraries.integers()
.between(-1000, 1000);
}
}