Added tests for reverse and intToBytes

#story[829]
This commit is contained in:
Michael Rausch
2017-04-30 23:54:32 +12:00
parent e7f9954970
commit 50083a9297
+27 -2
View File
@@ -9,12 +9,11 @@ import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue; import static junit.framework.TestCase.assertTrue;
public class TestMessage { public class TestMessage {
private static int XML_MESSAGE_LEN = 14; 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; private static int CRC_LEN = 4;
@@ -27,5 +26,31 @@ public class TestMessage {
assertTrue(m.getSize() == (XML_MESSAGE_LEN + "12345".length())); 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);
}
} }