fix tests and configuration
This commit is contained in:
Simon Fortier 2019-04-23 16:39:35 -04:00 committed by GitHub
commit 6e4b2358af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 16 deletions

View File

@ -77,6 +77,7 @@
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version> <version>2.7.2</version>
<configuration> <configuration>
<forkMode>never</forkMode>
<workingDirectory>./src/main/resources</workingDirectory> <workingDirectory>./src/main/resources</workingDirectory>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -5,12 +5,29 @@ 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() {
ServerConfiguration config = new ServerConfiguration("config.properties"); int memorySize = getConfig().getInt("memory_size");
int memorySize = config.getInt("memory_size");
Memory memory = new Memory(memorySize); Memory memory = new Memory(memorySize);
memory.set(1, 1); memory.set(1, 1);
@ -28,12 +45,9 @@ public class MemoryTest {
@Test @Test
public void write() { public void write() {
int memorySize = getConfig().getInt("memory_size");
ServerConfiguration config = new ServerConfiguration("config.properties");
int memorySize = config.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));
assertFalse(memory.write(0, new char[memorySize], 0, memorySize + 1)); assertFalse(memory.write(0, new char[memorySize], 0, memorySize + 1));
assertFalse(memory.write(0, new char[memorySize], 0, -1)); assertFalse(memory.write(0, new char[memorySize], 0, -1));

View File

@ -9,17 +9,32 @@ 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() {
ServerConfiguration config = new ServerConfiguration("config.properties"); int memorySize = getConfig().getInt("memory_size");
int memorySize = config.getInt("memory_size");
//Memory //Memory
Memory memory = new Memory(memorySize); Memory memory = new Memory(memorySize);
@ -129,8 +144,7 @@ public class AddInstructionTest {
*/ */
@Test @Test
public void addTargetImm() { public void addTargetImm() {
ServerConfiguration config = new ServerConfiguration("config.properties"); int memorySize = getConfig().getInt("memory_size");
int memorySize = config.getInt("memory_size");
//Memory //Memory
Memory memory = new Memory(memorySize); Memory memory = new Memory(memorySize);

View File

@ -7,13 +7,29 @@ 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");
ServerConfiguration config = new ServerConfiguration("config.properties");
int memorySize = config.getInt("memory_size");
//Memory //Memory
Memory memory = new Memory(memorySize); Memory memory = new Memory(memorySize);
@ -53,9 +69,7 @@ public class AndInstructionTest {
@Test @Test
public void executeTargetImm() { public void executeTargetImm() {
int memorySize = getConfig().getInt("memory_size");
ServerConfiguration config = new ServerConfiguration("config.properties");
int memorySize = config.getInt("memory_size");
//Memory //Memory
Memory memory = new Memory(memorySize); Memory memory = new Memory(memorySize);