8
8
9
9
import static org .junit .jupiter .api .Assertions .assertEquals ;
10
10
11
- public class TestGeneratorNumbers
11
+ public class SmileGeneratorNumbersTest
12
12
extends BaseTestForSmile
13
13
{
14
14
@ Test
@@ -118,9 +118,9 @@ public void testFloats() throws Exception
118
118
{
119
119
// float length is fixed, 6 bytes
120
120
ByteArrayOutputStream out = new ByteArrayOutputStream ();
121
- SmileGenerator gen = smileGenerator (out , false );
122
- gen .writeNumber (0.125f );
123
- gen . close ();
121
+ try ( SmileGenerator gen = smileGenerator (out , false )) {
122
+ gen .writeNumber (0.125f );
123
+ }
124
124
assertEquals (6 , out .toByteArray ().length );
125
125
}
126
126
@@ -129,12 +129,38 @@ public void testDoubles() throws Exception
129
129
{
130
130
// double length is fixed, 11 bytes
131
131
ByteArrayOutputStream out = new ByteArrayOutputStream ();
132
- SmileGenerator gen = smileGenerator (out , false );
133
- gen .writeNumber (0.125 );
134
- gen . close ();
132
+ try ( SmileGenerator gen = smileGenerator (out , false )) {
133
+ gen .writeNumber (0.125 );
134
+ }
135
135
assertEquals (11 , out .toByteArray ().length );
136
136
}
137
137
138
+ // [dataformats-binary#300]
139
+ @ Test
140
+ public void testFloatUnusedBits () throws Exception
141
+ {
142
+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
143
+ try (SmileGenerator gen = smileGenerator (out , false )) {
144
+ gen .writeNumber (-0f );
145
+ }
146
+ byte [] encoded = out .toByteArray ();
147
+ assertEquals (6 , encoded .length );
148
+ assertEquals (0x28 , encoded [0 ]); // type byte, float
149
+ }
150
+
151
+ // [dataformats-binary#300]
152
+ @ Test
153
+ public void testDoubleUnusedBits () throws Exception
154
+ {
155
+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
156
+ try (SmileGenerator gen = smileGenerator (out , false )) {
157
+ gen .writeNumber (-0d );
158
+ }
159
+ byte [] encoded = out .toByteArray ();
160
+ assertEquals (11 , encoded .length );
161
+ assertEquals (0x29 , encoded [0 ]); // type byte, double
162
+ }
163
+
138
164
// #16: Problems with 'Stringified' numbers
139
165
@ Test
140
166
public void testNumbersAsString () throws Exception
0 commit comments