@@ -249,6 +249,55 @@ describe('services/WindowStates', () => {
249249 expect ( result ?. windowSelection ) . to . eq ( WindowSelection . LEFT )
250250 } )
251251
252+ it ( 'getBestMatchingDeliveryWindow-skips5thFloorWithSingleFlower' , ( ) => {
253+ const dw = WindowStates . fromPersistence ( [
254+ { floor : 5 , windowSelection : WindowSelection . LEFT , flowers : [ Flower . ORANGE , Flower . BLUE , Flower . YELLOW , Flower . PURPLE , Flower . RED ] , deliveries : [ ] } ,
255+ { floor : 2 , windowSelection : WindowSelection . LEFT , flowers : [ Flower . RED , Flower . BLUE ] , deliveries : [ ] }
256+ ] )
257+
258+ // only 1 flower → 5th floor should be skipped, picks floor 2
259+ const result = dw . getBestMatchingDeliveryWindow ( [ Flower . RED ] )
260+
261+ expect ( result ?. floor ) . to . eq ( 2 )
262+ expect ( result ?. windowSelection ) . to . eq ( WindowSelection . LEFT )
263+ } )
264+
265+ it ( 'getBestMatchingDeliveryWindow-allows5thFloorWithTwoFlowers' , ( ) => {
266+ const dw = WindowStates . fromPersistence ( [
267+ { floor : 5 , windowSelection : WindowSelection . LEFT , flowers : [ Flower . ORANGE , Flower . BLUE , Flower . YELLOW , Flower . PURPLE , Flower . RED ] , deliveries : [ ] } ,
268+ { floor : 2 , windowSelection : WindowSelection . LEFT , flowers : [ Flower . RED , Flower . BLUE ] , deliveries : [ ] }
269+ ] )
270+
271+ // 2 flowers → 5th floor is allowed, both match 2, floor 2 has 0 missing vs floor 5 has 3 missing → floor 2 wins
272+ const result = dw . getBestMatchingDeliveryWindow ( [ Flower . RED , Flower . BLUE ] )
273+
274+ expect ( result ?. floor ) . to . eq ( 2 )
275+ expect ( result ?. windowSelection ) . to . eq ( WindowSelection . LEFT )
276+ } )
277+
278+ it ( 'getBestMatchingDeliveryWindow-skips5thFloorWithSingleFlower-noOtherWindows' , ( ) => {
279+ const dw = WindowStates . fromPersistence ( [
280+ { floor : 5 , windowSelection : WindowSelection . LEFT , flowers : [ Flower . ORANGE , Flower . BLUE , Flower . YELLOW , Flower . PURPLE , Flower . RED ] , deliveries : [ ] }
281+ ] )
282+
283+ // only 1 flower and only 5th floor available → no match
284+ const result = dw . getBestMatchingDeliveryWindow ( [ Flower . RED ] )
285+
286+ expect ( result ) . to . be . undefined
287+ } )
288+
289+ it ( 'getBestMatchingDeliveryWindow-allows5thFloorWithTwoFlowers-only5thFloor' , ( ) => {
290+ const dw = WindowStates . fromPersistence ( [
291+ { floor : 5 , windowSelection : WindowSelection . LEFT , flowers : [ Flower . ORANGE , Flower . BLUE , Flower . YELLOW , Flower . PURPLE , Flower . RED ] , deliveries : [ ] }
292+ ] )
293+
294+ // 2 flowers and only 5th floor → 5th floor is allowed
295+ const result = dw . getBestMatchingDeliveryWindow ( [ Flower . RED , Flower . BLUE ] )
296+
297+ expect ( result ?. floor ) . to . eq ( 5 )
298+ expect ( result ?. windowSelection ) . to . eq ( WindowSelection . LEFT )
299+ } )
300+
252301 it ( 'getBestMatchingUndefinedWindow-picksHighestUndefined' , ( ) => {
253302 // only floor 5 left is defined, all others undefined
254303 const dw = WindowStates . new ( )
0 commit comments