Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync all exercises #895

Merged
merged 32 commits into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f40724f
Sync exercises A* B* C*
SleeplessByte Dec 16, 2020
f05b120
Sync exercises D*
SleeplessByte Dec 17, 2020
957199c
Sync exercises E*
SleeplessByte Dec 17, 2020
490984e
Sync exercises F*
SleeplessByte Dec 17, 2020
1ffa54a
Fix grade-school implementation
SleeplessByte Dec 18, 2020
80355e7
Sync exericses G*
SleeplessByte Dec 18, 2020
33ab5f0
Sync exericses H*
SleeplessByte Dec 18, 2020
d919f63
Sync exericses I*
SleeplessByte Dec 18, 2020
5af8ac2
Sync exericses K*
SleeplessByte Dec 18, 2020
61864ad
Fix crypto-square
SleeplessByte Dec 18, 2020
c5f3a86
Re-implement linked-list
SleeplessByte Dec 18, 2020
e882a15
Sync exericses L*
SleeplessByte Dec 18, 2020
59be3f1
Fix binary implementation
SleeplessByte Dec 18, 2020
09115b8
Fix binary implementation
SleeplessByte Dec 18, 2020
31c60ff
Skip a crytpo test for now
SleeplessByte Dec 18, 2020
774fb12
two-bucket: skip broken/unimplemented tests
SleeplessByte Dec 18, 2020
c3cc507
Fix package.json
SleeplessByte Dec 18, 2020
ac1b248
Sync exercises M*
SleeplessByte Dec 19, 2020
db4c0b1
Sync exercises O*
SleeplessByte Dec 19, 2020
33a23d5
Add new tests for linked-list
SleeplessByte Dec 23, 2020
eef3fe1
Fix format-code version
SleeplessByte Dec 23, 2020
b26265d
Sync exercises P*
SleeplessByte Dec 24, 2020
7eac325
Merge branch 'chore/sync-tests-toml' of https://github.com/exercism/j…
SleeplessByte Dec 24, 2020
9da0055
Sync exercises Q*
SleeplessByte Dec 24, 2020
2add3c6
Sync exercises R*
SleeplessByte Dec 24, 2020
4b57ac2
Fix format
SleeplessByte Dec 24, 2020
2a9e3f3
Fix proverb implementation
SleeplessByte Dec 24, 2020
9a3fdce
Sync exercises S*
SleeplessByte Dec 24, 2020
d72ba05
Sync exercises T*
SleeplessByte Dec 24, 2020
6a088df
Sync exercises W*
SleeplessByte Dec 24, 2020
6240c9a
Sync exercises Z*
SleeplessByte Dec 24, 2020
2f4cbf5
Fix test
SleeplessByte Dec 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/format-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: 'Format code'
run: ./bin/format.sh
env:
EXERCISM_PRETTIER_VERSION: '2.1.2'
EXERCISM_PRETTIER_VERSION: '2.2.1'

- name: 'Commit formatted code'
run: |
Expand Down
9 changes: 9 additions & 0 deletions exercises/acronym/acronym.spec.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import { parse } from './acronym';

describe('Acronyms are produced from', () => {
// basic
test('title cased phrases', () => {
expect(parse('Portable Network Graphics')).toEqual('PNG');
});

// lowercase words
xtest('other title cased phrases', () => {
expect(parse('Ruby on Rails')).toEqual('ROR');
});

// punctuation
xtest('phrases with punctuation', () => {
expect(parse('First In, First Out')).toEqual('FIFO');
});

// all caps word
xtest('phrases with all uppercase words', () => {
expect(parse('GNU Image Manipulation Program')).toEqual('GIMP');
});

// punctuation without whitespace
xtest('phrases with punctuation without whitespace', () => {
expect(parse('Complementary metal-oxide semiconductor')).toEqual('CMOS');
});

// very long abbreviation
xtest('long phrases', () => {
expect(
parse(
Expand All @@ -29,14 +35,17 @@ describe('Acronyms are produced from', () => {
).toEqual('ROTFLSHTMDCOALM');
});

// consecutive delimiters
xtest('phrases with consecutive delimiters', () => {
expect(parse('Something - I made up from thin air')).toEqual('SIMUFTA');
});

// apostrophes
xtest('phrases with apostrophes', () => {
expect(parse("Halley's Comet")).toEqual('HC');
});

// underscore emphasis
xtest('phrases with underscore emphasis', () => {
expect(parse('The Road _Not_ Taken')).toEqual('TRNT');
});
Expand Down
49 changes: 49 additions & 0 deletions exercises/affine-cipher/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[canonical-tests]

# encode yes
"2ee1d9af-1c43-416c-b41b-cefd7d4d2b2a" = true

# encode no
"785bade9-e98b-4d4f-a5b0-087ba3d7de4b" = true

# encode OMG
"2854851c-48fb-40d8-9bf6-8f192ed25054" = true

# encode O M G
"bc0c1244-b544-49dd-9777-13a770be1bad" = true

# encode mindblowingly
"381a1a20-b74a-46ce-9277-3778625c9e27" = true

# encode numbers
"6686f4e2-753b-47d4-9715-876fdc59029d" = true

# encode deep thought
"ae23d5bd-30a8-44b6-afbe-23c8c0c7faa3" = true

# encode all the letters
"c93a8a4d-426c-42ef-9610-76ded6f7ef57" = true

# encode with a not coprime to m
"0673638a-4375-40bd-871c-fb6a2c28effb" = true

# decode exercism
"3f0ac7e2-ec0e-4a79-949e-95e414953438" = true

# decode a sentence
"241ee64d-5a47-4092-a5d7-7939d259e077" = true

# decode numbers
"33fb16a1-765a-496f-907f-12e644837f5e" = true

# decode all the letters
"20bc9dce-c5ec-4db6-a3f1-845c776bcbf7" = true

# decode with no spaces in input
"623e78c0-922d-49c5-8702-227a3e8eaf81" = true

# decode with too many spaces
"58fd5c2a-1fd9-4563-a80a-71cff200f26f" = true

# decode with a not coprime to m
"b004626f-c186-4af9-a3f4-58f74cdb86d5" = true
24 changes: 0 additions & 24 deletions exercises/all-your-base/all-your-base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,4 @@ describe('Converter', () => {
convert([1], -2, -7);
}).toThrow(new Error('Wrong input base'));
});

xtest('missing input base throws an error', () => {
expect(() => {
convert([0]);
}).toThrow(new Error('Wrong input base'));
});

xtest('wrong input_base base not integer', () => {
expect(() => {
convert([0], 2.5);
}).toThrow(new Error('Wrong input base'));
});

xtest('missing output base throws an error', () => {
expect(() => {
convert([0], 2);
}).toThrow(new Error('Wrong output base'));
});

xtest('wrong output_base base not integer', () => {
expect(() => {
convert([0], 3, 2.5);
}).toThrow(new Error('Wrong output base'));
});
});
18 changes: 18 additions & 0 deletions exercises/alphametics/alphametics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,22 @@ describe('Solve the alphametics puzzle', () => {
};
expect(solve(puzzle)).toEqual(expected);
});

test.skip('puzzle with ten letters and 199 addends', () => {
const puzzle =
'THIS + A + FIRE + THEREFORE + FOR + ALL + HISTORIES + I + TELL + A + TALE + THAT + FALSIFIES + ITS + TITLE + TIS + A + LIE + THE + TALE + OF + THE + LAST + FIRE + HORSES + LATE + AFTER + THE + FIRST + FATHERS + FORESEE + THE + HORRORS + THE + LAST + FREE + TROLL + TERRIFIES + THE + HORSES + OF + FIRE + THE + TROLL + RESTS + AT + THE + HOLE + OF + LOSSES + IT + IS + THERE + THAT + SHE + STORES + ROLES + OF + LEATHERS + AFTER + SHE + SATISFIES + HER + HATE + OFF + THOSE + FEARS + A + TASTE + RISES + AS + SHE + HEARS + THE + LEAST + FAR + HORSE + THOSE + FAST + HORSES + THAT + FIRST + HEAR + THE + TROLL + FLEE + OFF + TO + THE + FOREST + THE + HORSES + THAT + ALERTS + RAISE + THE + STARES + OF + THE + OTHERS + AS + THE + TROLL + ASSAILS + AT + THE + TOTAL + SHIFT + HER + TEETH + TEAR + HOOF + OFF + TORSO + AS + THE + LAST + HORSE + FORFEITS + ITS + LIFE + THE + FIRST + FATHERS + HEAR + OF + THE + HORRORS + THEIR + FEARS + THAT + THE + FIRES + FOR + THEIR + FEASTS + ARREST + AS + THE + FIRST + FATHERS + RESETTLE + THE + LAST + OF + THE + FIRE + HORSES + THE + LAST + TROLL + HARASSES + THE + FOREST + HEART + FREE + AT + LAST + OF + THE + LAST + TROLL + ALL + OFFER + THEIR + FIRE + HEAT + TO + THE + ASSISTERS + FAR + OFF + THE + TROLL + FASTS + ITS + LIFE + SHORTER + AS + STARS + RISE + THE + HORSES + REST + SAFE + AFTER + ALL + SHARE + HOT + FISH + AS + THEIR + AFFILIATES + TAILOR + A + ROOFS + FOR + THEIR + SAFE == FORTRESSES';
const expected = {
A: 1,
E: 0,
F: 5,
H: 8,
I: 7,
L: 2,
O: 6,
R: 3,
S: 4,
T: 9,
};
expect(solve(puzzle)).toEqual(expected);
});
});
102 changes: 56 additions & 46 deletions exercises/binary-search-tree/binary-search-tree.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,40 @@ describe('BinarySearchTree', () => {
expect(new BinarySearchTree(4).data).toEqual(4);
});

xtest('inserting less', () => {
const four = new BinarySearchTree(4);
four.insert(2);

expect(four.data).toEqual(4);
expect(four.left.data).toEqual(2);
describe('insert data at proper node', () => {
xtest('smaller number at left node', () => {
const four = new BinarySearchTree(4);
four.insert(2);

expect(four.data).toEqual(4);
expect(four.left.data).toEqual(2);
});

xtest('same number at left node"', () => {
const four = new BinarySearchTree(4);
four.insert(4);

expect(four.data).toEqual(4);
expect(four.left.data).toEqual(4);
});

xtest('greater number at right node', () => {
const four = new BinarySearchTree(4);
four.insert(5);

expect(four.data).toEqual(4);
expect(four.right.data).toEqual(5);
});
});

xtest('inserting same', () => {
const four = new BinarySearchTree(4);
four.insert(4);

expect(four.data).toEqual(4);
expect(four.left.data).toEqual(4);
});

xtest('inserting right', () => {
const four = new BinarySearchTree(4);
four.insert(5);

expect(four.data).toEqual(4);
expect(four.right.data).toEqual(5);
});

xtest('complex tree', () => {
xtest('can create complex tree', () => {
const four = new BinarySearchTree(4);
four.insert(2);
four.insert(6);
four.insert(1);
four.insert(3);
four.insert(7);
four.insert(5);
four.insert(7);

expect(four.data).toEqual(4);
expect(four.left.data).toEqual(2);
Expand All @@ -55,33 +57,41 @@ describe('BinarySearchTree', () => {
expect(four.right.right.data).toEqual(7);
});

xtest('iterating one element', () => {
expect(recordAllData(new BinarySearchTree(4))).toEqual([4]);
});
describe('can sort data', () => {
xtest('can sort single number', () => {
expect(recordAllData(new BinarySearchTree(2))).toEqual([2]);
});

xtest('iterating over smaller element', () => {
const four = new BinarySearchTree(4);
four.insert(2);
xtest('can sort if second number is smaller than first', () => {
const four = new BinarySearchTree(2);
four.insert(1);

expect(recordAllData(four)).toEqual([2, 4]);
});
expect(recordAllData(four)).toEqual([1, 2]);
});

xtest('iterating over larger element', () => {
const four = new BinarySearchTree(4);
four.insert(5);
xtest('can sort if second number is same as first', () => {
const four = new BinarySearchTree(2);
four.insert(2);

expect(recordAllData(four)).toEqual([4, 5]);
});
expect(recordAllData(four)).toEqual([2, 2]);
});

xtest('iterating over complex tree', () => {
const four = new BinarySearchTree(4);
four.insert(2);
four.insert(1);
four.insert(3);
four.insert(6);
four.insert(7);
four.insert(5);
xtest('can sort if second number is greater than first', () => {
const four = new BinarySearchTree(2);
four.insert(3);

expect(recordAllData(four)).toEqual([2, 3]);
});

xtest('can sort complex tree', () => {
const four = new BinarySearchTree(2);
four.insert(1);
four.insert(3);
four.insert(6);
four.insert(7);
four.insert(5);

expect(recordAllData(four)).toEqual([1, 2, 3, 4, 5, 6, 7]);
expect(recordAllData(four)).toEqual([1, 2, 3, 5, 6, 7]);
});
});
});
26 changes: 19 additions & 7 deletions exercises/binary/binary.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,26 @@ describe('binary', () => {
xtest('10001101000 is decimal 1128', () =>
expect(new Binary('10001101000').toDecimal()).toEqual(1128));

xtest('00011111 is decimal 31', () =>
xtest('ignores leading zeros', () =>
expect(new Binary('00011111').toDecimal()).toEqual(31));

xtest('invalid inputs are decimal 0', () => {
expect(new Binary('carrot').toDecimal()).toEqual(0);
expect(new Binary('012').toDecimal()).toEqual(0);
expect(new Binary('10nope').toDecimal()).toEqual(0);
expect(new Binary('nope10').toDecimal()).toEqual(0);
expect(new Binary('10nope10').toDecimal()).toEqual(0);
xtest('invalid inputs are null', () => {
// "2 is not a valid binary digit
expect(new Binary('2').toDecimal()).toEqual(null);

// a number containing a non-binary digit is invalid
expect(new Binary('01201').toDecimal()).toEqual(null);

// a number with trailing non-binary characters is invalid
expect(new Binary('10nope').toDecimal()).toEqual(null);

// a number with leading non-binary characters is invalid
expect(new Binary('nope10').toDecimal()).toEqual(null);

// a number with internal non-binary characters is invalid
expect(new Binary('10nope10').toDecimal()).toEqual(null);

// a number and a word whitespace separated is invalid
expect(new Binary('001nope').toDecimal()).toEqual(null);
});
});
8 changes: 6 additions & 2 deletions exercises/binary/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

export class Binary {
constructor(binary) {
this.binary = binary.match(/^[01]*$/) ? parseInt(binary, 2) : 0;
this.binary = binary.match(/^[01]*$/) ? parseInt(binary, 2) : null;
}

toDecimal() {
if (this.binary === null) {
return null;
}

const out = Number(this.binary.toString(10));
return Number.isNaN(out) ? 0 : out;
return Number.isNaN(out) ? null : out;
}
}
4 changes: 2 additions & 2 deletions exercises/bob/bob.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ describe('Bob', () => {
expect(result).toEqual('Whoa, chill out!');
});

xtest('only numbers', () => {
xtest('no letters', () => {
const result = hey('1, 2, 3');
expect(result).toEqual('Whatever.');
});

xtest('question with only numbers', () => {
xtest('question with no letters', () => {
const result = hey('4?');
expect(result).toEqual('Sure.');
});
Expand Down
Loading