Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanButton committed Sep 9, 2022
1 parent 8d4bcd1 commit 724b8b2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
54 changes: 52 additions & 2 deletions packages/react-guitar-fretter/src/__test__/fretter.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,65 @@
import fretter from '../'
import fretter, { toSemitones } from '../'

const toSemitones = (text: string) => text.split('').map((c) => c === '1')
describe('toSemitones()', () => {
it(`maps correctly`, () =>
// prettier-ignore
expect(
toSemitones('01010101010')
).toEqual([false, true, false, true, false, true, false, true, false, true, false]))
})

describe('fretter()', () => {
it(`frets C major`, () =>
expect(
fretter({ root: 0, semitones: toSemitones('00010010000') })[0]
).toEqual([0, 1, 0, 2, 3, -1]))

it(`frets C major barre`, () =>
expect(
fretter(
{
root: 0,
semitones: toSemitones('00010010000'),
},
{ restrictChordTypeTo: 'barre' }
)[0]
).toEqual([3, 5, 5, 5, 3, -1]))

it(`frets C major open`, () =>
expect(
fretter(
{
root: 0,
semitones: toSemitones('00010010000'),
},
{ restrictChordTypeTo: 'open' }
)[0]
).toEqual([0, 1, 0, 2, 3, -1]))

it(`frets A minor`, () =>
expect(
fretter({ root: 9, semitones: toSemitones('00100010000') })[0]
).toEqual([0, 1, 2, 2, 0, -1]))

it(`frets A minor barre`, () =>
expect(
fretter(
{
root: 9,
semitones: toSemitones('00100010000'),
},
{ restrictChordTypeTo: 'barre' }
)[0]
).toEqual([5, 5, 5, 7, 7, 5]))

it(`frets A minor open`, () =>
expect(
fretter(
{
root: 9,
semitones: toSemitones('00100010000'),
},
{ restrictChordTypeTo: 'open' }
)[0]
).toEqual([0, 1, 2, 2, 0, -1]))
})
6 changes: 3 additions & 3 deletions packages/react-guitar-fretter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function fretter(
options?: {
tuning?: number[]
frets?: number
restrictChordTypeTo?: 'open' | 'barre' | 'all'
restrictChordTypeTo?: 'open' | 'barre'
}
): number[][] {
const { root, semitones } = chord
Expand Down Expand Up @@ -106,8 +106,8 @@ export default function fretter(
fretting.length === 0
? flatten(
reverse(range(tuning.length))
.map((string) => getFrets(string, [root]))
.map((frets, i) =>
.map((string: number) => getFrets(string, [root]))
.map((frets: any[], i: number) =>
frets.map((fret) =>
range(i + 1).map((j) => (j !== i ? -1 : fret))
)
Expand Down

0 comments on commit 724b8b2

Please sign in to comment.