optimize transpose service
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
|
||||
import {TransposeService} from './transpose.service';
|
||||
import {LineType} from './line-type';
|
||||
import {Line} from './line';
|
||||
|
||||
describe('TransposeService', () => {
|
||||
let service: TransposeService;
|
||||
@@ -12,7 +14,7 @@ describe('TransposeService', () => {
|
||||
|
||||
it('should create map upwards', () => {
|
||||
const distance = service.getDistance('D', 'G');
|
||||
const map = service.getMap('D', distance);
|
||||
const map = service.getMap('D', 'G', distance);
|
||||
|
||||
if (map) {
|
||||
void expect(map['D']).toBe('G');
|
||||
@@ -21,10 +23,71 @@ describe('TransposeService', () => {
|
||||
|
||||
it('should create map downwards', () => {
|
||||
const distance = service.getDistance('G', 'D');
|
||||
const map = service.getMap('G', distance);
|
||||
const map = service.getMap('G', 'D', distance);
|
||||
|
||||
if (map) {
|
||||
void expect(map['G']).toBe('D');
|
||||
}
|
||||
});
|
||||
|
||||
it('should transpose enharmonic targets by semitone distance', () => {
|
||||
const distance = service.getDistance('C', 'Db');
|
||||
const map = service.getMap('C', 'Db', distance);
|
||||
|
||||
expect(distance).toBe(1);
|
||||
expect(map?.['C']).toBe('Db');
|
||||
expect(map?.['G']).toBe('Ab');
|
||||
});
|
||||
|
||||
it('should keep german B/H notation consistent', () => {
|
||||
const distance = service.getDistance('H', 'C');
|
||||
const map = service.getMap('H', 'C', distance);
|
||||
|
||||
expect(distance).toBe(1);
|
||||
expect(map?.['H']).toBe('C');
|
||||
expect(map?.['B']).toBe('C#');
|
||||
});
|
||||
|
||||
it('should render unknown chords as X', () => {
|
||||
const line: Line = {
|
||||
type: LineType.chord,
|
||||
text: '',
|
||||
chords: [
|
||||
{chord: 'Q', add: 'sus4', slashChord: null, position: 0, length: 1},
|
||||
],
|
||||
};
|
||||
|
||||
const rendered = service.renderChords(line);
|
||||
|
||||
expect(rendered.text).toBe('Xsus4');
|
||||
});
|
||||
|
||||
it('should render unknown slash chords as X', () => {
|
||||
const line: Line = {
|
||||
type: LineType.chord,
|
||||
text: '',
|
||||
chords: [
|
||||
{chord: 'C', add: null, slashChord: 'Q', position: 0, length: 1},
|
||||
],
|
||||
};
|
||||
|
||||
const rendered = service.renderChords(line);
|
||||
|
||||
expect(rendered.text).toBe('C/X');
|
||||
});
|
||||
|
||||
it('should transpose lines with long chord positions without truncating', () => {
|
||||
const line: Line = {
|
||||
type: LineType.chord,
|
||||
text: '',
|
||||
chords: [
|
||||
{chord: 'C', add: null, slashChord: null, position: 120, length: 1},
|
||||
],
|
||||
};
|
||||
|
||||
const rendered = service.renderChords(line);
|
||||
|
||||
expect(rendered.text.length).toBe(121);
|
||||
expect(rendered.text.endsWith('C')).toBeTrue();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user