@@ -80,6 +80,32 @@ describe('float', () => {
80
80
) ;
81
81
} ) ;
82
82
83
+ it ( 'should reject any constraints defining min (not-NaN) equal to max if one is exclusive' , ( ) => {
84
+ fc . assert (
85
+ fc . property (
86
+ float32raw ( ) ,
87
+ fc . record ( { noDefaultInfinity : fc . boolean ( ) , noNaN : fc . boolean ( ) } , { withDeletedKeys : true } ) ,
88
+ fc . constantFrom ( 'min' , 'max' , 'both' ) ,
89
+ ( f , otherCt , exclusiveMode ) => {
90
+ // Arrange
91
+ fc . pre ( isNotNaN32bits ( f ) ) ;
92
+ spyInteger ( ) ;
93
+
94
+ // Act / Assert
95
+ expect ( ( ) =>
96
+ float ( {
97
+ ...otherCt ,
98
+ min : f ,
99
+ max : f ,
100
+ minExcluded : exclusiveMode === 'min' || exclusiveMode === 'both' ,
101
+ maxExcluded : exclusiveMode === 'max' || exclusiveMode === 'both' ,
102
+ } )
103
+ ) . toThrowError ( ) ;
104
+ }
105
+ )
106
+ ) ;
107
+ } ) ;
108
+
83
109
it ( 'should reject non-32-bit or NaN floating point numbers if specified for min' , ( ) => {
84
110
fc . assert (
85
111
fc . property ( float64raw ( ) , ( f64 ) => {
@@ -136,10 +162,16 @@ describe('float', () => {
136
162
expect ( integer ) . not . toHaveBeenCalled ( ) ;
137
163
} ) ;
138
164
139
- it ( 'should properly convert integer value for index between min and max into its associated float value' , ( ) =>
165
+ it ( 'should properly convert integer value for index between min and max into its associated float value' , ( ) => {
166
+ const withoutExcludedConstraints = {
167
+ ...defaultFloatRecordConstraints ,
168
+ minExcluded : fc . constant ( false ) ,
169
+ maxExcluded : fc . constant ( false ) ,
170
+ } ;
171
+
140
172
fc . assert (
141
173
fc . property (
142
- fc . option ( floatConstraints ( ) , { nil : undefined } ) ,
174
+ fc . option ( floatConstraints ( withoutExcludedConstraints ) , { nil : undefined } ) ,
143
175
fc . maxSafeNat ( ) ,
144
176
fc . option ( fc . integer ( { min : 2 } ) , { nil : undefined } ) ,
145
177
( ct , mod , biasFactor ) => {
@@ -159,7 +191,8 @@ describe('float', () => {
159
191
expect ( f ) . toBe ( indexToFloat ( arbitraryGeneratedIndex ) ) ;
160
192
}
161
193
)
162
- ) ) ;
194
+ ) ;
195
+ } ) ;
163
196
164
197
describe ( 'with NaN' , ( ) => {
165
198
const withNaNRecordConstraints = { ...defaultFloatRecordConstraints , noNaN : fc . constant ( false ) } ;
@@ -236,13 +269,15 @@ describe('float', () => {
236
269
const { min, max } = minMaxForConstraints ( ct ) ;
237
270
const minIndex = floatToIndex ( min ) ;
238
271
const maxIndex = floatToIndex ( max ) ;
272
+ const expectedMinIndex = ct . minExcluded ? minIndex + 1 : minIndex ;
273
+ const expectedMaxIndex = ct . maxExcluded ? maxIndex - 1 : maxIndex ;
239
274
240
275
// Act
241
276
float ( ct ) ;
242
277
243
278
// Assert
244
279
expect ( integer ) . toHaveBeenCalledTimes ( 1 ) ;
245
- expect ( integer ) . toHaveBeenCalledWith ( { min : minIndex , max : maxIndex } ) ;
280
+ expect ( integer ) . toHaveBeenCalledWith ( { min : expectedMinIndex , max : expectedMaxIndex } ) ;
246
281
} )
247
282
) ;
248
283
} ) ;
0 commit comments