test.music.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import test from 'ava'
  2. import Chance from '../chance.js'
  3. import _ from 'lodash'
  4. const chance = new Chance()
  5. // chance.note()
  6. test('note() returns a valid note', t => {
  7. _.times(1000, () => {
  8. let note = chance.note()
  9. t.true(_.isString(note))
  10. t.true(note.length <= 2)
  11. })
  12. })
  13. // chance.midi_note()
  14. test('midi_note() returns a valid midi note between 0 and 127', t => {
  15. _.times(1000, () => {
  16. let midi_note = chance.midi_note()
  17. t.true(_.isNumber(midi_note))
  18. t.true(midi_note >= 0)
  19. t.true(midi_note <= 127)
  20. })
  21. })
  22. // chance.chord_quality()
  23. test('chord_quality() returns a valid chord quality', t => {
  24. _.times(1000, () => {
  25. let chord_quality = chance.chord_quality()
  26. t.true(_.isString(chord_quality))
  27. t.true(chord_quality.length <= 4)
  28. })
  29. })
  30. // chance.chord()
  31. test('chord() returns a valid chord', t => {
  32. _.times(1000, () => {
  33. let chord = chance.chord()
  34. t.true(_.isString(chord))
  35. t.true(chord.length <= 6)
  36. })
  37. })
  38. // chance.tempo()
  39. test('tempo() returns a valid tempo between 40 and 320', t => {
  40. _.times(1000, () => {
  41. let tempo = chance.tempo()
  42. t.true(_.isNumber(tempo))
  43. t.true(tempo >= 40)
  44. t.true(tempo <= 320)
  45. })
  46. })