Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 624a17d

Browse files
author
programmiri
committed
Add exercise triangle
1 parent e9116b3 commit 624a17d

File tree

6 files changed

+4413
-0
lines changed

6 files changed

+4413
-0
lines changed

‎triangle/.eslintrc‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"root": true,
3+
"parser": "babel-eslint",
4+
"parserOptions": {
5+
"ecmaVersion": 7,
6+
"sourceType": "module"
7+
},
8+
"env": {
9+
"es6": true,
10+
"node": true,
11+
"jest": true
12+
},
13+
"extends": [
14+
"eslint:recommended",
15+
"plugin:import/errors",
16+
"plugin:import/warnings"
17+
],
18+
"rules": {
19+
"linebreak-style": "off",
20+
21+
"import/extensions": "off",
22+
"import/no-default-export": "off",
23+
"import/no-unresolved": "off",
24+
"import/prefer-default-export": "off"
25+
}
26+
}

‎triangle/README.md‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Triangle
2+
3+
Determine if a triangle is equilateral, isosceles, or scalene.
4+
5+
An _equilateral_ triangle has all three sides the same length.
6+
7+
An _isosceles_ triangle has at least two sides the same length. (It is sometimes
8+
specified as having exactly two sides the same length, but for the purposes of
9+
this exercise we'll say at least two.)
10+
11+
A _scalene_ triangle has all sides of different lengths.
12+
13+
## Note
14+
15+
For a shape to be a triangle at all, all sides have to be of length > 0, and
16+
the sum of the lengths of any two sides must be greater than or equal to the
17+
length of the third side. See [Triangle Inequality](https://en.wikipedia.org/wiki/Triangle_inequality).
18+
19+
## Dig Deeper
20+
21+
The case where the sum of the lengths of two sides _equals_ that of the
22+
third is known as a _degenerate_ triangle - it has zero area and looks like
23+
a single line. Feel free to add your own code/tests to check for degenerate triangles.
24+
25+
## Setup
26+
27+
Go through the setup instructions for Javascript to install the necessary
28+
dependencies:
29+
30+
[https://exercism.io/tracks/javascript/installation](https://exercism.io/tracks/javascript/installation)
31+
32+
## Requirements
33+
34+
Install assignment dependencies:
35+
36+
```bash
37+
$ npm install
38+
```
39+
40+
## Making the test suite pass
41+
42+
Execute the tests with:
43+
44+
```bash
45+
$ npm test
46+
```
47+
48+
In the test suites all tests but the first have been skipped.
49+
50+
Once you get a test passing, you can enable the next one by changing `xtest` to
51+
`test`.
52+
53+
## Source
54+
55+
The Ruby Koans triangle project, parts 1 & 2 [http://rubykoans.com](http://rubykoans.com)
56+
57+
## Submitting Incomplete Solutions
58+
59+
It's possible to submit an incomplete solution so you can see how others have
60+
completed the exercise.

‎triangle/babel.config.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/env',
5+
{
6+
targets: {
7+
node: 'current',
8+
},
9+
useBuiltIns: false,
10+
},
11+
12+
],
13+
],
14+
};

‎triangle/package.json‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "exercism-javascript",
3+
"version": "0.0.0",
4+
"description": "Exercism exercises in Javascript.",
5+
"author": "Katrina Owen",
6+
"private": true,
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/exercism/javascript"
10+
},
11+
"devDependencies": {
12+
"@babel/cli": "^7.2.3",
13+
"@babel/core": "^7.4.0",
14+
"@babel/preset-env": "^7.4.2",
15+
"babel-eslint": "^10.0.1",
16+
"babel-jest": "^24.5.0",
17+
"eslint": "^5.15.3",
18+
"eslint-plugin-import": "^2.16.0",
19+
"jest": "^24.5.0"
20+
},
21+
"jest": {
22+
"modulePathIgnorePatterns": [
23+
"package.json"
24+
]
25+
},
26+
"scripts": {
27+
"test": "jest --no-cache ./*",
28+
"watch": "jest --no-cache --watch ./*",
29+
"lint": "eslint .",
30+
"lint-test": "eslint . && jest --no-cache ./* "
31+
},
32+
"license": "MIT",
33+
"dependencies": {}
34+
}

‎triangle/triangle.spec.js‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { Triangle } from './triangle';
2+
3+
describe('Triangle', () => {
4+
test('equilateral triangles have equal sides', () => {
5+
const triangle = new Triangle(2, 2, 2);
6+
expect(triangle.kind()).toEqual('equilateral');
7+
});
8+
9+
xtest('larger equilateral triangles also have equal sides', () => {
10+
const triangle = new Triangle(10, 10, 10);
11+
expect(triangle.kind()).toEqual('equilateral');
12+
});
13+
14+
xtest('isosceles triangles have last two sides equal', () => {
15+
const triangle = new Triangle(3, 4, 4);
16+
expect(triangle.kind()).toEqual('isosceles');
17+
});
18+
19+
xtest('isosceles trianges have first and last sides equal', () => {
20+
const triangle = new Triangle(4, 3, 4);
21+
expect(triangle.kind()).toEqual('isosceles');
22+
});
23+
24+
xtest('isosceles triangles have two first sides equal', () => {
25+
const triangle = new Triangle(4, 4, 3);
26+
expect(triangle.kind()).toEqual('isosceles');
27+
});
28+
29+
xtest('isosceles triangles have in fact exactly two sides equal', () => {
30+
const triangle = new Triangle(10, 10, 2);
31+
expect(triangle.kind()).toEqual('isosceles');
32+
});
33+
34+
xtest('scalene triangles have no equal sides', () => {
35+
const triangle = new Triangle(3, 4, 5);
36+
expect(triangle.kind()).toEqual('scalene');
37+
});
38+
39+
xtest('scalene triangles have no equal sides at a larger scale too', () => {
40+
const triangle = new Triangle(10, 11, 12);
41+
expect(triangle.kind()).toEqual('scalene');
42+
});
43+
44+
xtest('scalene triangles have no equal sides in descending order either', () => {
45+
const triangle = new Triangle(5, 4, 2);
46+
expect(triangle.kind()).toEqual('scalene');
47+
});
48+
49+
xtest('very small triangles are legal', () => {
50+
const triangle = new Triangle(0.4, 0.6, 0.3);
51+
expect(triangle.kind()).toEqual('scalene');
52+
});
53+
54+
xtest('test triangles with no size are illegal', () => {
55+
const triangle = new Triangle(0, 0, 0);
56+
expect(triangle.kind.bind(triangle)).toThrow();
57+
});
58+
59+
xtest('triangles with negative sides are illegal', () => {
60+
const triangle = new Triangle(3, 4, -5);
61+
expect(triangle.kind.bind(triangle)).toThrow();
62+
});
63+
64+
xtest('triangles violating triangle inequality are illegal', () => {
65+
const triangle = new Triangle(1, 1, 3);
66+
expect(triangle.kind.bind(triangle)).toThrow();
67+
});
68+
69+
xtest('triangles violating triangle inequality are illegal 2', () => {
70+
const triangle = new Triangle(7, 3, 2);
71+
expect(triangle.kind.bind(triangle)).toThrow();
72+
});
73+
74+
xtest('triangles violating triangle inequality are illegal 3', () => {
75+
const triangle = new Triangle(10, 1, 3);
76+
expect(triangle.kind.bind(triangle)).toThrow();
77+
});
78+
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /