From 1d84562f77c3b1746e32cc8e9db04361758727da Mon Sep 17 00:00:00 2001 From: Gabriel Allegretti Date: Thu, 28 Jul 2022 21:58:39 -0300 Subject: [PATCH 1/2] Fix beat removeNote function keeping stringLookup reference --- src/model/Beat.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/model/Beat.ts b/src/model/Beat.ts index 0c1866dd9..9ec08724b 100644 --- a/src/model/Beat.ts +++ b/src/model/Beat.ts @@ -502,6 +502,9 @@ export class Beat { let index: number = this.notes.indexOf(note); if (index >= 0) { this.notes.splice(index, 1); + if (note.isStringed) { + this.noteStringLookup.delete(note.string); + } } } From 5b40856356d4f4bdedf0168358715434f356b52b Mon Sep 17 00:00:00 2001 From: Gabriel Allegretti Date: Sat, 27 Aug 2022 19:31:14 -0300 Subject: [PATCH 2/2] Add tests for Beat --- test/model/Beat.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/model/Beat.test.ts diff --git a/test/model/Beat.test.ts b/test/model/Beat.test.ts new file mode 100644 index 000000000..203acc057 --- /dev/null +++ b/test/model/Beat.test.ts @@ -0,0 +1,25 @@ +import { Note } from '@src/model'; +import { Beat } from '@src/model/Beat'; + +describe('BeatTests', () => { + it('add-stringed-note', () => { + const beat = new Beat(); + const note = new Note(); + note.string = 2; + beat.addNote(note); + expect(beat.notes.length).toBe(1); + expect(beat.hasNoteOnString(2)).toBe(true); + expect(beat.getNoteOnString(2)).toBe(note); + }); + + it('remove-stringed-note', () => { + const beat = new Beat(); + const note = new Note(); + note.string = 1; + beat.addNote(note); + beat.removeNote(note); + expect(beat.notes.length).toBe(0); + expect(beat.hasNoteOnString(2)).toBe(false); + expect(beat.getNoteOnString(2)).toBe(null); + }); +}); \ No newline at end of file