Skip to content

Commit

Permalink
add unit test for roads.mmd, but it doesn't really work yet
Browse files Browse the repository at this point in the history
  • Loading branch information
Abelkrijgtalles committed Dec 15, 2024
1 parent 22f5ef5 commit 06b756f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ dependencies {
//addMod can be used, to control it via the version.property
//addMod("example.maven:some_mod:${rootProject.some_mod_version}", rootProject.enable_some_mod)
testImplementation "net.fabricmc:fabric-loader-junit:${rootProject.fabric_loader_version}"
testImplementation 'com.github.javafaker:javafaker:1.0.2'
}

task deleteResources(type: Delete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,46 @@

package nl.abelkrijgtalles.mojangmaps.common.config.roads;

import java.nio.file.Path;
import com.github.javafaker.Faker;
import java.util.ArrayList;
import java.util.List;
import nl.abelkrijgtalles.mojangmaps.common.MojangMaps;
import java.util.Random;
import net.minecraft.core.Position;
import net.minecraft.world.phys.Vec3;
import nl.abelkrijgtalles.mojangmaps.common.model.Road;
import nl.abelkrijgtalles.mojangmaps.fabric.MojangMapsFabric;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.RepetitionInfo;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class RoadDataTest {

@Test
void generateRoadData() {
@RepeatedTest(5)
void testGeneratingRoadData(RepetitionInfo repetitionInfo) {

MojangMaps.LOGGER.info("Generating the roads data in {}", Path.of(MojangMaps.loaderInfo.getConfig().getDataDirectory().toString(), "roads.mmd").toString());
RoadData generator = new RoadData();
generator.generateRoadData(RoadData.roads);
List<Road> roads = new ArrayList<>();
Random rand = new Random();
Faker faker = new Faker();
RoadData roadData = new RoadData();

}
for (int i = 0; i < repetitionInfo.getCurrentRepetition(); i++) {

List<Position> waypoints = new ArrayList<>();

@Test
void readRoadData() {
for (int j = 0; j < repetitionInfo.getCurrentRepetition(); j++) {

MojangMaps.LOGGER.info("Reading roads data in {}", Path.of(MojangMaps.loaderInfo.getConfig().getDataDirectory().toString(), "roads.mmd").toString());
RoadData generator = new RoadData();
List<Road> roads = generator.readRoadData();
for (Road road : roads) {
waypoints.add(new Vec3(rand.nextDouble(1000), rand.nextDouble(256), rand.nextDouble(1000)));

MojangMaps.LOGGER.info(road.getName());
MojangMaps.LOGGER.info(road.getWorldName());
MojangMaps.LOGGER.info(road.getWaypoints());
}

roads.add(new Road(faker.address().streetName(), "world", waypoints));

}

roadData.generateRoadData(roads);
assertEquals(roads, roadData.readRoadData());

}

@BeforeEach
Expand Down

0 comments on commit 06b756f

Please sign in to comment.