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 { 16 computeIntervals, 17 performReordering, 18} from './dragndrop_logic'; 19 20describe('performReordering', () => { 21 test('has the same elements in the result', () => { 22 const arr = [1, 2, 3, 4, 5, 6]; 23 const arrSet = new Set(arr); 24 25 for (let i = 0; i < arr.length; i++) { 26 for (let j = 0; j < arr.length; j++) { 27 if (i === j) { 28 // The function has a precondition that two indices have to be 29 // different. 30 continue; 31 } 32 33 const permutedLeft = 34 performReordering(computeIntervals(arr.length, i, j, 'left'), arr); 35 expect(new Set(permutedLeft)).toEqual(arrSet); 36 expect(permutedLeft.length).toEqual(arr.length); 37 38 const permutedRight = 39 performReordering(computeIntervals(arr.length, i, j, 'right'), arr); 40 expect(new Set(permutedRight)).toEqual(arrSet); 41 expect(permutedRight.length).toEqual(arr.length); 42 } 43 } 44 }); 45}); 46