|
| 1 | +import { assert } from 'chai'; |
| 2 | +import sinon from 'sinon'; |
| 3 | +import File from '../../../File.js'; |
| 4 | +import { assertOutputAnswer } from '../../../assertOutputAnswer.js'; |
| 5 | +import { execute } from '../../../../lib/training/expert/musicScores/musicScores.js'; |
| 6 | + |
| 7 | +/** |
| 8 | + * Tests for the "Music scores" puzzle. |
| 9 | + */ |
| 10 | +suite('Music scores', function() { |
| 11 | + const sandbox = sinon.createSandbox(); |
| 12 | + |
| 13 | + setup(function () { |
| 14 | + sandbox.stub(console, "log"); |
| 15 | + }); |
| 16 | + |
| 17 | + teardown(function () { |
| 18 | + sandbox.restore(); |
| 19 | + }); |
| 20 | + |
| 21 | + |
| 22 | + test('One quarter note between lines', function() { |
| 23 | + let inputFile = new File('./test/training/expert/musicScores/input/01 - one quarter note between lines.txt'); |
| 24 | + |
| 25 | + execute(inputFile.readline.bind(inputFile)); |
| 26 | + |
| 27 | + assert.strictEqual( |
| 28 | + console.log.getCall(0).args[0], |
| 29 | + "AQ" |
| 30 | + ); |
| 31 | + }); |
| 32 | + |
| 33 | + test('One quarter note on a line', function() { |
| 34 | + let inputFile = new File('./test/training/expert/musicScores/input/02 - one quarter note on a line.txt'); |
| 35 | + |
| 36 | + execute(inputFile.readline.bind(inputFile)); |
| 37 | + |
| 38 | + assert.strictEqual( |
| 39 | + console.log.getCall(0).args[0], |
| 40 | + "BQ" |
| 41 | + ); |
| 42 | + }); |
| 43 | + |
| 44 | + test('One half note between lines', function() { |
| 45 | + let inputFile = new File('./test/training/expert/musicScores/input/03 - one half note between lines.txt'); |
| 46 | + |
| 47 | + execute(inputFile.readline.bind(inputFile)); |
| 48 | + |
| 49 | + assert.strictEqual( |
| 50 | + console.log.getCall(0).args[0], |
| 51 | + "AH" |
| 52 | + ); |
| 53 | + }); |
| 54 | + |
| 55 | + test('One half note on a line', function() { |
| 56 | + let inputFile = new File('./test/training/expert/musicScores/input/04 - one half note on a line.txt'); |
| 57 | + |
| 58 | + execute(inputFile.readline.bind(inputFile)); |
| 59 | + |
| 60 | + assert.strictEqual( |
| 61 | + console.log.getCall(0).args[0], |
| 62 | + "BH" |
| 63 | + ); |
| 64 | + }); |
| 65 | + |
| 66 | + test('Only quarter notes without lower C', function() { |
| 67 | + let inputFile = new File('./test/training/expert/musicScores/input/05 - only quarter notes without lower C.txt'); |
| 68 | + |
| 69 | + execute(inputFile.readline.bind(inputFile)); |
| 70 | + |
| 71 | + assert.strictEqual( |
| 72 | + console.log.getCall(0).args[0], |
| 73 | + "CQ CQ CQ CQ DQ EQ CQ AQ" |
| 74 | + ); |
| 75 | + }); |
| 76 | + |
| 77 | + test('Only half notes without lower C', function() { |
| 78 | + let inputFile = new File('./test/training/expert/musicScores/input/06 - only half notes without lower C.txt'); |
| 79 | + |
| 80 | + execute(inputFile.readline.bind(inputFile)); |
| 81 | + |
| 82 | + assert.strictEqual( |
| 83 | + console.log.getCall(0).args[0], |
| 84 | + "DH EH FH AH CH EH DH" |
| 85 | + ); |
| 86 | + }); |
| 87 | + |
| 88 | + test('Scale half and quarter notes', function() { |
| 89 | + let inputFile = new File('./test/training/expert/musicScores/input/07 - scale half and quarter notes.txt'); |
| 90 | + |
| 91 | + execute(inputFile.readline.bind(inputFile)); |
| 92 | + |
| 93 | + assert.strictEqual( |
| 94 | + console.log.getCall(0).args[0], |
| 95 | + "EQ FH GQ AH BQ CH DQ EH FQ" |
| 96 | + ); |
| 97 | + }); |
| 98 | + |
| 99 | + test('Lower C', function() { |
| 100 | + let inputFile = new File('./test/training/expert/musicScores/input/08 - lower C.txt'); |
| 101 | + |
| 102 | + execute(inputFile.readline.bind(inputFile)); |
| 103 | + |
| 104 | + assert.strictEqual( |
| 105 | + console.log.getCall(0).args[0], |
| 106 | + "CQ CQ CQ DQ EH DH CQ EQ DQ DQ CH" |
| 107 | + ); |
| 108 | + }); |
| 109 | + |
| 110 | + test('Very close', function() { |
| 111 | + let inputFile = new File('./test/training/expert/musicScores/input/09 - very close.txt'); |
| 112 | + |
| 113 | + execute(inputFile.readline.bind(inputFile)); |
| 114 | + |
| 115 | + assert.strictEqual( |
| 116 | + console.log.getCall(0).args[0], |
| 117 | + "BQ CH DH EH FQ GQ GQ BQ DH BQ" |
| 118 | + ); |
| 119 | + }); |
| 120 | + |
| 121 | + test('Only 1 pixel wide', function() { |
| 122 | + let inputFile = new File('./test/training/expert/musicScores/input/10 - Only 1 pixel wide.txt'); |
| 123 | + |
| 124 | + execute(inputFile.readline.bind(inputFile)); |
| 125 | + |
| 126 | + assert.strictEqual( |
| 127 | + console.log.getCall(0).args[0], |
| 128 | + "BQ CH DH EH FQ GQ GQ BQ DH BQ BQ CH DH EH FQ GQ GQ BQ DH BQ" |
| 129 | + ); |
| 130 | + }); |
| 131 | + |
| 132 | + test('Doctor Who theme', function() { |
| 133 | + let inputFile = new File('./test/training/expert/musicScores/input/11 - doctor Who theme.txt'); |
| 134 | + |
| 135 | + execute(inputFile.readline.bind(inputFile)); |
| 136 | + |
| 137 | + assertOutputAnswer('./test/training/expert/musicScores/output/11 - doctor Who theme.txt'); |
| 138 | + }); |
| 139 | + |
| 140 | + test('Random', function() { |
| 141 | + let inputFile = new File('./test/training/expert/musicScores/input/12 - random.txt'); |
| 142 | + |
| 143 | + execute(inputFile.readline.bind(inputFile)); |
| 144 | + |
| 145 | + assertOutputAnswer('./test/training/expert/musicScores/output/12 - random.txt'); |
| 146 | + }); |
| 147 | +}); |
0 commit comments