mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 22:38:43 +00:00
Added tests for reverse and intToBytes
#story[829]
This commit is contained in:
@@ -9,12 +9,11 @@ import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
public class TestMessage {
|
||||
private static int XML_MESSAGE_LEN = 14;
|
||||
private static int RACE_STATUS_BASE_LEN = 24;
|
||||
private static int BOAT_SUB_MESSAGE_LEN = 20;
|
||||
private static int CRC_LEN = 4;
|
||||
|
||||
|
||||
@@ -27,5 +26,31 @@ public class TestMessage {
|
||||
assertTrue(m.getSize() == (XML_MESSAGE_LEN + "12345".length()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageBytesReverse(){
|
||||
byte[] bytes = {1,2,3,4,5};
|
||||
Message.reverse(bytes);
|
||||
|
||||
int testValue = 1;
|
||||
for (int i = 5; i > 0; i--){
|
||||
assertEquals((byte) testValue, bytes[i-1]);
|
||||
testValue++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntToByteArray(){
|
||||
long originalValue = 0x5050;
|
||||
long testValue = 0;
|
||||
|
||||
byte[] bytes = Message.intToByteArray(originalValue, 6);
|
||||
Message.reverse(bytes);
|
||||
|
||||
for (int i = 0; i < bytes.length; i++){
|
||||
testValue += ((long) bytes[i] & 0xffL) << (8 * i);
|
||||
}
|
||||
|
||||
assertEquals(originalValue, testValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user