@@ -141,6 +141,90 @@ describe("addQuantities", () => {
141141 } ) ;
142142 } ) ;
143143
144+ it ( "should also work when at least one value is a range" , ( ) => {
145+ expect (
146+ addQuantities (
147+ {
148+ value : {
149+ type : "range" ,
150+ min : { type : "decimal" , value : 100 } ,
151+ max : { type : "decimal" , value : 200 } ,
152+ } ,
153+ unit : "g" ,
154+ } ,
155+ {
156+ value : {
157+ type : "range" ,
158+ min : { type : "decimal" , value : 10 } ,
159+ max : { type : "decimal" , value : 20 } ,
160+ } ,
161+ unit : "g" ,
162+ } ,
163+ ) ,
164+ ) . toEqual ( {
165+ value : {
166+ type : "range" ,
167+ min : { type : "decimal" , value : 110 } ,
168+ max : { type : "decimal" , value : 220 } ,
169+ } ,
170+ unit : "g" ,
171+ } ) ;
172+
173+ expect (
174+ addQuantities (
175+ {
176+ value : {
177+ type : "fixed" ,
178+ value : { type : "decimal" , value : 100 } ,
179+ } ,
180+ unit : "g" ,
181+ } ,
182+ {
183+ value : {
184+ type : "range" ,
185+ min : { type : "decimal" , value : 10 } ,
186+ max : { type : "decimal" , value : 20 } ,
187+ } ,
188+ unit : "g" ,
189+ } ,
190+ ) ,
191+ ) . toEqual ( {
192+ value : {
193+ type : "range" ,
194+ min : { type : "decimal" , value : 110 } ,
195+ max : { type : "decimal" , value : 120 } ,
196+ } ,
197+ unit : "g" ,
198+ } ) ;
199+
200+ expect (
201+ addQuantities (
202+ {
203+ value : {
204+ type : "range" ,
205+ min : { type : "decimal" , value : 10 } ,
206+ max : { type : "decimal" , value : 20 } ,
207+ } ,
208+ unit : "g" ,
209+ } ,
210+ {
211+ value : {
212+ type : "fixed" ,
213+ value : { type : "decimal" , value : 100 } ,
214+ } ,
215+ unit : "g" ,
216+ } ,
217+ ) ,
218+ ) . toEqual ( {
219+ value : {
220+ type : "range" ,
221+ min : { type : "decimal" , value : 110 } ,
222+ max : { type : "decimal" , value : 120 } ,
223+ } ,
224+ unit : "g" ,
225+ } ) ;
226+ } ) ;
227+
144228 it ( "should add compatible metric units and convert to largest" , ( ) => {
145229 expect (
146230 addQuantities (
@@ -271,6 +355,18 @@ describe("addQuantities", () => {
271355 } ,
272356 ) ,
273357 ) . toThrow ( IncompatibleUnitsError ) ;
358+ expect ( ( ) =>
359+ addQuantities (
360+ {
361+ value : { type : "fixed" , value : { type : "decimal" , value : 100 } } ,
362+ unit : "g" ,
363+ } ,
364+ {
365+ value : { type : "fixed" , value : { type : "decimal" , value : 1 } } ,
366+ unit : "bag" ,
367+ } ,
368+ ) ,
369+ ) . toThrow ( IncompatibleUnitsError ) ;
274370 } ) ;
275371
276372 it ( "should add quantities defined as ranges" , ( ) => {
0 commit comments