From 283a071c8609960e6d2bf6799265e81035c7c134 Mon Sep 17 00:00:00 2001 From: Alex McLean Date: Tue, 18 Jun 2024 22:58:08 +0100 Subject: [PATCH] Fix bug in Fraction.lcm (#1133) * bugfix lcm --- packages/core/fraction.mjs | 4 ++-- packages/core/test/pattern.test.mjs | 36 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/packages/core/fraction.mjs b/packages/core/fraction.mjs index a339567f..dc7fe27a 100644 --- a/packages/core/fraction.mjs +++ b/packages/core/fraction.mjs @@ -119,10 +119,10 @@ export const lcm = (...fractions) => { if (fractions.length === 0) { return undefined; } - + const x = fractions.pop(); return fractions.reduce( (lcm, fraction) => (lcm === undefined || fraction === undefined ? undefined : lcm.lcm(fraction)), - fraction(1), + x, ); }; diff --git a/packages/core/test/pattern.test.mjs b/packages/core/test/pattern.test.mjs index 845ed00a..c8129b5c 100644 --- a/packages/core/test/pattern.test.mjs +++ b/packages/core/test/pattern.test.mjs @@ -1209,4 +1209,40 @@ describe('Pattern', () => { } }); }); + describe('s_expand', () => { + it('can expand four things in half', () => { + expect( + sameFirst( + sequence(0, 1, 2, 3).s_expand(1, 0.5), + s_cat(sequence(0, 1, 2, 3), sequence(0, 1, 2, 3).s_expand(0.5)), + ), + ); + }); + it('can expand five things in half', () => { + expect( + sameFirst( + sequence(0, 1, 2, 3, 4).s_expand(1, 0.5), + s_cat(sequence(0, 1, 2, 3, 4), sequence(0, 1, 2, 3, 4).s_expand(0.5)), + ), + ); + }); + }); + describe('stepJoin', () => { + it('can join a pattern with a tactus of 2', () => { + expect( + sameFirst( + sequence(pure(pure('a')), pure(pure('b').setTactus(2))).stepJoin(), + s_cat(pure('a'), pure('b').setTactus(2)), + ), + ); + }); + it('can join a pattern with a tactus of 0.5', () => { + expect( + sameFirst( + sequence(pure(pure('a')), pure(pure('b').setTactus(0.5))).stepJoin(), + s_cat(pure('a'), pure('b').setTactus(0.5)), + ), + ); + }); + }); });