• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2023 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 {allUnique, range} from './array_utils';
16
17describe('range', () => {
18  it('returns array of elements in range [0; n)', () => {
19    expect(range(3)).toEqual([0, 1, 2]);
20    expect(range(5)).toEqual([0, 1, 2, 3, 4]);
21  });
22
23  it('returns empty array on n = 0', () => {
24    expect(range(0)).toEqual([]);
25  });
26
27  it('throws an error on negative input', () => {
28    expect(() => {
29      range(-10);
30    }).toThrowError();
31  });
32});
33
34describe('allUnique', () => {
35  it('returns true on array with unique elements', () => {
36    expect(allUnique(['a', 'b', 'c'])).toBeTruthy();
37  });
38
39  it('returns false on array with repeated elements', () => {
40    expect(allUnique(['a', 'a', 'b'])).toBeFalsy();
41  });
42
43  // Couple of corner cases
44  it('returns true on an empty array', () => {
45    expect(allUnique([])).toBeTruthy();
46  });
47
48  it('returns true on an array with one element', () => {
49    expect(allUnique(['test'])).toBeTruthy();
50  });
51});
52