1 | import test from 'ava'
|
2 | import Chance from '../chance.js'
|
3 | import _ from 'lodash'
|
4 |
|
5 | const chance = new Chance()
|
6 |
|
7 |
|
8 | test('note() returns a valid note', t => {
|
9 | _.times(1000, () => {
|
10 | let note = chance.note()
|
11 | t.true(_.isString(note))
|
12 | t.true(note.length <= 2)
|
13 | })
|
14 | })
|
15 |
|
16 |
|
17 | test('midi_note() returns a valid midi note between 0 and 127', t => {
|
18 | _.times(1000, () => {
|
19 | let midi_note = chance.midi_note()
|
20 | t.true(_.isNumber(midi_note))
|
21 | t.true(midi_note >= 0)
|
22 | t.true(midi_note <= 127)
|
23 | })
|
24 | })
|
25 |
|
26 |
|
27 | test('chord_quality() returns a valid chord quality', t => {
|
28 | _.times(1000, () => {
|
29 | let chord_quality = chance.chord_quality()
|
30 | t.true(_.isString(chord_quality))
|
31 | t.true(chord_quality.length <= 4)
|
32 | })
|
33 | })
|
34 |
|
35 |
|
36 | test('chord() returns a valid chord', t => {
|
37 | _.times(1000, () => {
|
38 | let chord = chance.chord()
|
39 | t.true(_.isString(chord))
|
40 | t.true(chord.length <= 6)
|
41 | })
|
42 | })
|
43 |
|
44 |
|
45 | test('tempo() returns a valid tempo between 40 and 320', t => {
|
46 | _.times(1000, () => {
|
47 | let tempo = chance.tempo()
|
48 | t.true(_.isNumber(tempo))
|
49 | t.true(tempo >= 40)
|
50 | t.true(tempo <= 320)
|
51 | })
|
52 | })
|
53 |
|
54 |
|
55 |
|
56 | const music_genres = [
|
57 | 'Rock',
|
58 | 'Pop',
|
59 | 'Hip-Hop',
|
60 | 'Jazz',
|
61 | 'Classical',
|
62 | 'Electronic',
|
63 | 'Country',
|
64 | 'R&B',
|
65 | 'Reggae',
|
66 | 'Blues',
|
67 | 'Metal',
|
68 | 'Folk',
|
69 | 'Alternative',
|
70 | 'Punk',
|
71 | 'Disco',
|
72 | 'Funk',
|
73 | 'Techno',
|
74 | 'Indie',
|
75 | 'Gospel',
|
76 | 'Dance',
|
77 | 'Children\'s',
|
78 | 'World'
|
79 | ]
|
80 |
|
81 | test('music_genre() returns an error if category given is invalid', t => {
|
82 | t.throws(() => {
|
83 | chance.music_genre('UnknownGenre');
|
84 | }, Error);
|
85 | })
|
86 |
|
87 | test('music_genre() returns a valid genre for general category', t => {
|
88 | const randomGenre = chance.music_genre('general');
|
89 | t.true(typeof randomGenre === 'string');
|
90 | });
|
91 |
|
92 | music_genres.forEach(category => {
|
93 | test(`music_genre() returns a valid genre in the ${category} category`, t => {
|
94 | const genre = chance.music_genre(category.toLowerCase());
|
95 | t.true(typeof genre === 'string');
|
96 | });
|
97 | })
|
98 |
|