Skip to content

Commit

Permalink
test: unit test new median function
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Jun 17, 2024
1 parent e6f9c46 commit 0e047c3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'node:assert';
import { describe, it } from 'node:test';
import { average, sort, sum } from '../src/index.js';
import { average, median, sort, sum } from '../src/index.js';

describe('sum', () => {
it('should sum all numbers', () => {
Expand All @@ -25,6 +25,16 @@ describe('average', () => {
});
});

describe('median', () => {
it('should calculate median for odd-length array', () => {
assert.strictEqual(median([3, 1, 2]), 2);
});

it('should calculate median for even-length array', () => {
assert.strictEqual(median([3, 4, 1, 2]), 2.5);
});
});

describe('sort', () => {
it('should sort numbers in ascending order by default', () => {
assert.deepEqual(sort([4, 2, 1, 3]), [1, 2, 3, 4]);
Expand Down

0 comments on commit 0e047c3

Please sign in to comment.