12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- import org.junit.After;
- import org.junit.AfterClass;
- import org.junit.Assert;
- import org.junit.Before;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import tools.mips.Memory;
- /**
- *
- * @author EUGENIO CARVALHO
- */
- public class MemoryJUnitTest {
- private Memory memory;
- public MemoryJUnitTest() {
- }
- @BeforeClass
- public static void setUpClass() {
- }
- @AfterClass
- public static void tearDownClass() {
- }
- @Before
- public void setUp() {
- memory = new Memory(16 * 1024);
- }
- @After
- public void tearDown() {
- }
- @Test
- public void WriteByte() throws Exception {
- String bd = "00000010";
- memory.WB(bd);
- Assert.assertEquals(bd, memory.RB(0));
- }
- @Test
- public void WriteByteAddressed() throws Exception {
- String bd = "00000010";
- Long address = 16L;
- memory.WB(address, bd);
- Assert.assertEquals(bd, memory.RB(address));
- }
- @Test
- public void WriteMultByteAddressed() throws Exception {
- Long value = 14030L;
- Long address = 16L;
- // Escreve 4 bytes a partir do endereco 16
- memory.W(address, Long.toBinaryString(value), 4);
- // Lê 4 bytes a partir do endereco 16 -> converte binario para long
- Assert.assertEquals(value, memory.ReadLong(address, 4));
- }
- @Test
- public void WriteInvalidAddress() throws Exception {
- boolean result = false;
- try {
- String bd = "00000010";
- Long address = 17000L;
- memory.WB(address, bd);
- } catch (Exception e) {
- result = true;
- }
- Assert.assertTrue(result);
- }
- }
|