1import { bjorklund } from '../euclid.mjs'; 2import { describe, expect, it } from 'vitest'; 3import { fastcat } from '../pattern.mjs'; 4 5describe('bjorklund', () => { 6 it('should apply bjorklundlund to ons and steps', () => { 7 expect(bjorklund(3, 8)).toStrictEqual([1, 0, 0, 1, 0, 0, 1, 0]); 8 expect(bjorklund(-3, 8)).toStrictEqual([0, 1, 1, 0, 1, 1, 0, 1]); 9 expect(bjorklund(8, 8)).toStrictEqual([1, 1, 1, 1, 1, 1, 1, 1]); 10 expect(bjorklund(-8, 8)).toStrictEqual([0, 0, 0, 0, 0, 0, 0, 0]); 11 expect(bjorklund(5, 8)).toStrictEqual([1, 0, 1, 1, 0, 1, 1, 0]); 12 }); 13}); 14 15describe('euclid', () => { 16 it('Can create euclid', () => { 17 expect( 18 fastcat('a') 19 .euclid(3, 8) 20 .firstCycle() 21 .sort((a, b) => a.part.begin.sub(b.part.begin)) 22 .map((a) => a.showWhole(true)), 23 ).toStrictEqual(['0/1 → 1/8: a', '3/8 → 1/2: a', '3/4 → 7/8: a']); 24 expect( 25 fastcat('a') 26 .euclid(5, 8) 27 .firstCycle() 28 .sort((a, b) => a.part.begin.sub(b.part.begin)) 29 .map((a) => a.showWhole(true)), 30 ).toStrictEqual(['0/1 → 1/8: a', '1/4 → 3/8: a', '3/8 → 1/2: a', '5/8 → 3/4: a', '3/4 → 7/8: a']); 31 }); 32}); 33 34describe('euclidRot', () => { 35 it('Can create euclidRot', () => { 36 expect( 37 fastcat('a') 38 .euclidRot(3, 8, 2) 39 .firstCycle() 40 .sort((a, b) => a.part.begin.sub(b.part.begin)) 41 .map((a) => a.showWhole(true)), 42 ).toStrictEqual(['0/1 → 1/8: a', '1/4 → 3/8: a', '5/8 → 3/4: a']); 43 expect( 44 fastcat('a') 45 .euclidRot(5, 8, 2) 46 .firstCycle() 47 .sort((a, b) => a.part.begin.sub(b.part.begin)) 48 .map((a) => a.showWhole(true)), 49 ).toStrictEqual(['0/1 → 1/8: a', '1/4 → 3/8: a', '1/2 → 5/8: a', '5/8 → 3/4: a', '7/8 → 1/1: a']); 50 }); 51}); 52 53describe('euclidLegato', () => { 54 it('Can create euclidLegato', () => { 55 expect( 56 fastcat('a') 57 .euclidLegato(3, 8) 58 .firstCycle() 59 .sort((a, b) => a.part.begin.sub(b.part.begin)) 60 .map((a) => a.showWhole(true)), 61 ).toStrictEqual(['0/1 → 3/8: a', '3/8 → 3/4: a', '3/4 → 1/1: a']); 62 expect( 63 fastcat('a') 64 .euclidLegato(5, 8) 65 .firstCycle() 66 .sort((a, b) => a.part.begin.sub(b.part.begin)) 67 .map((a) => a.showWhole(true)), 68 ).toStrictEqual(['0/1 → 1/4: a', '1/4 → 3/8: a', '3/8 → 5/8: a', '5/8 → 3/4: a', '3/4 → 1/1: a']); 69 }); 70}); 71 72describe('euclidLegatoRot', () => { 73 it('Can create euclidLegatoRot', () => { 74 expect( 75 fastcat('a') 76 .euclidLegatoRot(3, 8, 2) 77 .firstCycle() 78 .sort((a, b) => a.part.begin.sub(b.part.begin)) 79 .map((a) => a.showWhole(true)), 80 ).toStrictEqual(['0/1 → 1/4: a', '1/4 → 5/8: a', '5/8 → 1/1: a']); 81 expect( 82 fastcat('a') 83 .euclidLegatoRot(5, 8, 2) 84 .firstCycle() 85 .sort((a, b) => a.part.begin.sub(b.part.begin)) 86 .map((a) => a.showWhole(true)), 87 ).toStrictEqual(['0/1 → 1/4: a', '1/4 → 1/2: a', '1/2 → 5/8: a', '5/8 → 7/8: a', '7/8 → 1/1: a']); 88 }); 89});