MemoryJUnitTest.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 junit.framework.Assert;
  7. import org.junit.After;
  8. import org.junit.AfterClass;
  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 WriteBinaryByte() throws Exception {
  36. // System.out.println(Long.toBinaryString(2L));
  37. // System.out.println(Long.toBinaryString(2L));
  38. Long value = -3L;
  39. memory.W(0L, Long.toBinaryString(value), 4);
  40. Assert.assertEquals(value, memory.ReadLong(0L, 4));
  41. value = 3L;
  42. memory.W(0L, Long.toBinaryString(value), 4);
  43. Assert.assertEquals(value, memory.ReadLong(0L, 4));
  44. // System.out.println(Long.toBinaryString(-3L));
  45. // System.out.println(Long.parseUnsignedLong(Long.toBinaryString(-3L), 2));
  46. // System.out.println(Long.parseUnsignedLong("11111111111111111111111111111101", 2));
  47. // System.out.println(Long.parseUnsignedLong("1111111111111111111111111111111111111111111111111111111111111101", 2));
  48. }
  49. // @Test
  50. // public void WriteByte() throws Exception {
  51. // String bd = "00000010";
  52. // memory.WB(bd);
  53. // Assert.assertEquals(bd, memory.RB(0));
  54. // }
  55. //
  56. // @Test
  57. // public void WriteByteAddressed() throws Exception {
  58. // String bd = "00000010";
  59. // Long address = 16L;
  60. // memory.WB(address, bd);
  61. // Assert.assertEquals(bd, memory.RB(address));
  62. // }
  63. // @Test
  64. // public void WriteMultByteAddressed() throws Exception {
  65. // Long value = 14030L;
  66. //
  67. // Long address = 16L;
  68. // // Escreve 4 bytes a partir do endereco 16
  69. // memory.W(address, Long.toBinaryString(value), 4);
  70. //
  71. // // Lê 4 bytes a partir do endereco 16 -> converte binario para long
  72. // Assert.assertEquals(value, memory.ReadLong(address, 4));
  73. // }
  74. //
  75. // @Test
  76. // public void WriteNegativeValueAddressed() throws Exception {
  77. // Long value = -3L;
  78. // Long address = 16L;
  79. // // Escreve 4 bytes a partir do endereco 16
  80. // memory.W(address, value, 4);
  81. // // Lê 4 bytes a partir do endereco 16 -> converte binario para long
  82. // Assert.assertEquals(value, memory.ReadLong(address, 4));
  83. // }
  84. // @Test
  85. // public void WriteInvalidAddress() throws Exception {
  86. // boolean result = false;
  87. // try {
  88. // String bd = "00000010";
  89. // Long address = 17000L;
  90. // memory.WB(address, bd);
  91. // } catch (Exception e) {
  92. // result = true;
  93. // }
  94. // Assert.assertTrue(result);
  95. // }
  96. }