Simple monitor for displaying MIDI status for digital pianos.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

65 lines
1.7 KiB

  1. import * as fc from 'fast-check'
  2. import isNaturalKey from './isNaturalKey'
  3. it('should exist', () => {
  4. expect(isNaturalKey).toBeDefined()
  5. })
  6. it('should be a callable', () => {
  7. expect(typeof isNaturalKey).toBe('function')
  8. })
  9. it('should accept 1 parameter', () => {
  10. expect(isNaturalKey).toHaveLength(1)
  11. })
  12. it('should throw TypeError upon passing invalid types', () => {
  13. fc.assert(
  14. fc.property(
  15. fc.anything().filter((anything) => typeof anything !== 'number'),
  16. (anything) => {
  17. expect(() => isNaturalKey(anything as number)).toThrowError(TypeError)
  18. },
  19. ),
  20. )
  21. })
  22. it('should throw RangeError upon passing NaN', () => {
  23. expect(() => isNaturalKey(NaN)).toThrowError(RangeError)
  24. })
  25. it('should throw RangeError upon passing negative numbers', () => {
  26. fc.assert(
  27. fc.property(
  28. fc.anything().filter((anything) => typeof anything! === 'number' && !isNaN(anything) && anything < 0),
  29. (negativeValue) => {
  30. expect(() => isNaturalKey(negativeValue as number)).toThrowError(RangeError)
  31. },
  32. ),
  33. )
  34. })
  35. describe('upon passing a positive number or zero', () => {
  36. it('should not throw any error', () => {
  37. fc.assert(
  38. fc.property(
  39. fc.anything().filter((anything) => typeof anything! === 'number' && !isNaN(anything) && anything >= 0),
  40. (value) => {
  41. expect(() => isNaturalKey(value as number)).not.toThrow()
  42. },
  43. ),
  44. )
  45. })
  46. it('should return a boolean', () => {
  47. fc.assert(
  48. fc.property(
  49. fc.anything().filter((anything) => typeof anything! === 'number' && !isNaN(anything) && anything >= 0),
  50. (value) => {
  51. expect(typeof isNaturalKey(value as number)).toBe('boolean')
  52. },
  53. ),
  54. )
  55. })
  56. })