test: wrote proptest for IntVector to practise proptesting

This commit is contained in:
Yannik Bretschneider 2021-05-28 14:47:15 +02:00
parent 745bea58b8
commit b2b963579e
1 changed files with 17 additions and 0 deletions

View File

@ -2,6 +2,9 @@ package uulm.teamname.marvelous.gamelibrary.json.ingame;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.jqwik.api.ForAll;
import net.jqwik.api.Property;
import net.jqwik.api.lifecycle.BeforeProperty;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -50,4 +53,18 @@ class IntVector2DeserializerTest {
// System.out.println(jsonDescribingTarget);
}
}
// A PropTest written to get comfortable with jqwik. It practically does the same as the test above,
// but took less than 1/30th of the time to write. Quite impressive indeed.
@BeforeProperty
void beforeProperty() {
this.mapper = new ObjectMapper();
}
@Property
void deserializedVectorHasCorrectValues(@ForAll int someX, @ForAll int someY) throws JsonProcessingException {
assertThat(mapper.readValue(String.format("[%d, %d]", someX, someY), IntVector2.class))
.isEqualTo(new IntVector2(someX, someY));
}
}