29import static org.jau.util.ValueConv.*;
31import org.junit.Assert;
35import org.junit.FixMethodOrder;
37import org.junit.runners.MethodSorters;
39@FixMethodOrder(MethodSorters.NAME_ASCENDING)
44 Assert.assertEquals(Byte.MAX_VALUE, float_to_byte( 1.0f,
true));
45 Assert.assertEquals(Byte.MIN_VALUE, float_to_byte(-1.0f,
true));
46 Assert.assertEquals( 1.0f, byte_to_float( Byte.MAX_VALUE,
true), 0.0);
47 Assert.assertEquals(-1.0f, byte_to_float( Byte.MIN_VALUE,
true), 0.0);
49 Assert.assertEquals(Short.MAX_VALUE, float_to_short( 1.0f,
true));
50 Assert.assertEquals(Short.MIN_VALUE, float_to_short(-1.0f,
true));
51 Assert.assertEquals( 1.0f, short_to_float( Short.MAX_VALUE,
true), 0.0);
52 Assert.assertEquals(-1.0f, short_to_float( Short.MIN_VALUE,
true), 0.0);
54 Assert.assertEquals(Integer.MAX_VALUE, float_to_int( 1.0f,
true));
55 Assert.assertEquals(Integer.MIN_VALUE, float_to_int(-1.0f,
true));
56 Assert.assertEquals( 1.0f, int_to_float( Integer.MAX_VALUE,
true), 0.0);
57 Assert.assertEquals(-1.0f, int_to_float( Integer.MIN_VALUE,
true), 0.0);
59 Assert.assertEquals((
byte)0xff, float_to_byte( 1.0f,
false));
60 Assert.assertEquals( 1.0f, byte_to_float( (
byte)0xff,
false), 0.0);
62 Assert.assertEquals((
short)0xffff, float_to_short( 1.0f,
false));
63 Assert.assertEquals( 1.0f, short_to_float( (
short)0xffff,
false), 0.0);
65 Assert.assertEquals(0xffffffff, float_to_int( 1.0f,
false));
66 Assert.assertEquals( 1.0f, int_to_float( 0xffffffff,
false), 0.0);
71 Assert.assertEquals(Byte.MAX_VALUE, double_to_byte( 1.0,
true));
72 Assert.assertEquals(Byte.MIN_VALUE, double_to_byte(-1.0,
true));
73 Assert.assertEquals( 1.0, byte_to_double( Byte.MAX_VALUE,
true), 0.0);
74 Assert.assertEquals(-1.0, byte_to_double( Byte.MIN_VALUE,
true), 0.0);
76 Assert.assertEquals(Short.MAX_VALUE, double_to_short( 1.0,
true));
77 Assert.assertEquals(Short.MIN_VALUE, double_to_short(-1.0,
true));
78 Assert.assertEquals( 1.0, short_to_double( Short.MAX_VALUE,
true), 0.0);
79 Assert.assertEquals(-1.0, short_to_double( Short.MIN_VALUE,
true), 0.0);
81 Assert.assertEquals(Integer.MAX_VALUE, double_to_int( 1.0,
true));
82 Assert.assertEquals(Integer.MIN_VALUE, double_to_int(-1.0,
true));
83 Assert.assertEquals( 1.0, int_to_double( Integer.MAX_VALUE,
true), 0.0);
84 Assert.assertEquals(-1.0, int_to_double( Integer.MIN_VALUE,
true), 0.0);
86 Assert.assertEquals((
byte)0xff, double_to_byte( 1.0,
false));
87 Assert.assertEquals( 1.0, byte_to_double( (
byte)0xff,
false), 0.0);
89 Assert.assertEquals((
short)0xffff, double_to_short( 1.0,
false));
90 Assert.assertEquals( 1.0, short_to_double( (
short)0xffff,
false), 0.0);
92 Assert.assertEquals(0xffffffff, double_to_int( 1.0,
false));
93 Assert.assertEquals( 1.0, int_to_double( 0xffffffff,
false), 0.0);
99 final byte sb1 = -128;
101 final float sf0 = byte_to_float(sb0,
true);
102 final float sf1 = byte_to_float(sb1,
true);
103 final short ss0 = byte_to_short(sb0,
true,
true);
104 final short ss1 = byte_to_short(sb1,
true,
true);
105 final int si0 = byte_to_int(sb0,
true,
true);
106 final int si1 = byte_to_int(sb1,
true,
true);
108 Assert.assertEquals(1.0f, sf0, 0.0);
109 Assert.assertEquals(-1.0f, sf1, 0.0);
110 Assert.assertEquals(Short.MAX_VALUE, ss0);
111 Assert.assertEquals(Short.MIN_VALUE, ss1);
112 Assert.assertEquals(Integer.MAX_VALUE, si0);
113 Assert.assertEquals(Integer.MIN_VALUE, si1);
115 Assert.assertEquals(sb0, short_to_byte(ss0,
true,
true));
116 Assert.assertEquals(sb1, short_to_byte(ss1,
true,
true));
117 Assert.assertEquals(sb0, int_to_byte(si0,
true,
true));
118 Assert.assertEquals(sb1, int_to_byte(si1,
true,
true));
120 final byte ub0 = (byte) 0xff;
121 final float uf0 = byte_to_float(ub0,
false);
122 final short us0 = byte_to_short(ub0,
false,
false);
123 final int ui0 = byte_to_int(ub0,
false,
false);
125 Assert.assertEquals(1.0f, uf0, 0.0);
126 Assert.assertEquals((
short)0xffff, us0);
127 Assert.assertEquals(0xffffffff, ui0);
129 Assert.assertEquals(ub0, short_to_byte(us0,
false,
false));
130 Assert.assertEquals(us0, int_to_short(ui0,
false,
false));
133 public static void main(
final String args[]) {
static void main(final String args[])