mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-10 06:16:45 +00:00
Fix build fail and refactor config file in tests
This commit is contained in:
parent
6e4b2358af
commit
2f7d2cd85a
@ -237,7 +237,7 @@ public class VaultDimension {
|
|||||||
openings.add(Direction.WEST);
|
openings.add(Direction.WEST);
|
||||||
attachedWorld.openings.add(Direction.EAST);
|
attachedWorld.openings.add(Direction.EAST);
|
||||||
break;
|
break;
|
||||||
case default;
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
Server/src/test/java/net/simon987/server/ConfigHelper.java
Normal file
24
Server/src/test/java/net/simon987/server/ConfigHelper.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package net.simon987.server;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class ConfigHelper {
|
||||||
|
public static ServerConfiguration getConfig() {
|
||||||
|
File workingDir = new File("");
|
||||||
|
File file = new File(workingDir.getAbsolutePath(), "config.properties");
|
||||||
|
|
||||||
|
if (!file.exists()) {
|
||||||
|
File fallback = new File("Server/src/main/resources/", file.getName());
|
||||||
|
if (fallback.exists()) {
|
||||||
|
file = fallback;
|
||||||
|
} else {
|
||||||
|
throw new AssertionError("'config.properties' and " +
|
||||||
|
"'Server/src/main/resources/config.properties' cannot be found with working directory: " +
|
||||||
|
workingDir.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ServerConfiguration(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,33 +1,15 @@
|
|||||||
package net.simon987.server.assembly;
|
package net.simon987.server.assembly;
|
||||||
|
|
||||||
import net.simon987.server.ServerConfiguration;
|
import net.simon987.server.ConfigHelper;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class MemoryTest {
|
public class MemoryTest {
|
||||||
|
|
||||||
ServerConfiguration getConfig() {
|
|
||||||
String filePath = "config.properties";
|
|
||||||
|
|
||||||
if (!new File(filePath).exists()) {
|
|
||||||
File fallback = new File("Server/src/main/resources/", filePath);
|
|
||||||
if (fallback.exists()) {
|
|
||||||
filePath = fallback.getAbsolutePath();
|
|
||||||
} else {
|
|
||||||
throw new AssertionError("'config.properties' and 'Server/src/main/resources/config.properties' cannot be found with working directory: " + new File("").getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerConfiguration config = new ServerConfiguration(filePath);
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSet() {
|
public void getSet() {
|
||||||
int memorySize = getConfig().getInt("memory_size");
|
int memorySize = ConfigHelper.getConfig().getInt("memory_size");
|
||||||
Memory memory = new Memory(memorySize);
|
Memory memory = new Memory(memorySize);
|
||||||
|
|
||||||
memory.set(1, 1);
|
memory.set(1, 1);
|
||||||
@ -45,7 +27,7 @@ public class MemoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void write() {
|
public void write() {
|
||||||
int memorySize = getConfig().getInt("memory_size");
|
int memorySize = ConfigHelper.getConfig().getInt("memory_size");
|
||||||
Memory memory = new Memory(memorySize);
|
Memory memory = new Memory(memorySize);
|
||||||
|
|
||||||
assertTrue(memory.write(0, new char[memorySize], 0, memorySize));
|
assertTrue(memory.write(0, new char[memorySize], 0, memorySize));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.simon987.server.assembly.instruction;
|
package net.simon987.server.assembly.instruction;
|
||||||
|
|
||||||
import net.simon987.server.ServerConfiguration;
|
import net.simon987.server.ConfigHelper;
|
||||||
import net.simon987.server.assembly.Memory;
|
import net.simon987.server.assembly.Memory;
|
||||||
import net.simon987.server.assembly.Register;
|
import net.simon987.server.assembly.Register;
|
||||||
import net.simon987.server.assembly.RegisterSet;
|
import net.simon987.server.assembly.RegisterSet;
|
||||||
@ -9,32 +9,14 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class AddInstructionTest {
|
public class AddInstructionTest {
|
||||||
|
|
||||||
ServerConfiguration getConfig() {
|
|
||||||
String filePath = "config.properties";
|
|
||||||
|
|
||||||
if (!new File(filePath).exists()) {
|
|
||||||
File fallback = new File("Server/src/main/resources/", filePath);
|
|
||||||
if (fallback.exists()) {
|
|
||||||
filePath = fallback.getAbsolutePath();
|
|
||||||
} else {
|
|
||||||
throw new AssertionError("'config.properties' and 'Server/src/main/resources/config.properties' cannot be found with working directory: " + new File("").getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerConfiguration config = new ServerConfiguration(filePath);
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ADD mem/reg, mem/reg
|
* ADD mem/reg, mem/reg
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addTargetTarget() {
|
public void addTargetTarget() {
|
||||||
int memorySize = getConfig().getInt("memory_size");
|
int memorySize = ConfigHelper.getConfig().getInt("memory_size");
|
||||||
|
|
||||||
//Memory
|
//Memory
|
||||||
Memory memory = new Memory(memorySize);
|
Memory memory = new Memory(memorySize);
|
||||||
@ -144,7 +126,7 @@ public class AddInstructionTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addTargetImm() {
|
public void addTargetImm() {
|
||||||
int memorySize = getConfig().getInt("memory_size");
|
int memorySize = ConfigHelper.getConfig().getInt("memory_size");
|
||||||
|
|
||||||
//Memory
|
//Memory
|
||||||
Memory memory = new Memory(memorySize);
|
Memory memory = new Memory(memorySize);
|
||||||
|
@ -1,35 +1,17 @@
|
|||||||
package net.simon987.server.assembly.instruction;
|
package net.simon987.server.assembly.instruction;
|
||||||
|
|
||||||
import net.simon987.server.ServerConfiguration;
|
import net.simon987.server.ConfigHelper;
|
||||||
import net.simon987.server.assembly.Memory;
|
import net.simon987.server.assembly.Memory;
|
||||||
import net.simon987.server.assembly.Status;
|
import net.simon987.server.assembly.Status;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class AndInstructionTest {
|
public class AndInstructionTest {
|
||||||
|
|
||||||
ServerConfiguration getConfig() {
|
|
||||||
String filePath = "config.properties";
|
|
||||||
|
|
||||||
if (!new File(filePath).exists()) {
|
|
||||||
File fallback = new File("Server/src/main/resources/", filePath);
|
|
||||||
if (fallback.exists()) {
|
|
||||||
filePath = fallback.getAbsolutePath();
|
|
||||||
} else {
|
|
||||||
throw new AssertionError("'config.properties' and 'Server/src/main/resources/config.properties' cannot be found with working directory: " + new File("").getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerConfiguration config = new ServerConfiguration(filePath);
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void executeTargetTarget() {
|
public void executeTargetTarget() {
|
||||||
int memorySize = getConfig().getInt("memory_size");
|
int memorySize = ConfigHelper.getConfig().getInt("memory_size");
|
||||||
|
|
||||||
//Memory
|
//Memory
|
||||||
Memory memory = new Memory(memorySize);
|
Memory memory = new Memory(memorySize);
|
||||||
@ -69,7 +51,7 @@ public class AndInstructionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void executeTargetImm() {
|
public void executeTargetImm() {
|
||||||
int memorySize = getConfig().getInt("memory_size");
|
int memorySize = ConfigHelper.getConfig().getInt("memory_size");
|
||||||
|
|
||||||
//Memory
|
//Memory
|
||||||
Memory memory = new Memory(memorySize);
|
Memory memory = new Memory(memorySize);
|
||||||
|
@ -3,7 +3,7 @@ package net.simon987.server.assembly.instruction;
|
|||||||
import net.simon987.server.assembly.Status;
|
import net.simon987.server.assembly.Status;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class BrkInstructionTest {
|
public class BrkInstructionTest {
|
||||||
@Test
|
@Test
|
||||||
@ -17,8 +17,7 @@ public class BrkInstructionTest {
|
|||||||
|
|
||||||
brkInstruction.execute(status);
|
brkInstruction.execute(status);
|
||||||
|
|
||||||
assertEquals(true, status.isBreakFlag());
|
assertTrue(status.isBreakFlag());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user