|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2019 Google LLC. All Rights Reserved. |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * ============================================================================= |
| 16 | + */ |
| 17 | + |
| 18 | +import {padSequences} from "./sequence_utils"; |
| 19 | + |
| 20 | +describe('padSequences', () => { |
| 21 | + it('post pad, post truncate', () => { |
| 22 | + const sequences = [[10, 20, 30], [5, 15], [], [1, 2, 3, 4, 5, 6]]; |
| 23 | + const output = padSequences(sequences, 4, 'post', 'post'); |
| 24 | + expect(output).toEqual( |
| 25 | + [[10, 20, 30, 0], [5, 15, 0, 0], [0, 0, 0, 0], [1, 2, 3, 4]]); |
| 26 | + }); |
| 27 | + |
| 28 | + it('post pad, pre trucnate', () => { |
| 29 | + const sequences = [[10, 20, 30], [5, 15], [], [1, 2, 3, 4, 5, 6]]; |
| 30 | + const output = padSequences(sequences, 4, 'post', 'pre'); |
| 31 | + expect(output).toEqual( |
| 32 | + [[10, 20, 30, 0], [5, 15, 0, 0], [0, 0, 0, 0], [3, 4, 5, 6]]); |
| 33 | + }); |
| 34 | + |
| 35 | + it('pre pad, post trucnate', () => { |
| 36 | + const sequences = [[10, 20, 30], [5, 15], [], [1, 2, 3, 4, 5, 6]]; |
| 37 | + const output = padSequences(sequences, 4, 'pre', 'post'); |
| 38 | + expect(output).toEqual( |
| 39 | + [[0, 10, 20, 30], [0, 0, 5, 15], [0, 0, 0, 0], [1, 2, 3, 4]]); |
| 40 | + }); |
| 41 | + |
| 42 | + it('pre pad, pre trucnate', () => { |
| 43 | + const sequences = [[10, 20, 30], [5, 15], [], [1, 2, 3, 4, 5, 6]]; |
| 44 | + const output = padSequences(sequences, 4, 'pre', 'pre'); |
| 45 | + expect(output).toEqual( |
| 46 | + [[0, 10, 20, 30], [0, 0, 5, 15], [0, 0, 0, 0], [3, 4, 5, 6]]); |
| 47 | + }); |
| 48 | + |
| 49 | + it('custom padding character', () => { |
| 50 | + const sequences = [[10, 20, 30], [5, 15], [], [1, 2, 3, 4, 5, 6]]; |
| 51 | + const output = padSequences(sequences, 4, 'pre', 'pre', 42); |
| 52 | + expect(output).toEqual( |
| 53 | + [[42, 10, 20, 30], [42, 42, 5, 15], [42, 42, 42, 42], [3, 4, 5, 6]]); |
| 54 | + }); |
| 55 | +}); |
0 commit comments