1// Copyright (C) 2022 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import {computeIntervals, performReordering} from './dragndrop_logic'; 16 17describe('performReordering', () => { 18 test('has the same elements in the result', () => { 19 const arr = [1, 2, 3, 4, 5, 6]; 20 const arrSet = new Set(arr); 21 22 for (let i = 0; i < arr.length; i++) { 23 for (let j = 0; j < arr.length; j++) { 24 if (i === j) { 25 // The function has a precondition that two indices have to be 26 // different. 27 continue; 28 } 29 30 const permutedLeft = performReordering( 31 computeIntervals(arr.length, i, j, 'left'), 32 arr, 33 ); 34 expect(new Set(permutedLeft)).toEqual(arrSet); 35 expect(permutedLeft.length).toEqual(arr.length); 36 37 const permutedRight = performReordering( 38 computeIntervals(arr.length, i, j, 'right'), 39 arr, 40 ); 41 expect(new Set(permutedRight)).toEqual(arrSet); 42 expect(permutedRight.length).toEqual(arr.length); 43 } 44 } 45 }); 46}); 47