88
99import static org .junit .jupiter .api .Assertions .assertEquals ;
1010
11- public class TestGeneratorNumbers
11+ public class SmileGeneratorNumbersTest
1212 extends BaseTestForSmile
1313{
1414 @ Test
@@ -118,9 +118,9 @@ public void testFloats() throws Exception
118118 {
119119 // float length is fixed, 6 bytes
120120 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+ }
124124 assertEquals (6 , out .toByteArray ().length );
125125 }
126126
@@ -129,12 +129,38 @@ public void testDoubles() throws Exception
129129 {
130130 // double length is fixed, 11 bytes
131131 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+ }
135135 assertEquals (11 , out .toByteArray ().length );
136136 }
137137
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+
138164 // #16: Problems with 'Stringified' numbers
139165 @ Test
140166 public void testNumbersAsString () throws Exception
0 commit comments