.defragmentHaps() (#299)

This commit is contained in:
Alex McLean 2022-12-11 23:21:53 +00:00 committed by GitHub
parent c5083b2aef
commit 56424d29a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 0 deletions

View file

@ -915,4 +915,22 @@ describe('Pattern', () => {
expect(sequence(1, 2).add.squeeze(4, 5).firstCycle()).toStrictEqual(sequence(5, 6, 6, 7).firstCycle());
});
});
describe('defragmentHaps', () => {
it('Can merge two touching haps with same whole and value', () => {
expect(stack(pure('a').mask(1,0), pure('a').mask(0,1)).defragmentHaps().firstCycle().length)
.toStrictEqual(1);
});
it('Doesnt merge two overlapping haps', () => {
expect(stack(pure('a').mask(1,1,0), pure('a').mask(0,1)).defragmentHaps().firstCycle().length)
.toStrictEqual(2);
});
it('Doesnt merge two touching haps with different values', () => {
expect(stack(pure('a').mask(1,0), pure('b').mask(0,1)).defragmentHaps().firstCycle().length)
.toStrictEqual(2);
});
it('Doesnt merge two touching haps with different wholes', () => {
expect(stack(sequence('a', silence), pure('a').mask(0,1)).defragmentHaps().firstCycle().length)
.toStrictEqual(2);
});
});
});