-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainMemTest.java
100 lines (85 loc) · 2.66 KB
/
MainMemTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* The test class MainMemTest.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MainMemTest
{
/**
* Default constructor for test class MainMemTest
*/
public MainMemTest()
{
}
/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
@Before
public void setUp()
{
}
/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
@After
public void tearDown()
{
}
@Test
public void testByteToHexOneByteZero()
{
MainMem mainMem1 = new MainMem((int) Math.pow(2, 7), 8);
assertEquals("00", mainMem1.byteToHex(new byte[]{(byte)0x0}));
}
@Test
public void testByteToHexOneByteFF()
{
MainMem mainMem1 = new MainMem((int) Math.pow(2, 7), 8);
assertEquals("FF", mainMem1.byteToHex(new byte[]{(byte)0xFF}));
}
@Test
public void testByteToHexTwoBytesCC()
{
MainMem mainMem1 = new MainMem((int) Math.pow(2, 7), 8);
assertEquals("CC CC", mainMem1.byteToHex(new byte[]{(byte)0xCC, (byte)0xCC}));
}
@Test
public void testByteToHexFourBytes()
{
MainMem mainMem1 = new MainMem((int) Math.pow(2, 7), 8);
assertEquals("55 EF AF C0", mainMem1.byteToHex(new byte[]{(byte)0x55, (byte)0xEF, (byte)0xAF, (byte)0xC0}));
}
@Test
public void testMemSize128ReadWrite()
{
MainMem mainMem1 = new MainMem((int) Math.pow(2, 7), 4);
java.lang.String[][] content = mainMem1.getContentHex();
assertEquals(32, content.length);
assertArrayEquals(new byte[] {0x0, 0x0, 0x0, 0x0}, mainMem1.read(0));
assertArrayEquals(new byte[] {0x0, 0x0, 0x0, 0x0}, mainMem1.read(5));
mainMem1.write(0, new byte[] {(byte)0xAA, (byte)0x2C, (byte)0x5A, (byte)0x11});
mainMem1.write(5, new byte[] {(byte)0x55, (byte)0x43, (byte)0x22, (byte)0x1B});
assertArrayEquals(new byte[] {(byte)0xAA, (byte)0x2C, (byte)0x5A, (byte)0x11}, mainMem1.read(0));
assertArrayEquals(new byte[] {(byte)0x55, (byte)0x43, (byte)0x22, (byte)0x1B}, mainMem1.read(5));
}
@Test
public void testMemorySize0ReadWrite()
{
MainMem mainMem1 = new MainMem(0, 4);
assertNull(mainMem1.read(0));
assertNull(mainMem1.read(5));
mainMem1.write(0, new byte[] {(byte)0xAA, (byte)0x2C, (byte)0x5A, (byte)0x11});
mainMem1.write(5, new byte[] {0x55, 0x43, 0x22, 0x1B});
assertNull(mainMem1.read(0));
assertNull(mainMem1.read(5));
}
}