Tests, a lot of textures and bug fixes
This commit is contained in:
39
src/test/java/de/siphalor/was/ContentTests.java
Normal file
39
src/test/java/de/siphalor/was/ContentTests.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package de.siphalor.was;
|
||||
|
||||
import de.siphalor.was.content.ContentManager;
|
||||
import de.siphalor.was.content.pack.ContentPack;
|
||||
import de.siphalor.was.content.pack.JarContentPack;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class ContentTests {
|
||||
static ContentManager contentManager;
|
||||
static ContentPack contentPack;
|
||||
|
||||
@BeforeAll
|
||||
public static void prepareAll() {
|
||||
contentManager = new ContentManager();
|
||||
contentPack = new JarContentPack("jar", "content");
|
||||
contentManager.addPack(contentPack);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void areLangsUpToDate() throws IOException {
|
||||
Properties properties = new Properties();
|
||||
InputStream inputStream = contentManager.getResource("lang/en_us.lang").orElseThrow().getInputStream();
|
||||
properties.load(inputStream);
|
||||
|
||||
contentManager.getResources("lang", "lang").forEach(resource -> {
|
||||
if (!resource.getId().equals("lang/en_us.lang")) {
|
||||
Properties props = new Properties();
|
||||
Assertions.assertDoesNotThrow(() -> props.load(resource.getInputStream()));
|
||||
Assertions.assertEquals(properties.keySet(), props.keySet(), "Missing lang keys for " + resource.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
36
src/test/java/de/siphalor/was/I18nTests.java
Normal file
36
src/test/java/de/siphalor/was/I18nTests.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package de.siphalor.was;
|
||||
|
||||
import de.siphalor.was.content.ContentManager;
|
||||
import de.siphalor.was.content.lang.Lang;
|
||||
import de.siphalor.was.dummy.DummyContentPack;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class I18nTests {
|
||||
static ContentManager contentManager;
|
||||
static DummyContentPack contentPack;
|
||||
static Lang lang;
|
||||
|
||||
@BeforeAll
|
||||
public static void prepareAll() {
|
||||
contentManager = new ContentManager();
|
||||
contentPack = new DummyContentPack("dummy");
|
||||
contentManager.addPack(contentPack);
|
||||
contentPack.content.put("lang/dummy.lang", "abc = missingno\nescaped = \\\\\na.b.c = noop\nformatted = Formatted: %s!\nunicode = \\u20ac");
|
||||
lang = new Lang("dummy");
|
||||
lang.load(contentManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicTest() {
|
||||
Assertions.assertEquals("missingno", lang.get("abc"));
|
||||
Assertions.assertEquals("noop", lang.get("a.b.c"));
|
||||
Assertions.assertEquals("\\", lang.get("escaped"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unicodeTest() {
|
||||
Assertions.assertEquals("\u20ac", lang.get("unicode"), "Failed to resolve unicode in lang file");
|
||||
}
|
||||
}
|
||||
72
src/test/java/de/siphalor/was/StorageTests.java
Normal file
72
src/test/java/de/siphalor/was/StorageTests.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package de.siphalor.was;
|
||||
|
||||
import de.siphalor.was.content.product.Product;
|
||||
import de.siphalor.was.dummy.DummyProduct;
|
||||
import de.siphalor.was.game.Storage;
|
||||
import de.siphalor.was.game.StorageSlot;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class StorageTests {
|
||||
static Storage storage;
|
||||
static DummyProduct.Type productType;
|
||||
static Product simpleProduct;
|
||||
static Product deepProduct;
|
||||
|
||||
@BeforeAll
|
||||
public static void prepareAll() {
|
||||
storage = new Storage(3, 3, 3);
|
||||
productType = new DummyProduct.Type("dummy", "one", "two");
|
||||
simpleProduct = productType.getProduct(new String[]{"simple", "a"});
|
||||
deepProduct = productType.getProduct(new String[]{"deep", "wood"});
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void prepare() {
|
||||
storage.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void illegalConstructorTest() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> new Storage(0, 1, 2), "Illegal storage constructed");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> new Storage(1, 0, 2), "Illegal storage constructed");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> new Storage(1, 1, 0), "Illegal storage constructed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearTest() {
|
||||
for (int x = 0; x < storage.getWidth(); x++) {
|
||||
for (int y = 0; y < storage.getHeight(); y++) {
|
||||
storage.get(x, y).add(productType.getProduct(new String[]{"test", Double.toString(Math.random())}));
|
||||
}
|
||||
}
|
||||
|
||||
storage.clear();
|
||||
|
||||
for (int x = 0; x < storage.getWidth(); x++) {
|
||||
for (int y = 0; y < storage.getHeight(); y++) {
|
||||
Assertions.assertNull(storage.get(x, y).front(), "Failed to clear storage");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void depthTest() {
|
||||
StorageSlot slot = storage.get(0, 0);
|
||||
|
||||
Assertions.assertEquals(0, slot.add(simpleProduct));
|
||||
Assertions.assertEquals(1, slot.add(simpleProduct));
|
||||
Assertions.assertEquals(2, slot.add(simpleProduct));
|
||||
Assertions.assertEquals(-1, slot.add(simpleProduct), "Can add more products to storage than allowed");
|
||||
|
||||
slot.clear();
|
||||
Assertions.assertEquals(0, slot.add(deepProduct));
|
||||
Assertions.assertEquals(-1, slot.add(simpleProduct), "Can add more depth to storage than allowed");
|
||||
|
||||
slot.clear();
|
||||
Assertions.assertEquals(0, slot.add(simpleProduct));
|
||||
Assertions.assertEquals(-1, slot.add(deepProduct), "Can add more depth to storage than allowed");
|
||||
}
|
||||
}
|
||||
36
src/test/java/de/siphalor/was/dummy/DummyContentPack.java
Normal file
36
src/test/java/de/siphalor/was/dummy/DummyContentPack.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package de.siphalor.was.dummy;
|
||||
|
||||
import de.siphalor.was.content.pack.ContentPack;
|
||||
import de.siphalor.was.content.resource.Resource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class DummyContentPack implements ContentPack {
|
||||
public final String id;
|
||||
public final Map<String, String> content = new HashMap<>();
|
||||
|
||||
public DummyContentPack(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Stream<Resource> getResources(@NotNull String location, @NotNull String type) {
|
||||
return content.entrySet().stream().filter(e -> e.getKey().startsWith(location) && e.getKey().endsWith(type)).map(e -> new DummyResource(e.getKey(), e.getValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Resource getResource(@NotNull String location) {
|
||||
if (content.containsKey(location))
|
||||
return new DummyResource(location, content.get(location));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
94
src/test/java/de/siphalor/was/dummy/DummyProduct.java
Normal file
94
src/test/java/de/siphalor/was/dummy/DummyProduct.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package de.siphalor.was.dummy;
|
||||
|
||||
import de.siphalor.was.content.product.Product;
|
||||
import de.siphalor.was.content.product.ProductType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class DummyProduct implements Product {
|
||||
public final Type type;
|
||||
public final Predicate<Integer> yPredicate;
|
||||
public final int depth;
|
||||
public final String[] properties;
|
||||
|
||||
public DummyProduct(Type type, Predicate<Integer> yPredicate, int depth, String[] properties) {
|
||||
this.type = type;
|
||||
this.yPredicate = yPredicate;
|
||||
this.depth = depth;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getPropertySpecifier() {
|
||||
return String.join(", ", properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testY(int y) {
|
||||
if (yPredicate != null)
|
||||
return yPredicate.test(y);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ProductType<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Product product) {
|
||||
return product.getType() == getType() && product.getPropertySpecifier().equals(getPropertySpecifier());
|
||||
}
|
||||
|
||||
public static class Type implements ProductType<DummyProduct> {
|
||||
public final String id;
|
||||
public final String[] properties;
|
||||
|
||||
public Type(String id, String... properties) {
|
||||
this.id = id;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DummyProduct getProduct(@NotNull String[] values) {
|
||||
Predicate<Integer> yPredicate = null;
|
||||
int depth = 1;
|
||||
if (Arrays.binarySearch(values, "deep") >= 0) {
|
||||
depth = 3;
|
||||
} else if (Arrays.binarySearch(values, "heavy") >= 0) {
|
||||
yPredicate = y -> y == 0;
|
||||
}
|
||||
return new DummyProduct(this, yPredicate, depth, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String[] getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Product randomProduct(Random random) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/test/java/de/siphalor/was/dummy/DummyResource.java
Normal file
22
src/test/java/de/siphalor/was/dummy/DummyResource.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package de.siphalor.was.dummy;
|
||||
|
||||
import de.siphalor.was.content.resource.Resource;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class DummyResource extends Resource {
|
||||
public final String value;
|
||||
|
||||
protected DummyResource(String id, String value) {
|
||||
super(id);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable InputStream getInputStream() {
|
||||
return new ByteArrayInputStream(value.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
49
src/test/java/de/siphalor/was/dummy/DummyVisual.java
Normal file
49
src/test/java/de/siphalor/was/dummy/DummyVisual.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package de.siphalor.was.dummy;
|
||||
|
||||
import de.siphalor.was.WhatAStorage;
|
||||
import de.siphalor.was.content.product.Product;
|
||||
import de.siphalor.was.content.quest.Quest;
|
||||
import de.siphalor.was.game.Balance;
|
||||
import de.siphalor.was.visual.Visual;
|
||||
|
||||
public class DummyVisual implements Visual {
|
||||
@Override
|
||||
public void setup(WhatAStorage whatAStorage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScheduleStop() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBalanceChanged(int budget, Balance.Transaction transaction, int change, int totalIncome, int totalLoss) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuestAdded(Quest newQuest, boolean canCreateMore) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuestRemoved(int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProductSet(int x, int y, int z, Product product) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProductCleared(int x, int y, int z) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user