This commit is contained in:
2022-11-05 17:20:19 +01:00
parent d9c3eafba1
commit 942e6bba84
13 changed files with 16381 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
!.meta
# Protected or generated
.git
.vscode
# When using npm
node_modules/*
# Configuration files
.eslintrc.cjs
babel.config.cjs
jest.config.cjs
+41
View File
@@ -0,0 +1,41 @@
module.exports = {
root: true,
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
overrides: [
// Student provided files
{
files: ['*.ts'],
excludedFiles: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
extends: '@exercism/eslint-config-typescript',
},
// Exercism given tests
{
files: ['*.test.ts'],
excludedFiles: ['custom.test.ts'],
env: {
jest: true,
},
extends: '@exercism/eslint-config-typescript/maintainers',
},
// Student provided tests
{
files: ['custom.test.ts'],
env: {
jest: true,
},
extends: '@exercism/eslint-config-typescript',
},
// Exercism provided files
{
files: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
excludedFiles: ['custom.test.ts'],
extends: '@exercism/eslint-config-typescript/maintainers',
rules: {
"@typescript-eslint/semi": 0,
},
},
],
}
+18
View File
@@ -0,0 +1,18 @@
{
"blurb": "Bob is a lackadaisical teenager. In conversation, his responses are very limited.",
"authors": ["masters3d"],
"contributors": [
"amscotti",
"DFXLuna",
"kytrinyx",
"lukaszklis",
"SleeplessByte"
],
"files": {
"solution": ["bob.ts"],
"test": ["bob.test.ts"],
"example": [".meta/proof.ci.ts"]
},
"source": "Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial.",
"source_url": "http://pine.fm/LearnToProgram/?Chapter=06"
}
+1
View File
@@ -0,0 +1 @@
{"track":"typescript","exercise":"bob","id":"48a2f27edfa24d61a7c0b0620dc2bce8","url":"https://exercism.org/tracks/typescript/exercises/bob","handle":"briemens","is_requester":true,"auto_approve":false}
+44
View File
@@ -0,0 +1,44 @@
# Help
## Running the tests
Execute the tests with:
```bash
$ yarn test
```
## Skipped tests
In the test suites all tests but the first have been skipped.
Once you get a test passing, you can enable the next one by changing `xit` to
`it`.
## Submitting your solution
You can submit your solution using the `exercism submit bob.ts` command.
This command will upload your solution to the Exercism website and print the solution page's URL.
It's possible to submit an incomplete solution which allows you to:
- See how others have completed the exercise
- Request help from a mentor
## Need to get help?
If you'd like help solving the exercise, check the following pages:
- The [TypeScript track's documentation](https://exercism.org/docs/tracks/typescript)
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
To get help if you're having trouble, you can use one of the following resources:
- [TypeScript QuickStart](https://www.typescriptlang.org/docs/handbook/release-notes/overview.html)
- [ECMAScript 2015 Language Specification](https://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2015.pdf) (pdf)
- [Mozilla JavaScript Reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference)
- [/r/typescript](https://www.reddit.com/r/typescript) is the TypeScript subreddit.
- [StackOverflow](https://stackoverflow.com/questions/tagged/typescript) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
+39
View File
@@ -0,0 +1,39 @@
# Bob
Welcome to Bob on Exercism's TypeScript Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Instructions
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
Bob answers 'Sure.' if you ask him a question, such as "How are you?".
He answers 'Whoa, chill out!' if you YELL AT HIM (in all capitals).
He answers 'Calm down, I know what I'm doing!' if you yell a question at him.
He says 'Fine. Be that way!' if you address him without actually saying
anything.
He answers 'Whatever.' to anything else.
Bob's conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English.
## Source
### Created by
- @masters3d
### Contributed to by
- @amscotti
- @DFXLuna
- @kytrinyx
- @lukaszklis
- @SleeplessByte
### Based on
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. - http://pine.fm/LearnToProgram/?Chapter=06
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
presets: ['@exercism/babel-preset-typescript'],
plugins: [],
}
+123
View File
@@ -0,0 +1,123 @@
import { hey } from "./bob";
describe("Bob", () => {
it("stating something", () => {
const result = hey("Tom-ay-to, tom-aaaah-to.");
expect(result).toEqual("Whatever.");
});
it("shouting", () => {
const result = hey("WATCH OUT!");
expect(result).toEqual("Whoa, chill out!");
});
it("shouting gibberish", () => {
const result = hey("FCECDFCAAB");
expect(result).toEqual("Whoa, chill out!");
});
it("asking a question", () => {
const result = hey("Does this cryogenic chamber make me look fat?");
expect(result).toEqual("Sure.");
});
it("asking a numeric question", () => {
const result = hey("You are, what, like 15?");
expect(result).toEqual("Sure.");
});
it("asking gibberish", () => {
const result = hey("fffbbcbeab?");
expect(result).toEqual("Sure.");
});
it("talking forcefully", () => {
const result = hey("Let's go make out behind the gym!");
expect(result).toEqual("Whatever.");
});
it("using acronyms in regular speech", () => {
const result = hey("It's OK if you don't want to go to the DMV.");
expect(result).toEqual("Whatever.");
});
it("forceful question", () => {
const result = hey("WHAT THE HELL WERE YOU THINKING?");
expect(result).toEqual("Calm down, I know what I'm doing!");
});
it("shouting numbers", () => {
const result = hey("1, 2, 3 GO!");
expect(result).toEqual("Whoa, chill out!");
});
it("no letters", () => {
const result = hey("1, 2, 3");
expect(result).toEqual("Whatever.");
});
it("question with no letters", () => {
const result = hey("4?");
expect(result).toEqual("Sure.");
});
it("shouting with special characters", () => {
const result = hey("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!");
expect(result).toEqual("Whoa, chill out!");
});
it("shouting with no exclamation mark", () => {
const result = hey("I HATE THE DMV");
expect(result).toEqual("Whoa, chill out!");
});
it("statement containing question mark", () => {
const result = hey("Ending with ? means a question.");
expect(result).toEqual("Whatever.");
});
it("prattling on", () => {
const result = hey("Wait! Hang on. Are you going to be OK?");
expect(result).toEqual("Sure.");
});
it("silence", () => {
const result = hey("");
expect(result).toEqual("Fine. Be that way!");
});
it("prolonged silence", () => {
const result = hey(" ");
expect(result).toEqual("Fine. Be that way!");
});
it("alternate silence", () => {
const result = hey("\t\t\t\t\t\t\t\t\t\t");
expect(result).toEqual("Fine. Be that way!");
});
it("multiple line question", () => {
const result = hey("\nDoes this cryogenic chamber make me look fat?\nNo.");
expect(result).toEqual("Whatever.");
});
it("starting with whitespace", () => {
const result = hey(" hmmmmmmm...");
expect(result).toEqual("Whatever.");
});
it("ending with whitespace", () => {
const result = hey("Okay if like my spacebar quite a bit? ");
expect(result).toEqual("Sure.");
});
it("other whitespace", () => {
const result = hey("\n\r \t");
expect(result).toEqual("Fine. Be that way!");
});
it("non-question ending with whitespace", () => {
const result = hey("This is a statement ending with whitespace ");
expect(result).toEqual("Whatever.");
});
});
+24
View File
@@ -0,0 +1,24 @@
const isQuestion = (message: string): boolean => message.trim().endsWith("?");
const hasUpperCase = (message: string): boolean =>
Boolean(message.match(/[A-Z]/));
const hasLowerCase = (message: string): boolean =>
Boolean(message.match(/[a-z]/));
const isOnlyUpperCase = (message: string): boolean =>
hasUpperCase(message) && !hasLowerCase(message);
const isEmpty = (message: string): boolean => message.trim() === "";
export function hey(message: string): string {
if (isQuestion(message)) {
if (isOnlyUpperCase(message)) {
return "Calm down, I know what I'm doing!";
}
return "Sure.";
}
if (isOnlyUpperCase(message)) {
return "Whoa, chill out!";
}
if (isEmpty(message)) {
return "Fine. Be that way!";
}
return "Whatever.";
}
+19
View File
@@ -0,0 +1,19 @@
module.exports = {
verbose: true,
projects: ['<rootDir>'],
testMatch: [
'**/__tests__/**/*.[jt]s?(x)',
'**/test/**/*.[jt]s?(x)',
'**/?(*.)+(spec|test).[jt]s?(x)',
],
testPathIgnorePatterns: [
'/(?:production_)?node_modules/',
'.d.ts$',
'<rootDir>/test/fixtures',
'<rootDir>/test/helpers',
'__mocks__',
],
transform: {
'^.+\\.[jt]sx?$': 'babel-jest',
},
}
+15996
View File
File diff suppressed because it is too large Load Diff
+31
View File
@@ -0,0 +1,31 @@
{
"name": "@exercism/typescript-bob",
"version": "1.0.0",
"description": "Exercism exercises in Typescript.",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/exercism/typescript"
},
"type": "module",
"engines": {
"node": "^14.13.1 || >=16.0.0"
},
"devDependencies": {
"@exercism/babel-preset-typescript": "^0.1.0",
"@exercism/eslint-config-typescript": "^0.4.1",
"@types/jest": "^27.4.0",
"@types/node": "^16.11.24",
"babel-jest": "^27.5.1",
"core-js": "^3.21.0",
"eslint": "^8.9.0",
"jest": "^27.5.1",
"typescript": "^4.5.4"
},
"scripts": {
"test": "yarn lint:types && jest --no-cache",
"lint": "yarn lint:types && yarn lint:ci",
"lint:types": "yarn tsc --noEmit -p .",
"lint:ci": "eslint . --ext .tsx,.ts"
}
}
+28
View File
@@ -0,0 +1,28 @@
{
"display": "Configuration for Exercism TypeScript Exercises",
"compilerOptions": {
// Allows you to use the newest syntax, and have access to console.log
// https://www.typescriptlang.org/tsconfig#lib
"lib": ["ESNEXT", "dom"],
// Make sure typescript is configured to output ESM
// https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm
"module": "ES2020",
// Since this project is using babel, TypeScript may target something very
// high, and babel will make sure it runs on your local Node version.
// https://babeljs.io/docs/en/
"target": "ESNext", // ESLint doesn't support this yet: "es2022",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
// Because we'll be using babel: ensure that Babel can safely transpile
// files in the TypeScript project.
//
// https://babeljs.io/docs/en/babel-plugin-transform-typescript/#caveats
"isolatedModules": true
},
"include": ["*.ts", "*.tsx", ".meta/*.ts", ".meta/*.tsx"],
"exclude": ["node_modules"]
}