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

Add exercise resistor color #300

Merged
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
11 changes: 11 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
"logic"
]
},
{
"slug": "resistor-color",
"uuid": "c6f41fd5-584c-46ca-b3c5-6a0825446bf4",
"core": true,
"unlocked_by": null,
"difficulty": 1,
"topics": [
"arrays",
"strings"
]
},
{
"slug": "rna-transcription",
"uuid": "b4db381f-1c99-44c6-948c-c8892d77823e",
Expand Down
10 changes: 10 additions & 0 deletions exercises/resistor-color/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
bin/*
dist/*
docs/*
node_modules/*
production_node_modules/*
test/fixtures/*
tmp/*

babel.config.js
jest.config.js
86 changes: 86 additions & 0 deletions exercises/resistor-color/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
// Code style not forced upon the student
"@typescript-eslint/array-type": "off",

// Prevent bugs
"@typescript-eslint/explicit-function-return-type": [
"warn", {
"allowExpressions": false,
"allowTypedFunctionExpressions": true,
"allowHigherOrderFunctions": true
}
],

// Code style not forced upon the student
"@typescript-eslint/explicit-member-accessibility": "off",

// Code style not forced upon the student
"@typescript-eslint/indent": "off",

"@typescript-eslint/no-inferrable-types": [
"error", {
"ignoreParameters": true
}
],

// Code style not forced upon the student
"@typescript-eslint/member-delimiter-style": "off",

// Code style not forced upon the student
"@typescript-eslint/no-non-null-assertion": "off",

// Only disallow readonly without an access modifier
"@typescript-eslint/no-parameter-properties": [
"warn", {
"allows": [
"private", "protected", "public",
"private readonly", "protected readonly", "public readonly"
]
}
],

// Covered by the tsc compiler (noUnusedLocals)
"@typescript-eslint/no-unused-vars": "off",

// Prevent bugs, not styling
"@typescript-eslint/no-use-before-define": [
"error", {
"functions": false,
"typedefs": false
}
],

// Always disable base-rule
"semi": "off",

// Code style not forced upon student
"@typescript-eslint/semi": "off"
}
}
57 changes: 57 additions & 0 deletions exercises/resistor-color/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Resistor Color

Resistors have color coded bands, where each color maps to a number. The first 2 bands of a resistor have a simple encoding scheme: each color maps to a single number.

These colors are encoded as follows:

- Black: 0
- Brown: 1
- Red: 2
- Orange: 3
- Yellow: 4
- Green: 5
- Blue: 6
- Violet: 7
- Grey: 8
- White: 9

Mnemonics map the colors to the numbers, that, when stored as an array, happen to map to their index in the array: Better Be Right Or Your Great Big Values Go Wrong.

More information on the color encoding of resistors can be found in the [Electronic color code Wikipedia article](https://en.wikipedia.org/wiki/Electronic_color_code)

## Setup

Go through the setup instructions for TypeScript to install the necessary
dependencies:

[https://exercism.io/tracks/typescript/installation](https://exercism.io/tracks/typescript/installation)

## Requirements

Install assignment dependencies:

```bash
$ yarn install
```

## Making the test suite pass

Execute the tests with:

```bash
$ yarn test
```

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`.

## Source

https://github.com/exercism/problem-specifications/issues/1458

## Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have
completed the exercise.
20 changes: 20 additions & 0 deletions exercises/resistor-color/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
presets: [
[
"@babel/preset-env",
{
targets: {
node: "current",
},
useBuiltIns: "entry",
corejs: 3,
},
],
"@babel/preset-typescript",
],
plugins: [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
"@babel/plugin-syntax-bigint",
],
}
19 changes: 19 additions & 0 deletions exercises/resistor-color/jest.config.js
Original file line number Diff line number Diff line change
@@ -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",
},
}
34 changes: 34 additions & 0 deletions exercises/resistor-color/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@exercism/typescript",
"description": "Exercism exercises in Typescript.",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/exercism/typescript"
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/preset-env": "^7.12.10",
"@babel/preset-typescript": "^7.12.7",
"@types/jest": "^26.0.19",
"@types/node": "^14.14.13",
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.9.1",
"babel-jest": "^26.6.3",
"core-js": "^3.8.1",
"eslint": "^7.15.0",
"eslint-plugin-import": "^2.22.1",
"jest": "^26.6.3",
"typescript": "^4.1.3"
},
"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"
},
"dependencies": {}
}
3 changes: 3 additions & 0 deletions exercises/resistor-color/resistor-color.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const COLORS = ["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"]

export const colorCode = (color: string): number => COLORS.indexOf(color)
SleeplessByte marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 21 additions & 0 deletions exercises/resistor-color/resistor-color.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { colorCode, COLORS } from './resistor-color'

describe('color code', () => {
it('Black', () => {
expect(colorCode('black')).toEqual(0)
})

xit('White', () => {
expect(colorCode('white')).toEqual(9)
})

xit('Orange', () => {
expect(colorCode('orange')).toEqual(3)
})
SleeplessByte marked this conversation as resolved.
Show resolved Hide resolved
})

describe('Colors', () => {
xit('returns all colors', () => {
expect(COLORS).toEqual(["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"])
})
})
5 changes: 5 additions & 0 deletions exercises/resistor-color/resistor-color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const colorCode = () => {
throw new Error('Delete this line and implement this function')
}

export const COLORS = undefined;
65 changes: 65 additions & 0 deletions exercises/resistor-color/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["esnext", "es2016", "es2017"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./build", /* Redirect output structure to the directory. */
// "rootDirs": ["./"], /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
"isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
// "noEmitOnError": true, /* Do not emit outputs when compilation fails. */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": { "~src/*": ["./src/*"] }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"compileOnSave": true,
"exclude": [
"node_modules"
]
}
Loading