-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
81 lines (67 loc) · 3.23 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const processInput = require('./commands');
const {artists, albums} = require('./database');
function assertTrue(assertion) {
if (assertion) {
console.log("pass");
} else {
console.trace();
throw "Assertion not true";
}
}
let output;
// test adding
output = processInput('add "Ride the Lightning" "Metallica"');
assertTrue(output.length === 1);
assertTrue(output[0] === 'Added "Ride the Lightning" by Metallica');
assertTrue(artists.Metallica[0] === 'Ride the Lightning');
assertTrue(albums['Ride the Lightning'].artist === 'Metallica');
assertTrue(!albums['Ride the Lightning'].played);
processInput('add "Licensed to Ill" "Beastie Boys"');
assertTrue(artists['Beastie Boys'][0] === 'Licensed to Ill');
assertTrue(albums['Licensed to Ill'].artist === 'Beastie Boys');
assertTrue(!albums['Licensed to Ill'].played);
processInput('add "Pauls Boutique" "Beastie Boys"');
assertTrue(artists['Beastie Boys'][1] === 'Pauls Boutique');
assertTrue(albums['Pauls Boutique'].artist === 'Beastie Boys');
assertTrue(!albums['Pauls Boutique'].played);
processInput('add "The Dark Side of the Moon" "Pink Floyd"');
assertTrue(artists['Pink Floyd'][0] === 'The Dark Side of the Moon');
assertTrue(albums['The Dark Side of the Moon'].artist === 'Pink Floyd');
assertTrue(!albums['The Dark Side of the Moon'].played);
// test show all
output = processInput('show all');
assertTrue(output.length === 4);
assertTrue(output[0] === '"Ride the Lightning" by Metallica (unplayed)');
assertTrue(output[1] === '"Licensed to Ill" by Beastie Boys (unplayed)');
assertTrue(output[2] === '"Pauls Boutique" by Beastie Boys (unplayed)');
assertTrue(output[3] === '"The Dark Side of the Moon" by Pink Floyd (unplayed)');
// test playing
output = processInput('play "Licensed to Ill"');
assertTrue(output.length === 1);
assertTrue(output[0] === 'You\'re listening to "Licensed to Ill"');
assertTrue(albums['Licensed to Ill'].played);
output = processInput('play "The Dark Side of the Moon"');
assertTrue(output.length === 1);
assertTrue(output[0] === 'You\'re listening to "The Dark Side of the Moon"');
assertTrue(albums['The Dark Side of the Moon'].played);
// test show all after playing
output = processInput('show all');
assertTrue(output.length === 4);
assertTrue(output[0] === '"Ride the Lightning" by Metallica (unplayed)');
assertTrue(output[1] === '"Licensed to Ill" by Beastie Boys (played)');
assertTrue(output[2] === '"Pauls Boutique" by Beastie Boys (unplayed)');
assertTrue(output[3] === '"The Dark Side of the Moon" by Pink Floyd (played)');
// test show unplayed
output = processInput('show unplayed');
assertTrue(output[0] === '"Ride the Lightning" by Metallica');
assertTrue(output[1] === '"Pauls Boutique" by Beastie Boys');
// test show all by
output = processInput('show all by "Beastie Boys"');
assertTrue(output[0] === '"Licensed to Ill" by Beastie Boys (played)');
assertTrue(output[1] === '"Pauls Boutique" by Beastie Boys (unplayed)');
// test show unplayed by
output = processInput('show unplayed by "Beastie Boys"');
assertTrue(output[0] === '"Pauls Boutique" by Beastie Boys');
// test disallows duplicate album names
output = processInput('add "The Dark Side of the Moon" "The Flaming Lips"');
assertTrue(output[0] === 'Whoops, an album by that name has already been entered.');