MemoryJUnitTest.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. import org.junit.After;
  7. import org.junit.AfterClass;
  8. import org.junit.Assert;
  9. import org.junit.Before;
  10. import org.junit.BeforeClass;
  11. import org.junit.Test;
  12. import tools.mips.Memory;
  13. /**
  14. *
  15. * @author EUGENIO CARVALHO
  16. */
  17. public class MemoryJUnitTest {
  18. private Memory memory;
  19. public MemoryJUnitTest() {
  20. }
  21. @BeforeClass
  22. public static void setUpClass() {
  23. }
  24. @AfterClass
  25. public static void tearDownClass() {
  26. }
  27. @Before
  28. public void setUp() {
  29. memory = new Memory(16 * 1024);
  30. }
  31. @After
  32. public void tearDown() {
  33. }
  34. @Test
  35. public void WriteByte() throws Exception {
  36. String bd = "00000010";
  37. memory.WB(bd);
  38. Assert.assertEquals(bd, memory.RB(0));
  39. }
  40. @Test
  41. public void WriteByteAddressed() throws Exception {
  42. String bd = "00000010";
  43. Long address = 16L;
  44. memory.WB(address, bd);
  45. Assert.assertEquals(bd, memory.RB(address));
  46. }
  47. @Test
  48. public void WriteMultByteAddressed() throws Exception {
  49. Long value = 14030L;
  50. Long address = 16L;
  51. // Escreve 4 bytes a partir do endereco 16
  52. memory.W(address, Long.toBinaryString(value), 4);
  53. // Lê 4 bytes a partir do endereco 16 -> converte binario para long
  54. Assert.assertEquals(value, memory.ReadLong(address, 4));
  55. }
  56. @Test
  57. public void WriteInvalidAddress() throws Exception {
  58. boolean result = false;
  59. try {
  60. String bd = "00000010";
  61. Long address = 17000L;
  62. memory.WB(address, bd);
  63. } catch (Exception e) {
  64. result = true;
  65. }
  66. Assert.assertTrue(result);
  67. }
  68. }