jevstrudel.git / packages / core / test / drawLine.test.mjs

drawLine.test.mjs - <short description TODO> Copyright (C) 2022 Strudel contributors - see https://codeberg.org/uzu/strudel/src/branch/main/packages/core/test/drawLine.test.mjs This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

7import { fastcat, stack, slowcat, silence, pure } from '../pattern.mjs';
8import { describe, it, expect } from 'vitest';
9import drawLine from '../drawLine.mjs';
11describe('drawLine', () => {
12  it('supports equal lengths', () => {
13    expect(drawLine(fastcat(0), 4)).toEqual('|0|0');
14    expect(drawLine(fastcat(0, 1), 4)).toEqual('|01|01');
15    expect(drawLine(fastcat(0, 1, 2), 6)).toEqual('|012|012');
16  });
17  it('supports unequal lengths', () => {
18    expect(drawLine(fastcat(0, [1, 2]), 10)).toEqual('|0-12|0-12');
19    expect(drawLine(fastcat(0, [1, 2, 3]), 10)).toEqual('|0--123|0--123');
20    expect(drawLine(fastcat(0, 1, [2, 3]), 10)).toEqual('|0-1-23|0-1-23');
21  });
22  it('supports unequal silence', () => {
23    expect(drawLine(fastcat(0, silence, [1, 2]), 10)).toEqual('|0-..12|0-..12');
24  });
25  it('supports polyrhythms', () => {
26    // assert.equal(drawLine(fastcat(pure(0).fast(2), pure(1).fast(3)), 10), '|0--0--1-1-1-');
27    expect(drawLine(fastcat(pure(0).fast(2), pure(1).fast(3)), 10)).toEqual('|0--0--1-1-1-');
28  });
29  it('supports multiple lines', () => {
30    expect(drawLine(fastcat(0, stack(1, 2)), 10)).toEqual(`|01|01|01|01
31|.2|.2|.2|.2`);
32
33    expect(drawLine(fastcat(0, 1, stack(2, 3)), 10)).toEqual(`|012|012|012
34|..3|..3|..3`);
35
36    expect(drawLine(fastcat(0, stack(1, 2, 3)), 10)).toEqual(`|01|01|01|01
37|.2|.2|.2|.2
38|.3|.3|.3|.3`);
39    expect(drawLine(fastcat(0, 1, stack(2, 3, 4)), 10)).toEqual(`|012|012|012
40|..3|..3|..3
41|..4|..4|..4`);
42  });
43  it('supports unequal cycle lengths', () => {
44    expect(drawLine(slowcat(0, [1, 2]), 10)).toEqual(`|0|12|0|12`);
45  });
46});