Skip to content

Commit dbc6e26

Browse files
Allow for pending and skipped tests (#25)
* Allow for pending and skipped tests * Remove logging * Add propper skip test
1 parent 58ae9f1 commit dbc6e26

File tree

16 files changed

+498
-12
lines changed

16 files changed

+498
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.1.0
4+
5+
- Allow skipping/pending tests (`test.skip`)
6+
37
## 2.0.3
48

59
- Disable compilation of `.test.ts` files when running in test-runner

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@exercism/typescript-test-runner",
33
"description": "Automated Test runner for exercism solutions in TypeScript.",
44
"author": "Derk-Jan Karrenbeld <[email protected]>",
5-
"version": "2.0.3",
5+
"version": "2.1.0",
66
"license": "AGPL-3.0-or-later",
77
"repository": {
88
"type": "git",

src/output.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ export class Output {
5151
this.results.status =
5252
aggregatedResults.numRuntimeErrorTestSuites === 0 &&
5353
aggregatedResults.numFailedTestSuites === 0 &&
54-
aggregatedResults.numPendingTests === 0 &&
54+
// Pending tests are skipped tests. test.skip tests are fine in our
55+
// reporter and should not be forced to have ran here. So the next
56+
// line is commented out.
57+
//
58+
// aggregatedResults.numPendingTests === 0 &&
5559
aggregatedResults.numFailedTests === 0
5660
? 'pass'
5761
: 'fail'
@@ -279,16 +283,20 @@ function buildTestOutput(
279283
]
280284
}
281285

282-
return inner.map((assert) => {
283-
return {
284-
name: assert.ancestorTitles.concat(assert.title).join(' > '),
285-
status: assert.status === 'passed' ? 'pass' : 'fail',
286-
message: sanitizeErrorMessage(
287-
testResult.testFilePath,
288-
assert.failureMessages.map(removeStackTrace).join('\n')
289-
),
290-
}
291-
})
286+
return inner
287+
.filter(
288+
(assert) => assert.status !== 'skipped' && assert.status !== 'pending'
289+
)
290+
.map((assert) => {
291+
return {
292+
name: assert.ancestorTitles.concat(assert.title).join(' > '),
293+
status: assert.status === 'passed' ? 'pass' : 'fail',
294+
message: sanitizeErrorMessage(
295+
testResult.testFilePath,
296+
assert.failureMessages.map(removeStackTrace).join('\n')
297+
),
298+
}
299+
})
292300
}
293301

294302
function removeStackTrace(message: string): string {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Instructions
2+
3+
A Pythagorean triplet is a set of three natural numbers, {a, b, c}, for
4+
which,
5+
6+
```text
7+
a**2 + b**2 = c**2
8+
```
9+
10+
and such that,
11+
12+
```text
13+
a < b < c
14+
```
15+
16+
For example,
17+
18+
```text
19+
3**2 + 4**2 = 9 + 16 = 25 = 5**2.
20+
```
21+
22+
Given an input integer N, find all Pythagorean triplets for which `a + b + c = N`.
23+
24+
For example, with N = 1000, there is exactly one Pythagorean triplet for which `a + b + c = 1000`: `{200, 375, 425}`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
!.meta
2+
3+
# Protected or generated
4+
.git
5+
.vscode
6+
7+
# When using npm
8+
node_modules/*
9+
10+
# Configuration files
11+
babel.config.js
12+
jest.config.js
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"project": "./tsconfig.json",
6+
"ecmaFeatures": {
7+
"jsx": true
8+
},
9+
"ecmaVersion": 2020,
10+
"sourceType": "module"
11+
},
12+
"extends": "@exercism/eslint-config-typescript",
13+
"env": {
14+
"jest": true
15+
},
16+
"overrides": [
17+
{
18+
"files": [".meta/proof.ci.ts", ".meta/exemplar.ts", "*.test.ts"],
19+
"excludedFiles": ["custom.test.ts"],
20+
"extends": "@exercism/eslint-config-typescript/maintainers"
21+
}
22+
]
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"blurb": "There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product a * b * c.",
3+
"authors": ["mdowds"],
4+
"contributors": ["masters3d", "mdmower", "SleeplessByte"],
5+
"files": {
6+
"solution": ["pythagorean-triplet.ts"],
7+
"test": ["pythagorean-triplet.test.ts"],
8+
"example": [".meta/proof.ci.ts"]
9+
},
10+
"source": "Problem 9 at Project Euler",
11+
"source_url": "http://projecteuler.net/problem=9"
12+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
type Options = {
2+
minFactor?: number
3+
maxFactor?: number
4+
sum: number
5+
}
6+
7+
type TripletArray = [number, number, number]
8+
9+
class Triplet {
10+
constructor(
11+
private readonly a: TripletArray[0],
12+
private readonly b: TripletArray[1],
13+
private readonly c: TripletArray[2]
14+
) {}
15+
16+
public toArray(): TripletArray {
17+
return [this.a, this.b, this.c]
18+
}
19+
20+
public get pythagorean(): boolean {
21+
return this.a * this.a + this.b * this.b === this.c * this.c
22+
}
23+
24+
public get sum(): number {
25+
return this.a + this.b + this.c
26+
}
27+
}
28+
29+
export function triplets({ minFactor, maxFactor, sum }: Options): Triplet[] {
30+
const min = minFactor || 1
31+
const max = maxFactor || sum - 1
32+
33+
const isDesired = (triplet: Triplet): boolean => {
34+
return triplet.pythagorean && (!sum || triplet.sum === sum)
35+
}
36+
37+
const result: Triplet[] = []
38+
39+
for (let a = min; a < max - 1; a += 1) {
40+
for (let b = a + 1; b < max; b += 1) {
41+
for (let c = b + 1; c <= max; c += 1) {
42+
const triplet = new Triplet(a, b, c)
43+
44+
if (isDesired(triplet)) {
45+
result.push(triplet)
46+
}
47+
}
48+
}
49+
}
50+
51+
return result
52+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This is an auto-generated file. Regular comments will be removed when this
2+
# file is regenerated. Regenerating will not touch any manually added keys,
3+
# so comments can be added in a "comment" key.
4+
5+
[a19de65d-35b8-4480-b1af-371d9541e706]
6+
description = "triplets whose sum is 12"
7+
8+
[48b21332-0a3d-43b2-9a52-90b2a6e5c9f5]
9+
description = "triplets whose sum is 108"
10+
11+
[dffc1266-418e-4daa-81af-54c3e95c3bb5]
12+
description = "triplets whose sum is 1000"
13+
14+
[5f86a2d4-6383-4cce-93a5-e4489e79b186]
15+
description = "no matching triplets for 1001"
16+
17+
[bf17ba80-1596-409a-bb13-343bdb3b2904]
18+
description = "returns all matching triplets"
19+
20+
[9d8fb5d5-6c6f-42df-9f95-d3165963ac57]
21+
description = "several matching triplets"
22+
23+
[f5be5734-8aa0-4bd1-99a2-02adcc4402b4]
24+
description = "triplets for large number"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: 'current',
8+
},
9+
useBuiltIns: 'entry',
10+
corejs: '3.17',
11+
},
12+
],
13+
'@babel/preset-typescript',
14+
],
15+
plugins: [
16+
'@babel/proposal-class-properties',
17+
'@babel/proposal-object-rest-spread',
18+
'@babel/plugin-syntax-bigint',
19+
],
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
verbose: true,
3+
projects: ['<rootDir>'],
4+
testMatch: [
5+
'**/__tests__/**/*.[jt]s?(x)',
6+
'**/test/**/*.[jt]s?(x)',
7+
'**/?(*.)+(spec|test).[jt]s?(x)',
8+
],
9+
testPathIgnorePatterns: [
10+
'/(?:production_)?node_modules/',
11+
'.d.ts$',
12+
'<rootDir>/test/fixtures',
13+
'<rootDir>/test/helpers',
14+
'__mocks__',
15+
],
16+
transform: {
17+
'^.+\\.[jt]sx?$': 'babel-jest',
18+
},
19+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@exercism/typescript-pythagorean-triplet",
3+
"version": "1.0.0",
4+
"description": "Exercism exercises in Typescript.",
5+
"private": true,
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/exercism/typescript"
9+
},
10+
"devDependencies": {
11+
"@babel/core": "^7.15.5",
12+
"@babel/plugin-proposal-class-properties": "^7.14.5",
13+
"@babel/plugin-proposal-object-rest-spread": "^7.14.7",
14+
"@babel/plugin-syntax-bigint": "^7.8.3",
15+
"@babel/preset-env": "^7.15.4",
16+
"@babel/preset-typescript": "^7.15.0",
17+
"@types/jest": "^26.0.24",
18+
"@types/node": "^14.17.14",
19+
"@exercism/eslint-config-typescript": "^0.3.0",
20+
"babel-jest": "^26.6.3",
21+
"core-js": "^3.17.2",
22+
"eslint": "^7.32.0",
23+
"eslint-plugin-import": "^2.24.2",
24+
"jest": "^26.6.3",
25+
"typescript": "^4.4.2"
26+
},
27+
"scripts": {
28+
"test": "yarn lint:types && jest --no-cache",
29+
"lint": "yarn lint:types && yarn lint:ci",
30+
"lint:types": "yarn tsc --noEmit -p .",
31+
"lint:ci": "eslint . --ext .tsx,.ts"
32+
}
33+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { triplets } from './pythagorean-triplet'
2+
3+
type Triplet = [number, number, number]
4+
5+
function tripletsWithSum(sum: number, options = {}): Triplet[] {
6+
return triplets({ ...options, sum }).map((triplet) =>
7+
triplet.toArray().sort((a, b) => a - b)
8+
)
9+
}
10+
11+
describe('Triplet', () => {
12+
test('triplets whose sum is 12', () => {
13+
expect(tripletsWithSum(12)).toEqual([[3, 4, 5]])
14+
})
15+
16+
test('triplets whose sum is 108', () => {
17+
expect(tripletsWithSum(108)).toEqual([[27, 36, 45]])
18+
})
19+
20+
test('triplets whose sum is 1000', () => {
21+
expect(tripletsWithSum(1000)).toEqual([[200, 375, 425]])
22+
})
23+
24+
test('no matching triplets for 1001', () => {
25+
expect(tripletsWithSum(1001)).toEqual([])
26+
})
27+
28+
test('returns all matching triplets', () => {
29+
expect(tripletsWithSum(90)).toEqual([
30+
[9, 40, 41],
31+
[15, 36, 39],
32+
])
33+
})
34+
35+
test('several matching triplets', () => {
36+
expect(tripletsWithSum(840)).toEqual([
37+
[40, 399, 401],
38+
[56, 390, 394],
39+
[105, 360, 375],
40+
[120, 350, 370],
41+
[140, 336, 364],
42+
[168, 315, 357],
43+
[210, 280, 350],
44+
[240, 252, 348],
45+
])
46+
})
47+
48+
test('returns triplets with no factor smaller than minimum factor', () => {
49+
expect(tripletsWithSum(90, { minFactor: 10 })).toEqual([[15, 36, 39]])
50+
})
51+
52+
test('returns triplets with no factor larger than maximum factor', () => {
53+
expect(tripletsWithSum(840, { maxFactor: 349 })).toEqual([[240, 252, 348]])
54+
})
55+
56+
test('returns triplets with factors in range', () => {
57+
expect(tripletsWithSum(840, { maxFactor: 352, minFactor: 150 })).toEqual([
58+
[210, 280, 350],
59+
[240, 252, 348],
60+
])
61+
})
62+
63+
test.skip('triplets for large number', () => {
64+
expect(tripletsWithSum(30000)).toEqual([
65+
[1200, 14375, 14425],
66+
[1875, 14000, 14125],
67+
[5000, 12000, 13000],
68+
[6000, 11250, 12750],
69+
[7500, 10000, 12500],
70+
])
71+
})
72+
})

0 commit comments

Comments
 (0)