Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/scales/__tests__/saxon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Saxon as SaxonScale } from '../../scales'

describe('SAXON', () => {
describe('valid grade formats', () => {
let consoleWarnSpy

beforeEach(() => {
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation()
})

afterEach(() => {
consoleWarnSpy.mockRestore()
})

test('should handle valid grade format "1"', () => {
const score = SaxonScale.getScore('1')
expect(console.warn).not.toHaveBeenCalled()
expect(score).not.toEqual(-1)
})
})

describe('isType', () => {
test('should return true for valid grade format "7a"', () => {
const isValid = SaxonScale.isType('7a')
expect(isValid).toBe(true)
})

test('should return true for valid grade format "1"', () => {
const isValid = SaxonScale.isType('1')
expect(isValid).toBe(true)
})

test('should return false for invalid grade format "V"', () => {
const isValid = SaxonScale.isType('V')
expect(isValid).toBe(false)
})

test('should return false for invalid grade format "8d"', () => {
const isValid = SaxonScale.isType('8d')
expect(isValid).toBe(false)
})
})

describe('getScore', () => {
test('should handle grade format with slash "7a/7b"', () => {
const score = SaxonScale.getScore('7a/7b')
expect(score).not.toEqual(-1)
})
})
})
2 changes: 1 addition & 1 deletion src/scales/saxon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import routes from '../data/routes.json'
import { Route } from '.'
import { GradeBandTypes, routeScoreToBand } from '../GradeBands'

const saxonGradeRegex = /^((([7-9]|1[0-3])([a-c]))|([1-6]))$/i
const saxonGradeRegex = /^((([7-9]|1[0-3])([a-c]))|([1-6])|([7-9]|1[0-3])(([a-c])\/([7-9]|1[0-3])([a-c])))$/i
// Saxon grading system, predominant in Central Europe (esp. Germany, Austria, Switzerland)
// Supports 1 -> 13c, slash grades i.e. 7a/7b
// Uses Arabic numerals with letters from a-c, e.g. "7a" , "7b", or "7c" (hardest)
Expand Down