Commit dae09c82 authored by Lubomir Bulej's avatar Lubomir Bulej

Make __mask() and __bits() method in NetReferenceHelper package-private and add two simple tests.

parent ef005986
...@@ -69,14 +69,14 @@ final class NetReferenceHelper { ...@@ -69,14 +69,14 @@ final class NetReferenceHelper {
* Returns bits from the given {@code long} value masked using the given * Returns bits from the given {@code long} value masked using the given
* mask and shifted to the right by the given amount. * mask and shifted to the right by the given amount.
*/ */
private static long __bits ( static long __bits (
final long value, final long mask, final short shift final long value, final long mask, final short shift
) { ) {
return (value & mask) >>> shift; return (value & mask) >>> shift;
} }
private static long __mask (final int length, final int shift) { static long __mask (final int length, final int shift) {
assert length > 0 && shift >= 0; assert length > 0 && shift >= 0;
return ((1L << length) - 1) << shift; return ((1L << length) - 1) << shift;
} }
......
package ch.usi.dag.dislreserver.shadow;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.theories.Theories;
import org.junit.runner.RunWith;
@RunWith (Theories.class)
public class NetReferenceHelperTest {
@Test
public void testFlagMaskCalculation () {
// 1-bit fields
Assert.assertEquals (0x0000000000000001L, NetReferenceHelper.__mask (1, 0));
Assert.assertEquals (0x0000000080000000L, NetReferenceHelper.__mask (1, 31));
Assert.assertEquals (0x0000000100000000L, NetReferenceHelper.__mask (1, 32));
Assert.assertEquals (0x8000000000000000L, NetReferenceHelper.__mask (1, 63));
// Actual shift amount is the requested amount modulo 64 (shift & 0x3f).
Assert.assertEquals (0x0000000000000001L, NetReferenceHelper.__mask (1, 64));
}
@Test
public void testBitFieldMaskCalculation () {
Assert.assertEquals (0x000000ffffffffffL, NetReferenceHelper.__mask (40, 0));
Assert.assertEquals (0x3fffff0000000000L, NetReferenceHelper.__mask (22, 40));
Assert.assertEquals (0xc000000000000000L, NetReferenceHelper.__mask (2, 62));
}
// TODO Test flag and bit field extraction
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment