11package  com .fasterxml .jackson .dataformat .smile .gen ;
22
33import  java .io .ByteArrayOutputStream ;
4+ import  java .util .Arrays ;
45
56import  org .junit .jupiter .api .Test ;
67
78import  com .fasterxml .jackson .dataformat .smile .*;
89
10+ import  static  org .junit .jupiter .api .Assertions .assertArrayEquals ;
911import  static  org .junit .jupiter .api .Assertions .assertEquals ;
1012
11- public  class  TestGeneratorNumbers 
13+ public  class  SmileGeneratorNumbersTest 
1214    extends  BaseTestForSmile 
1315{
1416    @ Test 
@@ -118,9 +120,9 @@ public void testFloats() throws Exception
118120    {
119121        // float length is fixed, 6 bytes 
120122        ByteArrayOutputStream  out  = new  ByteArrayOutputStream ();
121-         SmileGenerator  gen  = smileGenerator (out , false ); 
122-         gen .writeNumber (0.125f );
123-         gen . close (); 
123+         try  ( SmileGenerator  gen  = smileGenerator (out , false )) { 
124+              gen .writeNumber (0.125f );
125+         } 
124126        assertEquals (6 , out .toByteArray ().length );
125127    }
126128
@@ -129,12 +131,49 @@ public void testDoubles() throws Exception
129131    {
130132        // double length is fixed, 11 bytes 
131133        ByteArrayOutputStream  out  = new  ByteArrayOutputStream ();
132-         SmileGenerator  gen  = smileGenerator (out , false ); 
133-         gen .writeNumber (0.125 );
134-         gen . close (); 
134+         try  ( SmileGenerator  gen  = smileGenerator (out , false )) { 
135+              gen .writeNumber (0.125 );
136+         } 
135137        assertEquals (11 , out .toByteArray ().length );
136138    }
137139
140+     // [dataformats-binary#300] 
141+     @ Test 
142+     public  void  testFloatUnusedBits () throws  Exception 
143+     {
144+         ByteArrayOutputStream  out  = new  ByteArrayOutputStream ();
145+         try  (SmileGenerator  gen  = smileGenerator (out , false )) {
146+             gen .writeNumber (-0f );
147+         }
148+         byte [] encoded  = out .toByteArray ();
149+         assertEquals (6 , encoded .length );
150+         assertEquals (0x28 , encoded [0 ]); // type byte, float 
151+ 
152+         // From 0x80 0x00 0x00 0x00 (spread over 5 x 7bits) 
153+         assertArrayEquals (new  byte [] {
154+                 0x08 , 0x00 , 0x00 , 0x00 , 0x00 
155+         }, Arrays .copyOfRange (encoded , 1 , encoded .length ));
156+ }
157+ 
158+     // [dataformats-binary#300] 
159+     @ Test 
160+     public  void  testDoubleUnusedBits () throws  Exception 
161+     {
162+         ByteArrayOutputStream  out  = new  ByteArrayOutputStream ();
163+         try  (SmileGenerator  gen  = smileGenerator (out , false )) {
164+             gen .writeNumber (-0d );
165+         }
166+         byte [] encoded  = out .toByteArray ();
167+         assertEquals (11 , encoded .length );
168+         assertEquals (0x29 , encoded [0 ]); // type byte, double 
169+         // From 0x80 0x00 0x00 0x00 ... 0x00 (spread over 10 x 7 bits) 
170+ 
171+         assertArrayEquals (new  byte [] {
172+                 0x01 , 0x00 , 0x00 , 0x00 , 0x00 ,
173+                 0x00 , 0x00 , 0x00 , 0x00 , 0x00 
174+         }, Arrays .copyOfRange (encoded , 1 , encoded .length ));
175+     }
176+ 
138177    // #16: Problems with 'Stringified' numbers 
139178    @ Test 
140179    public  void  testNumbersAsString () throws  Exception 
0 commit comments