-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// import { GradeBands } from '../../GradeBands' | ||
import { Polish } from '../../scales' | ||
|
||
describe('Polish', () => { | ||
describe('isPolish', () => { | ||
test('VI', () => { | ||
expect(Polish.isType('VI')) | ||
}) | ||
}) | ||
// describe('Get Score', () => { | ||
// test('9a > 5c', () => { | ||
// const lowGrade = Polish.getScore('5c') | ||
// const highGrade = Polish.getScore('9a') | ||
// expect(highGrade[0]).toBeGreaterThan(lowGrade[1]) | ||
// }) | ||
|
||
// test('1c > 1a+', () => { | ||
// const highGrade = Polish.getScore('1c') | ||
// const lowGrade = Polish.getScore('1a+') | ||
// expect(highGrade[0]).toBeGreaterThan(lowGrade[1]) | ||
// }) | ||
|
||
// test('1a/1a+ > 1a, one grade away', () => { | ||
// const highGrade = Polish.getScore('1a/1a+') | ||
// const lowGrade = Polish.getScore('1a') | ||
// expect(highGrade[0] < lowGrade[1] && highGrade[0] > lowGrade[0]) | ||
// expect(highGrade[1]).toBeGreaterThan(lowGrade[1]) | ||
// }) | ||
|
||
// test('4a > 3c+/4a, one grade away', () => { | ||
// const highGrade = Polish.getScore('4a') | ||
// const lowGrade = Polish.getScore('3c+/4a') | ||
// expect(highGrade[0] < lowGrade[1] && highGrade[0] > lowGrade[0]) | ||
// expect(highGrade[1]).toBeGreaterThan(lowGrade[1]) | ||
// }) | ||
// }) | ||
|
||
// describe('invalid grade format', () => { | ||
// jest.spyOn(console, 'warn').mockImplementation() | ||
// beforeEach(() => { | ||
// jest.clearAllMocks() | ||
// }) | ||
// test('extra plus modifier', () => { | ||
// const invalidGrade = Polish.getScore('5a++') | ||
// expect(console.warn).toHaveBeenCalledWith('Unexpected grade format: 5a++ for grade scale polish') | ||
// expect(invalidGrade).toEqual(-1) | ||
// }) | ||
// test('invalid minus modifier', () => { | ||
// const invalidGrade = Polish.getScore('5a-') | ||
// expect(console.warn).toHaveBeenCalledWith('Unexpected grade format: 5a- for grade scale polish') | ||
// expect(invalidGrade).toEqual(-1) | ||
// }) | ||
// test('extra slash grade', () => { | ||
// const invalidGrade = Polish.getScore('5a/5a+/5b+') | ||
// expect(console.warn).toHaveBeenCalledWith('Unexpected grade format: 5a/5a+/5b+ for grade scale polish') | ||
// expect(invalidGrade).toEqual(-1) | ||
// }) | ||
// test('extra slash', () => { | ||
// const invalidGrade = Polish.getScore('5a/') | ||
// expect(console.warn).toHaveBeenCalledWith('Unexpected grade format: 5a/ for grade scale polish') | ||
// expect(invalidGrade).toEqual(-1) | ||
// }) | ||
// test('not Polish scale', () => { | ||
// const invalidGrade = Polish.getScore('v11') | ||
// expect(console.warn).toHaveBeenCalledWith('Unexpected grade format: v11 for grade scale polish') | ||
// expect(invalidGrade).toEqual(-1) | ||
// }) | ||
// }) | ||
|
||
// describe('Get Grade', () => { | ||
// test('bottom of range', () => { | ||
// expect(Polish.getGrade(0)).toBe('1a') | ||
// }) | ||
|
||
// test('top of range', () => { | ||
// expect(Polish.getGrade(1000)).toBe('9c+') | ||
// }) | ||
|
||
// test('single score provided', () => { | ||
// expect(Polish.getGrade(34)).toBe('3c+') | ||
// expect(Polish.getGrade(34.5)).toBe('3c+') | ||
// expect(Polish.getGrade(35)).toBe('3c+') | ||
// }) | ||
// test('range of scores provided', () => { | ||
// expect(Polish.getGrade([0.5, 2])).toBe('1a/1a+') | ||
// expect(Polish.getGrade([8, 12])).toBe('1c/2a') | ||
// expect(Polish.getGrade([16, 17])).toBe('2b') | ||
// }) | ||
// }) | ||
|
||
// describe('Get Grade Band', () => { | ||
// test('gets Gradeband', () => { | ||
// expect(Polish.getGradeBand('1a')).toEqual(GradeBands.BEGINNER) | ||
// expect(Polish.getGradeBand('9c+')).toEqual(GradeBands.EXPERT) | ||
// }) | ||
// }) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import GradeScale, { findScoreRange, getAvgScore, GradeScales, Tuple, getRoundedScoreTuple } from '../GradeScale' | ||
import routes from '../data/routes.json' | ||
import { Route } from '.' | ||
import { GradeBandTypes, routeScoreToBand } from '../GradeBands' | ||
|
||
// TODO: set this regexp | ||
const polishGradeRegex = /^([1-9][a-c][+]?){1}(?:(\/)([1-9][a-c][+]?))?$/i | ||
// Supports 1a -> 9c+, slash grades i.e. 5a/5a+ or 6a+/6b | ||
// NOTE: this currently assumes "incorrect" slash grades follows the normal pattern | ||
// i.e. 6b+/5a => 6b+/6c | ||
const isPolish = (grade: string): RegExpMatchArray | null => grade.match(polishGradeRegex) | ||
|
||
const PolishScale: GradeScale = { | ||
displayName: 'Polish Scale', | ||
name: GradeScales.POLISH, | ||
offset: 1000, | ||
allowableConversionType: [GradeScales.YDS, GradeScales.EWBANK, GradeScales.SAXON], | ||
isType: (grade: string): boolean => { | ||
if (isPolish(grade) === null) { | ||
return false | ||
} | ||
return true | ||
}, | ||
getScore: (grade: string): number | Tuple => { | ||
return getScore(grade) | ||
}, | ||
getGrade: (score: number | Tuple): string => { | ||
const validateScore = (score: number): number => { | ||
const validScore = Number.isInteger(score) ? score : Math.ceil(score) | ||
Check warning on line 29 in src/scales/polish.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 29 in src/scales/polish.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
|
||
return Math.min(Math.max(0, validScore), routes.length - 1) | ||
} | ||
|
||
if (typeof score === 'number') { | ||
return routes[validateScore(score)].polish | ||
} | ||
Check warning on line 35 in src/scales/polish.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
|
||
const low: string = routes[validateScore(score[0])].polish | ||
const high: string = routes[validateScore(score[1])].polish | ||
if (low === high) return low | ||
Check warning on line 39 in src/scales/polish.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 39 in src/scales/polish.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
return `${low}/${high}` | ||
}, | ||
getGradeBand: (grade: string): GradeBandTypes => { | ||
const score = getScore(grade) | ||
return routeScoreToBand(getAvgScore(score)) | ||
} | ||
} | ||
|
||
const getScore = (grade: string): number | Tuple => { | ||
const parse = isPolish(grade) | ||
if (parse == null) { | ||
console.warn(`Unexpected grade format: ${grade} for grade scale polish`) | ||
return -1 | ||
} | ||
Check warning on line 53 in src/scales/polish.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
const [wholeMatch, basicGrade, slash] = parse | ||
const basicScore = findScoreRange((r: Route) => { | ||
return r.polish === basicGrade | ||
}, routes) | ||
|
||
if (wholeMatch !== basicGrade) { | ||
// 5a/5a+ | ||
let otherGrade | ||
if (slash !== null) { | ||
otherGrade = (typeof basicScore === 'number' ? basicScore : basicScore[1]) + 1 | ||
Check warning on line 63 in src/scales/polish.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 63 in src/scales/polish.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
|
||
} | ||
Check warning on line 64 in src/scales/polish.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
if (otherGrade !== undefined) { | ||
const nextGrade = findScoreRange( | ||
(r: Route) => r.polish.toLowerCase() === routes[otherGrade].polish.toLowerCase(), | ||
routes | ||
) | ||
const basicAvg = getAvgScore(basicScore) | ||
const nextGradeAvg = getAvgScore(nextGrade) | ||
const tuple = getRoundedScoreTuple(basicAvg, nextGradeAvg) | ||
return tuple | ||
} | ||
Check warning on line 74 in src/scales/polish.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
} | ||
Check warning on line 75 in src/scales/polish.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
return basicScore | ||
} | ||
|
||
export default PolishScale |