Skip to content

Commit b8b3693

Browse files
committed
Update some tests
1 parent bd408ce commit b8b3693

File tree

4 files changed

+11
-28
lines changed

4 files changed

+11
-28
lines changed

src/bundles/midi/src/__tests__/index.test.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
1-
import { head, tail, type List } from 'js-slang/dist/stdlib/list';
1+
import { list_to_vector } from 'js-slang/dist/stdlib/list';
22
import { describe, expect, test } from 'vitest';
33
import { letter_name_to_midi_note, midi_note_to_letter_name } from '..';
44
import { major_scale, minor_scale } from '../scales';
55
import { Accidental, type Note, type NoteWithOctave } from '../types';
66
import { noteToValues } from '../utils';
77

8-
function list_to_array(list: List) {
9-
const output: number[] = [];
10-
while (list !== null) {
11-
output.push(head(list));
12-
list = tail(list);
13-
}
14-
15-
return output;
16-
}
17-
188
describe('scales', () => {
199
test('major_scale', () => {
2010
const c0 = letter_name_to_midi_note('C0');
2111
const scale = major_scale(c0);
22-
expect(list_to_array(scale)).toMatchObject([12, 14, 16, 17, 19, 21, 23, 24]);
12+
expect(list_to_vector(scale)).toMatchObject([12, 14, 16, 17, 19, 21, 23, 24]);
2313
});
2414

2515
test('minor_scale', () => {
2616
const a0 = letter_name_to_midi_note('A0');
2717
const scale = minor_scale(a0);
28-
expect(list_to_array(scale)).toMatchObject([21, 23, 24, 26, 28, 29, 31, 33]);
18+
expect(list_to_vector(scale)).toMatchObject([21, 23, 24, 26, 28, 29, 31, 33]);
2919
});
3020
});
3121

src/bundles/pix_n_flix/vitest.config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { playwright } from '@vitest/browser-playwright';
21
import { defineProject } from 'vitest/config';
32

43
export default defineProject({
@@ -14,10 +13,6 @@ export default defineProject({
1413
name: 'pix_n_flix Bundle',
1514
browser: {
1615
enabled: true,
17-
provider: playwright(),
18-
instances: [{
19-
browser: 'chromium',
20-
}]
2116
}
2217
}
2318
});

src/bundles/sound/src/__tests__/recording.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('Recording functions', () => {
6363

6464
describe(funcs.record, () => {
6565
test('throws error if called without init_record', () => {
66-
expect(() => funcs.record(0)).toThrowError('Call init_record(); to obtain permission to use microphone');
66+
expect(() => funcs.record(0)).toThrowError('record: Call init_record(); to obtain permission to use microphone');
6767
});
6868

6969
test('throws error if called concurrently with another sound', () => {
@@ -101,7 +101,7 @@ describe('Recording functions', () => {
101101

102102
describe(funcs.record_for, () => {
103103
test('throws error if called without init_record', () => {
104-
expect(() => funcs.record_for(0, 0)).toThrowError('Call init_record(); to obtain permission to use microphone');
104+
expect(() => funcs.record_for(0, 0)).toThrowError('record_for: Call init_record(); to obtain permission to use microphone');
105105
});
106106

107107
test('throws error if called concurrently with another sound', () => {

src/bundles/sound/src/functions.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ function linear_decay(decay_period: number): (t: number) => number {
9292
* Determine if the user has already provided permission to use the
9393
* microphone and return the provided MediaStream if they have.
9494
*/
95-
function check_permission() {
95+
function getAudioStream(func_name: string) {
9696
if (globalVars.stream === null) {
97-
throw new Error('Call init_record(); to obtain permission to use microphone');
97+
throw new Error(`${func_name}: Call init_record(); to obtain permission to use microphone`);
9898
} else if (globalVars.stream === false) {
99-
throw new Error(`Permission has been denied.\n
99+
throw new Error(`${func_name}: Permission has been denied.\n
100100
Re-start browser and call init_record();\n
101101
to obtain permission to use microphone.`);
102102
}
@@ -201,7 +201,7 @@ export function record(buffer: number): () => SoundPromise {
201201
throw new Error(`${record.name}: Cannot record while another sound is playing!`);
202202
}
203203

204-
const stream = check_permission();
204+
const stream = getAudioStream(record.name);
205205
const mediaRecorder = new MediaRecorder(stream);
206206

207207
setTimeout(() => {
@@ -254,7 +254,7 @@ export function record_for(duration: number, buffer: number): SoundPromise {
254254
throw new Error(`${record_for.name}: Cannot record while another sound is playing!`);
255255
}
256256

257-
const stream = check_permission();
257+
const stream = getAudioStream(record_for.name);
258258
const mediaRecorder = new MediaRecorder(stream);
259259

260260
// order of events for record_for:
@@ -380,8 +380,7 @@ export function play_wave(wave: Wave, duration: number): Sound {
380380
}
381381

382382
/**
383-
* Plays the given Sound using the computer’s sound device.
384-
* The sound is added to a list of sounds to be played one-at-a-time
383+
* Adds the given Sound to a list of sounds to be played one-at-a-time
385384
* in a Source Academy tab.
386385
*
387386
* @param sound the Sound to play
@@ -392,7 +391,6 @@ export function play_in_tab(sound: Sound): Sound {
392391
// Type-check sound
393392
if (!is_sound(sound)) {
394393
throw new Error(`${play_in_tab.name} is expecting sound, but encountered ${sound}`);
395-
// If a sound is already playing, terminate execution.
396394
}
397395

398396
const duration = get_duration(sound);

0 commit comments

Comments
 (0)