amidstest/src/test/java/amidst/mojangapi/mocking/FakeMinecraftInterface.java

68 lines
2.1 KiB
Java
Raw Normal View History

added world icon test To prevent the need to make the minecraft jar file and libraries available on travis ci, this test uses previously generated testdata to ensure that the generated world icons are still the same as when the test data where generated. It is true, that this uses the production code to generate the test data, however, this is not an issue, because the test data are stored and not generated every time the test is executed. All in all, the test checks whether the generated world icons have changed since the test data where generated. It does not ensure, that the world icons are correct (meaning like minecraft generates them). The test: * loads the biome data from the test data * loads the world icons * creates a fake minecraft interface that provides the stored biome data * creates a world object using the fake minecraft interface * generates all world icons using the world object * compares the generated world icons to the loaded world icons The test data contains all biome data in the test area as well as all world icons. The test area is 10 fragments in all directions from [0, 0] ([-5120, -5120] to [5120, 5120]). The world icons are generated for the inner 10 - 1 = 9 fragments ([-4608, -4608] to [4608, 4608]). This prevents the world icon producers to request biome data that have not been stored. The test data are stored in a zip-file to prevent them from taking up to much space. One world requires about 6.5 MB (compressed). Thus, we should not add to much test worlds and not change them very often to prevent the repository from getting too big. An alternative would be stored the testdata somewhere else than in the repository. However, they have to be available for travis ci, so this will be the solution for now. * The End Cities are currently not included. * The current seed is "amidst-test-seed" using the default world type and minecraft version 1.8.9. * The test data are generated by running the test in the class DevToolRunner.
2016-01-24 17:05:37 -08:00
package amidst.mojangapi.mocking;
import amidst.documentation.ThreadSafe;
import amidst.gameengineabstraction.GameEngineType;
added world icon test To prevent the need to make the minecraft jar file and libraries available on travis ci, this test uses previously generated testdata to ensure that the generated world icons are still the same as when the test data where generated. It is true, that this uses the production code to generate the test data, however, this is not an issue, because the test data are stored and not generated every time the test is executed. All in all, the test checks whether the generated world icons have changed since the test data where generated. It does not ensure, that the world icons are correct (meaning like minecraft generates them). The test: * loads the biome data from the test data * loads the world icons * creates a fake minecraft interface that provides the stored biome data * creates a world object using the fake minecraft interface * generates all world icons using the world object * compares the generated world icons to the loaded world icons The test data contains all biome data in the test area as well as all world icons. The test area is 10 fragments in all directions from [0, 0] ([-5120, -5120] to [5120, 5120]). The world icons are generated for the inner 10 - 1 = 9 fragments ([-4608, -4608] to [4608, 4608]). This prevents the world icon producers to request biome data that have not been stored. The test data are stored in a zip-file to prevent them from taking up to much space. One world requires about 6.5 MB (compressed). Thus, we should not add to much test worlds and not change them very often to prevent the repository from getting too big. An alternative would be stored the testdata somewhere else than in the repository. However, they have to be available for travis ci, so this will be the solution for now. * The End Cities are currently not included. * The current seed is "amidst-test-seed" using the default world type and minecraft version 1.8.9. * The test data are generated by running the test in the class DevToolRunner.
2016-01-24 17:05:37 -08:00
import amidst.mojangapi.minecraftinterface.MinecraftInterface;
import amidst.mojangapi.minecraftinterface.MinecraftInterfaceException;
import amidst.mojangapi.minecraftinterface.RecognisedVersion;
import amidst.mojangapi.world.WorldType;
2016-01-31 09:10:43 -08:00
import amidst.mojangapi.world.testworld.storage.json.BiomeDataJson;
refactored the test code * improved the code * switched biome data storage format to protobuf (binary) * switched back to json (see reasons below) * switched biome data serialization strategy * added mechanism to test specific entries for specific worlds * squashed commits to prevent git from storing the outdated big testdata files forever And this are the old detailed commit messages: changed strategy for biome data storage * it now tracks and stores all biome data requests while the other test data are created * the same request during the running test will offer the same response as during the test data generation * this greatly simplifies the code, makes the size of the test data much smaller and the testdata creation and loading much faster removed the binary test data storage * switched back to json * did not serve a significant better result (time and space) * protobuf documentation discourages the use for large messages * I want to not use code generation whenever possible because * it contains warnings * it is differently formatted than the hand written code * it makes the build process more complicated Here are the stats: json binary binary packed test time: 13,193 s 9,838 s 9,333 s complete: 6,4 mb 6,1 mb 6,1 mb uncompressed: 260,8 mb 212,5 mb 212,5 mb complete is the compressed size of all zip files. uncompressed is the uncompressed size of the full-resolution biome data. We see, that the compression removes a big portion of the space advantage that would be served by the binary format. The binary packed format seems to not be any better than the default binary format. Just the few seconds are not really worth the disadvantages listed above. fixed bugs in test data generation * test world generation now omits unsupported entries * creation of an empty coordinates collection throws an exception to prevent the usage of empty testdata switched BiomeData to binary storage format rename refactorings and adjustments to the protobuf format added equalityChecker to TestWorldEntryDeclaration used the method TestWorldDeclaraion.isSupported() ... ... to allow that only specific features are tested for special test worlds enhanced readability of test world entry declaration more refactorings for the testworld code extracted the class TestWorld from the class TestWorldDirectory renamed and moved classes moved write and read methods to entry declaration added protobuf * library * license * testdata declarations * generated code from testdata declarations improved testdata storage * split up the single zip file into multiple small ones to only change as few data as possible, when they need to be changed * removed timestamp from zip files to make them reproducible removed many usages of TestWorldDeclaration by exposing the regocnised version from the world object
2016-01-31 07:27:22 -08:00
import amidst.mojangapi.world.testworld.storage.json.WorldMetadataJson;
added world icon test To prevent the need to make the minecraft jar file and libraries available on travis ci, this test uses previously generated testdata to ensure that the generated world icons are still the same as when the test data where generated. It is true, that this uses the production code to generate the test data, however, this is not an issue, because the test data are stored and not generated every time the test is executed. All in all, the test checks whether the generated world icons have changed since the test data where generated. It does not ensure, that the world icons are correct (meaning like minecraft generates them). The test: * loads the biome data from the test data * loads the world icons * creates a fake minecraft interface that provides the stored biome data * creates a world object using the fake minecraft interface * generates all world icons using the world object * compares the generated world icons to the loaded world icons The test data contains all biome data in the test area as well as all world icons. The test area is 10 fragments in all directions from [0, 0] ([-5120, -5120] to [5120, 5120]). The world icons are generated for the inner 10 - 1 = 9 fragments ([-4608, -4608] to [4608, 4608]). This prevents the world icon producers to request biome data that have not been stored. The test data are stored in a zip-file to prevent them from taking up to much space. One world requires about 6.5 MB (compressed). Thus, we should not add to much test worlds and not change them very often to prevent the repository from getting too big. An alternative would be stored the testdata somewhere else than in the repository. However, they have to be available for travis ci, so this will be the solution for now. * The End Cities are currently not included. * The current seed is "amidst-test-seed" using the default world type and minecraft version 1.8.9. * The test data are generated by running the test in the class DevToolRunner.
2016-01-24 17:05:37 -08:00
@ThreadSafe
public class FakeMinecraftInterface implements MinecraftInterface {
private final WorldMetadataJson worldMetadataJson;
private final BiomeDataJson quarterBiomeData;
private final BiomeDataJson fullBiomeData;
private volatile boolean isWorldCreated = false;
public FakeMinecraftInterface(
WorldMetadataJson worldMetadataJson,
BiomeDataJson quarterBiomeData,
BiomeDataJson fullBiomeData) {
added world icon test To prevent the need to make the minecraft jar file and libraries available on travis ci, this test uses previously generated testdata to ensure that the generated world icons are still the same as when the test data where generated. It is true, that this uses the production code to generate the test data, however, this is not an issue, because the test data are stored and not generated every time the test is executed. All in all, the test checks whether the generated world icons have changed since the test data where generated. It does not ensure, that the world icons are correct (meaning like minecraft generates them). The test: * loads the biome data from the test data * loads the world icons * creates a fake minecraft interface that provides the stored biome data * creates a world object using the fake minecraft interface * generates all world icons using the world object * compares the generated world icons to the loaded world icons The test data contains all biome data in the test area as well as all world icons. The test area is 10 fragments in all directions from [0, 0] ([-5120, -5120] to [5120, 5120]). The world icons are generated for the inner 10 - 1 = 9 fragments ([-4608, -4608] to [4608, 4608]). This prevents the world icon producers to request biome data that have not been stored. The test data are stored in a zip-file to prevent them from taking up to much space. One world requires about 6.5 MB (compressed). Thus, we should not add to much test worlds and not change them very often to prevent the repository from getting too big. An alternative would be stored the testdata somewhere else than in the repository. However, they have to be available for travis ci, so this will be the solution for now. * The End Cities are currently not included. * The current seed is "amidst-test-seed" using the default world type and minecraft version 1.8.9. * The test data are generated by running the test in the class DevToolRunner.
2016-01-24 17:05:37 -08:00
this.worldMetadataJson = worldMetadataJson;
this.quarterBiomeData = quarterBiomeData;
this.fullBiomeData = fullBiomeData;
}
@Override
public int[] getBiomeData(int x, int y, int width, int height, boolean useQuarterResolution)
throws MinecraftInterfaceException {
added world icon test To prevent the need to make the minecraft jar file and libraries available on travis ci, this test uses previously generated testdata to ensure that the generated world icons are still the same as when the test data where generated. It is true, that this uses the production code to generate the test data, however, this is not an issue, because the test data are stored and not generated every time the test is executed. All in all, the test checks whether the generated world icons have changed since the test data where generated. It does not ensure, that the world icons are correct (meaning like minecraft generates them). The test: * loads the biome data from the test data * loads the world icons * creates a fake minecraft interface that provides the stored biome data * creates a world object using the fake minecraft interface * generates all world icons using the world object * compares the generated world icons to the loaded world icons The test data contains all biome data in the test area as well as all world icons. The test area is 10 fragments in all directions from [0, 0] ([-5120, -5120] to [5120, 5120]). The world icons are generated for the inner 10 - 1 = 9 fragments ([-4608, -4608] to [4608, 4608]). This prevents the world icon producers to request biome data that have not been stored. The test data are stored in a zip-file to prevent them from taking up to much space. One world requires about 6.5 MB (compressed). Thus, we should not add to much test worlds and not change them very often to prevent the repository from getting too big. An alternative would be stored the testdata somewhere else than in the repository. However, they have to be available for travis ci, so this will be the solution for now. * The End Cities are currently not included. * The current seed is "amidst-test-seed" using the default world type and minecraft version 1.8.9. * The test data are generated by running the test in the class DevToolRunner.
2016-01-24 17:05:37 -08:00
if (isWorldCreated) {
return getBiomeData(useQuarterResolution).get(x, y, width, height);
} else {
throw new MinecraftInterfaceException("the world needs to be created first");
added world icon test To prevent the need to make the minecraft jar file and libraries available on travis ci, this test uses previously generated testdata to ensure that the generated world icons are still the same as when the test data where generated. It is true, that this uses the production code to generate the test data, however, this is not an issue, because the test data are stored and not generated every time the test is executed. All in all, the test checks whether the generated world icons have changed since the test data where generated. It does not ensure, that the world icons are correct (meaning like minecraft generates them). The test: * loads the biome data from the test data * loads the world icons * creates a fake minecraft interface that provides the stored biome data * creates a world object using the fake minecraft interface * generates all world icons using the world object * compares the generated world icons to the loaded world icons The test data contains all biome data in the test area as well as all world icons. The test area is 10 fragments in all directions from [0, 0] ([-5120, -5120] to [5120, 5120]). The world icons are generated for the inner 10 - 1 = 9 fragments ([-4608, -4608] to [4608, 4608]). This prevents the world icon producers to request biome data that have not been stored. The test data are stored in a zip-file to prevent them from taking up to much space. One world requires about 6.5 MB (compressed). Thus, we should not add to much test worlds and not change them very often to prevent the repository from getting too big. An alternative would be stored the testdata somewhere else than in the repository. However, they have to be available for travis ci, so this will be the solution for now. * The End Cities are currently not included. * The current seed is "amidst-test-seed" using the default world type and minecraft version 1.8.9. * The test data are generated by running the test in the class DevToolRunner.
2016-01-24 17:05:37 -08:00
}
}
private BiomeDataJson getBiomeData(boolean useQuarterResolution) {
if (useQuarterResolution) {
return quarterBiomeData;
} else {
return fullBiomeData;
}
}
@Override
public void createWorld(long seed, WorldType worldType, String generatorOptions)
throws MinecraftInterfaceException {
if (worldMetadataJson.getSeed() == seed && worldMetadataJson.getWorldType().equals(worldType)
added world icon test To prevent the need to make the minecraft jar file and libraries available on travis ci, this test uses previously generated testdata to ensure that the generated world icons are still the same as when the test data where generated. It is true, that this uses the production code to generate the test data, however, this is not an issue, because the test data are stored and not generated every time the test is executed. All in all, the test checks whether the generated world icons have changed since the test data where generated. It does not ensure, that the world icons are correct (meaning like minecraft generates them). The test: * loads the biome data from the test data * loads the world icons * creates a fake minecraft interface that provides the stored biome data * creates a world object using the fake minecraft interface * generates all world icons using the world object * compares the generated world icons to the loaded world icons The test data contains all biome data in the test area as well as all world icons. The test area is 10 fragments in all directions from [0, 0] ([-5120, -5120] to [5120, 5120]). The world icons are generated for the inner 10 - 1 = 9 fragments ([-4608, -4608] to [4608, 4608]). This prevents the world icon producers to request biome data that have not been stored. The test data are stored in a zip-file to prevent them from taking up to much space. One world requires about 6.5 MB (compressed). Thus, we should not add to much test worlds and not change them very often to prevent the repository from getting too big. An alternative would be stored the testdata somewhere else than in the repository. However, they have to be available for travis ci, so this will be the solution for now. * The End Cities are currently not included. * The current seed is "amidst-test-seed" using the default world type and minecraft version 1.8.9. * The test data are generated by running the test in the class DevToolRunner.
2016-01-24 17:05:37 -08:00
&& generatorOptions.isEmpty()) {
isWorldCreated = true;
} else {
isWorldCreated = false;
throw new MinecraftInterfaceException("the world has to match");
}
}
@Override
public RecognisedVersion getRecognisedVersion() {
return worldMetadataJson.getRecognisedVersion();
}
@Override
public GameEngineType getGameEngineType() {
return GameEngineType.MINECRAFT;
}
added world icon test To prevent the need to make the minecraft jar file and libraries available on travis ci, this test uses previously generated testdata to ensure that the generated world icons are still the same as when the test data where generated. It is true, that this uses the production code to generate the test data, however, this is not an issue, because the test data are stored and not generated every time the test is executed. All in all, the test checks whether the generated world icons have changed since the test data where generated. It does not ensure, that the world icons are correct (meaning like minecraft generates them). The test: * loads the biome data from the test data * loads the world icons * creates a fake minecraft interface that provides the stored biome data * creates a world object using the fake minecraft interface * generates all world icons using the world object * compares the generated world icons to the loaded world icons The test data contains all biome data in the test area as well as all world icons. The test area is 10 fragments in all directions from [0, 0] ([-5120, -5120] to [5120, 5120]). The world icons are generated for the inner 10 - 1 = 9 fragments ([-4608, -4608] to [4608, 4608]). This prevents the world icon producers to request biome data that have not been stored. The test data are stored in a zip-file to prevent them from taking up to much space. One world requires about 6.5 MB (compressed). Thus, we should not add to much test worlds and not change them very often to prevent the repository from getting too big. An alternative would be stored the testdata somewhere else than in the repository. However, they have to be available for travis ci, so this will be the solution for now. * The End Cities are currently not included. * The current seed is "amidst-test-seed" using the default world type and minecraft version 1.8.9. * The test data are generated by running the test in the class DevToolRunner.
2016-01-24 17:05:37 -08:00
}