-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from schemil053/dev
Merge upstream
- Loading branch information
Showing
12 changed files
with
113 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...st/java/de/emilschlampp/scheCPU/Main.java → ...e/emilschlampp/scheCPU/examples/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...chlampp/scheCPU/compile/CompilerTest.java → ...cheCPU/examples/compile/CompilerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...mpp/scheCPU/emulator/CPUEmulatorTest.java → ...PU/examples/emulator/CPUEmulatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...hlampp/scheCPU/high/HighCompilerTest.java → ...heCPU/examples/high/HighCompilerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...scheCPU/high/HighProgramCompilerTest.java → ...xamples/high/HighProgramCompilerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...p/scheCPU/util/CompileCompressorTest.java → .../examples/util/CompileCompressorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/test/java/de/emilschlampp/scheCPU/tests/CPUCompilerDecompilerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package de.emilschlampp.scheCPU.tests; | ||
|
||
import de.emilschlampp.scheCPU.compile.Compiler; | ||
import de.emilschlampp.scheCPU.dissassembler.Decompiler; | ||
import de.emilschlampp.scheCPU.util.StaticValues; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class CPUCompilerDecompilerTest { | ||
@Test | ||
public void testCompileDecompileSimple() { | ||
String val = "OUTW 1 0"; // Only simple instructions are possible | ||
|
||
byte[] program = new Compiler(val).compile(); | ||
|
||
assertEquals(val, new Decompiler(program).decompile()); | ||
} | ||
|
||
@Test | ||
public void testDeserial() { | ||
String val = "OUTW 1 0"; // Do not change!!! | ||
|
||
byte[] program = new Compiler(val).compile(); | ||
|
||
assertEquals(1, new Decompiler(program).getInstructions().length); | ||
assertEquals(StaticValues.OUTW_OPCODE, new Decompiler(program).getInstructions()[0].getOpCode()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/test/java/de/emilschlampp/scheCPU/tests/CPUStateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package de.emilschlampp.scheCPU.tests; | ||
|
||
import de.emilschlampp.scheCPU.compile.Compiler; | ||
import de.emilschlampp.scheCPU.emulator.ProcessorEmulator; | ||
import de.emilschlampp.scheCPU.util.FolderIOUtil; | ||
import de.emilschlampp.scheCPU.util.StaticValues; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
public class CPUStateTest { | ||
@Test() | ||
public void testSerialVersion() throws IOException { | ||
ProcessorEmulator processorEmulator = new ProcessorEmulator(5, 5, new Compiler("OUTW 1 0").compile()); | ||
processorEmulator.execute(); | ||
|
||
ByteArrayInputStream inputStream = new ByteArrayInputStream(processorEmulator.saveState()); | ||
|
||
assertEquals(FolderIOUtil.readInt(inputStream), StaticValues.SERIAL_VERSION); | ||
} | ||
|
||
@Test() | ||
public void testState() { | ||
byte[] program = new Compiler("OUTW 1 0").compile(); | ||
|
||
ProcessorEmulator processorEmulator1 = new ProcessorEmulator(5, 5, program); | ||
processorEmulator1.execute(); | ||
|
||
ProcessorEmulator processorEmulator2 = new ProcessorEmulator(5, 5, program); | ||
|
||
|
||
ProcessorEmulator stateCopy1 = new ProcessorEmulator(processorEmulator1.saveState()); | ||
ProcessorEmulator stateCopy2 = new ProcessorEmulator(processorEmulator2.saveState()); | ||
|
||
assertNotEquals(processorEmulator1.getJmp(), stateCopy2.getJmp()); | ||
assertNotEquals(processorEmulator2.getJmp(), stateCopy1.getJmp()); | ||
|
||
assertEquals(processorEmulator1.getJmp(), stateCopy1.getJmp()); | ||
assertEquals(processorEmulator2.getJmp(), stateCopy2.getJmp()); | ||
} | ||
} |