Skip to content

Allow skipping tests #62

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

Merged
merged 3 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ yarn-error.log
/out
/production_node_modules
/package.template.json

# Fixture development files
/test/fixtures/**/node_modules
/test/fixtures/**/package-lock.json
/test/fixtures/**/results.json
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.5.0

- Allow skipping/pending tests (`test.skip`)

## 2.4.0

- Update dependencies
Expand Down
3 changes: 2 additions & 1 deletion bin/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
test_file="$1$2"
test_file=${test_file//$'\r'}

abs_file=$(realpath $test_file)

if test -f "$test_file"; then
if test -f "$abs_file"; then
# Change xtest to test so all tests are run
if [[ "$OSTYPE" == "darwin"* ]]; then # Mac OS X
# BSD sed -i takes an extra parameter to specify the backup file extension
Expand Down
12 changes: 6 additions & 6 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ SETUP="$ROOT/dist/jest/setup.js"

if test -f "$REPORTER"; then
echo "Using reporter : $REPORTER"
echo "Using test root: $INPUT -> $OUTPUT"
echo "Using runner root: $ROOT"
echo "Using runner setup: $SETUP"
echo "Using test-root: $INPUT"
echo "Using base-root: $ROOT"
echo "Using setup-env: $SETUP"

echo ""
else
>&2 echo "Expected reporter.js to exist. Did you forget to yarn build first?"
>&2 echo "Using reporter : $REPORTER"
>&2 echo "Using test root: $INPUT -> $OUTPUT"
>&2 echo "Using runner root: $ROOT"
>&2 echo "Using runner setup: $SETUP"
>&2 echo "Using test-root: $INPUT"
>&2 echo "Using base-root: $ROOT"
>&2 echo "Using setup-env: $SETUP"
>&2 echo ""
>&2 echo "The following files exist in the dist folder (build output):"
>&2 echo $(ls $ROOT/dist)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@exercism/javascript-test-runner",
"description": "Automated Test runner for exercism solutions in Javascript.",
"author": "Derk-Jan Karrenbeld <derk-jan+github@karrenbeld.info>",
"version": "2.4.0",
"version": "2.5.0",
"license": "AGPL-3.0-or-later",
"repository": {
"type": "git",
Expand Down
6 changes: 5 additions & 1 deletion src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export class Output {
this.results.status =
aggregatedResults.numRuntimeErrorTestSuites === 0 &&
aggregatedResults.numFailedTestSuites === 0 &&
aggregatedResults.numPendingTests === 0 &&
// Pending tests are skipped tests. test.skip tests are fine in our
// reporter and should not be forced to have ran here. So the next
// line is commented out.
//
// aggregatedResults.numPendingTests === 0 &&
aggregatedResults.numFailedTests === 0
? 'pass'
: 'fail'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Instructions

A Pythagorean triplet is a set of three natural numbers, {a, b, c}, for
which,

```text
a**2 + b**2 = c**2
```

and such that,

```text
a < b < c
```

For example,

```text
3**2 + 4**2 = 9 + 16 = 25 = 5**2.
```

Given an input integer N, find all Pythagorean triplets for which `a + b + c = N`.

For example, with N = 1000, there is exactly one Pythagorean triplet for which `a + b + c = 1000`: `{200, 375, 425}`.
12 changes: 12 additions & 0 deletions test/fixtures/pythagorean-triplet/exemplar/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
!.meta

# Protected or generated
.git
.vscode

# When using npm
node_modules/*

# Configuration files
babel.config.js
jest.config.js
14 changes: 14 additions & 0 deletions test/fixtures/pythagorean-triplet/exemplar/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"root": true,
"extends": "@exercism/eslint-config-javascript",
"env": {
"jest": true
},
"overrides": [
{
"files": [".meta/proof.ci.js", ".meta/exemplar.js", "*.spec.js"],
"excludedFiles": ["custom.spec.js"],
"extends": "@exercism/eslint-config-javascript/maintainers"
}
]
}
19 changes: 19 additions & 0 deletions test/fixtures/pythagorean-triplet/exemplar/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"blurb": "There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product a * b * c.",
"authors": ["matthewmorgan"],
"contributors": [
"ankorGH",
"rchavarria",
"ryanplusplus",
"SleeplessByte",
"tejasbubane",
"xarxziux"
],
"files": {
"solution": ["pythagorean-triplet.js"],
"test": ["pythagorean-triplet.spec.js"],
"example": [".meta/proof.ci.js"]
},
"source": "Problem 9 at Project Euler",
"source_url": "http://projecteuler.net/problem=9"
}
49 changes: 49 additions & 0 deletions test/fixtures/pythagorean-triplet/exemplar/.meta/proof.ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class Triplet {
constructor(a, b, c) {
this.a = a
this.b = b
this.c = c
}

toArray() {
return [this.a, this.b, this.c]
}

get pythagorean() {
return this.a * this.a + this.b * this.b === this.c * this.c
}

get sum() {
return this.a + this.b + this.c
}
}

export function triplets({ minFactor, maxFactor, sum }) {
const min = minFactor || 1
const max = maxFactor || sum - 1

const isDesired = (triplet) => {
return triplet.pythagorean && (!sum || triplet.sum === sum)
}

const result = []
const squared_map = {}

for (let a = min; a < max; a += 1) {
squared_map[a * a] = a
}

for (let a = min; a < max - 1; a += 1) {
for (let b = a + 1; b < max; b += 1) {
const c = a * a + b * b
if (squared_map[c]) {
const triplet = new Triplet(a, b, squared_map[c])
if (isDesired(triplet)) {
result.push(triplet)
}
}
}
}

return result
}
24 changes: 24 additions & 0 deletions test/fixtures/pythagorean-triplet/exemplar/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.

[a19de65d-35b8-4480-b1af-371d9541e706]
description = "triplets whose sum is 12"

[48b21332-0a3d-43b2-9a52-90b2a6e5c9f5]
description = "triplets whose sum is 108"

[dffc1266-418e-4daa-81af-54c3e95c3bb5]
description = "triplets whose sum is 1000"

[5f86a2d4-6383-4cce-93a5-e4489e79b186]
description = "no matching triplets for 1001"

[bf17ba80-1596-409a-bb13-343bdb3b2904]
description = "returns all matching triplets"

[9d8fb5d5-6c6f-42df-9f95-d3165963ac57]
description = "several matching triplets"

[f5be5734-8aa0-4bd1-99a2-02adcc4402b4]
description = "triplets for large number"
15 changes: 15 additions & 0 deletions test/fixtures/pythagorean-triplet/exemplar/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
useBuiltIns: 'entry',
corejs: '3.18',
},
],
],
plugins: ['@babel/plugin-syntax-bigint'],
}
31 changes: 31 additions & 0 deletions test/fixtures/pythagorean-triplet/exemplar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@exercism/javascript-pythagorean-triplet",
"description": "Exercism exercises in Javascript.",
"author": "Katrina Owen",
"private": true,
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/exercism/javascript",
"directory": "exercises/practice/pythagorean-triplet"
},
"devDependencies": {
"@babel/cli": "^7.15.7",
"@babel/core": "^7.15.5",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/preset-env": "^7.15.6",
"@exercism/eslint-config-javascript": "^0.5.0",
"@types/jest": "^26.0.24",
"@types/node": "^16.10.2",
"babel-jest": "^27.2.4",
"core-js": "^3.18.1",
"eslint": "^7.32.0",
"jest": "^26.6.3"
},
"dependencies": {},
"scripts": {
"test": "jest --no-cache ./*",
"watch": "jest --no-cache --watch ./*",
"lint": "eslint ."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class Triplet {
constructor(a, b, c) {
this.a = a;
this.b = b;
this.c = c;
}

toArray() {
return [this.a, this.b, this.c];
}

get pythagorean() {
return this.a * this.a + this.b * this.b === this.c * this.c;
}

get sum() {
return this.a + this.b + this.c;
}
}

export function triplets({ minFactor, maxFactor, sum }) {
const min = minFactor || 1;
const max = maxFactor || sum - 1;

const isDesired = (triplet) => {
return triplet.pythagorean && (!sum || triplet.sum === sum);
};

const result = [];
const squared_map = {};

for (let a = min; a < max; a += 1) {
squared_map[a * a] = a;
}

for (let a = min; a < max - 1; a += 1) {
for (let b = a + 1; b < max; b += 1) {
const c = a * a + b * b;
if (squared_map[c]) {
const triplet = new Triplet(a, b, squared_map[c]);
if (isDesired(triplet)) {
result.push(triplet);
}
}
}
}

return result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { triplets } from './pythagorean-triplet';

function tripletsWithSum(sum, options = {}) {
return triplets({ ...options, sum }).map((triplet) =>
triplet.toArray().sort((a, b) => a - b)
);
}

describe('Triplet', () => {
test('triplets whose sum is 12', () => {
expect(tripletsWithSum(12)).toEqual([[3, 4, 5]]);
});

xtest('triplets whose sum is 108', () => {
expect(tripletsWithSum(108)).toEqual([[27, 36, 45]]);
});

xtest('triplets whose sum is 1000', () => {
expect(tripletsWithSum(1000)).toEqual([[200, 375, 425]]);
});

xtest('no matching triplets for 1001', () => {
expect(tripletsWithSum(1001)).toEqual([]);
});

xtest('returns all matching triplets', () => {
expect(tripletsWithSum(90)).toEqual([
[9, 40, 41],
[15, 36, 39],
]);
});

xtest('several matching triplets', () => {
expect(tripletsWithSum(840)).toEqual([
[40, 399, 401],
[56, 390, 394],
[105, 360, 375],
[120, 350, 370],
[140, 336, 364],
[168, 315, 357],
[210, 280, 350],
[240, 252, 348],
]);
});

xtest('returns triplets with no factor smaller than minimum factor', () => {
expect(tripletsWithSum(90, { minFactor: 10 })).toEqual([[15, 36, 39]]);
});

xtest('returns triplets with no factor larger than maximum factor', () => {
expect(tripletsWithSum(840, { maxFactor: 349 })).toEqual([[240, 252, 348]]);
});

xtest('returns triplets with factors in range', () => {
expect(tripletsWithSum(840, { maxFactor: 352, minFactor: 150 })).toEqual([
[210, 280, 350],
[240, 252, 348],
]);
});

test.skip('triplets for large number', () => {
expect(tripletsWithSum(30000)).toEqual([
[1200, 14375, 14425],
[1875, 14000, 14125],
[5000, 12000, 13000],
[6000, 11250, 12750],
[7500, 10000, 12500],
]);
});
});
Loading