Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
e8b8a89
add package.json
akiray03 Jan 10, 2021
067c630
Add eslint and prettier
akiray03 Jan 10, 2021
caf0b40
jest を追加
akiray03 Jan 10, 2021
66e8ded
カフェランチ chapter1 の最初のステップを追加
akiray03 Jan 10, 2021
4734921
chapter1 カフェの例に name を追加
akiray03 Jan 10, 2021
2432592
chapter1 ポーカーの例を実装
akiray03 Jan 10, 2021
e03dbd9
1行80文字で改行する
akiray03 Feb 12, 2021
472754f
chapter2 ランチプレートの例 (割引クラス等) を実装
akiray03 Feb 12, 2021
eee5e31
chapter2 ポーカーの例を実装
akiray03 Feb 14, 2021
d4784eb
chapter2 ポーカーのオブジェクト作成例のコードを追加
akiray03 Feb 14, 2021
ee8ea7f
DishCollection を追加
akiray03 Mar 7, 2021
2612e99
バランス配慮セット割引の料理を特定する処理を2つのバリエーションで実装
akiray03 Mar 20, 2021
f76a96b
DishCollection 利用例を実装
akiray03 Mar 21, 2021
6fdcb4d
Hand, Card, Rank, Suit をリファクタリング & テストケース追加
akiray03 Apr 10, 2021
63d9ccd
Rankコンストラクタで値の範囲をチェックする
akiray03 Apr 10, 2021
7f4bf89
Rankを強い順に並び替える
akiray03 Apr 10, 2021
857a8f8
Suitを強い順に並び替える
akiray03 Apr 10, 2021
6cd22b0
Cardを強さ順にソートする
akiray03 Apr 10, 2021
b78a8f3
Hand の一致比較を実装
akiray03 Apr 10, 2021
35223fa
旧実装を一度コメントアウト
akiray03 Apr 10, 2021
9308413
役の一部を構成する要素オブジェクトを実装
akiray03 Apr 10, 2021
5a0a8ec
Cardに同ランクであることをチェックするisSameRank() を追加
akiray03 Apr 10, 2021
9076650
OnePairPokerHand, TwoPairPokerHand を実装
akiray03 Apr 10, 2021
75a7955
PairにisSameRank() を実装してリファクタリング
akiray03 Apr 10, 2021
1935034
スリーカードの役を実装
akiray03 Apr 10, 2021
a9c6db4
フルハウスの役を実装
akiray03 Apr 10, 2021
334b219
OnePairPokerHand の強弱を比較できるようにする
akiray03 Apr 10, 2021
b10072c
TwoPair の役同士の強さ比較を実装
akiray03 Apr 10, 2021
590efc9
ThreeCardの役同士の比較を実装
akiray03 Apr 10, 2021
c4e577d
FullHouseの役同士の比較を実装
akiray03 Apr 10, 2021
9667082
IPokerHand に name プロパティを追加
akiray03 Apr 10, 2021
d29ba27
PokerHandCollection を実装
akiray03 Apr 10, 2021
2d5d9b5
HandがCardの配列ではなくCardCollectionを保持するように変更
akiray03 Apr 10, 2021
ba12b43
PokerHandCollectionFactoryを実装
akiray03 Apr 10, 2021
66f5985
Pair の引数の順番によらず、組み合わせのみで一致判定する
akiray03 Apr 11, 2021
513552e
太郎、次郎の手札からポーカーの役を導く処理をテストケースとして記述
akiray03 Apr 11, 2021
5805e93
太郎、次郎の役の候補に対するテストケースを追加
akiray03 Apr 11, 2021
3b2497c
Plateオブジェクトが DishCollection を保持するように変更
akiray03 Apr 11, 2021
1cf8524
DishCollection, Price などを充実させる
akiray03 Apr 11, 2021
daa2154
DiscountAmount のテストを追加
akiray03 Apr 11, 2021
87435de
ランチ 割引の実装を一旦コメントアウト
akiray03 Apr 11, 2021
7547947
Discount, DiscountCollection, Factory を実装
akiray03 Apr 11, 2021
51041f0
DishCollection の栄養合計を計算する
akiray03 Apr 11, 2021
4af358a
旧実装を削除
akiray03 Apr 11, 2021
f1343f5
太郎と次郎のランチプレートから、割引コレクションをFactoryで作成する
akiray03 Apr 11, 2021
44d0ff0
Orderオブジェクトを実装
akiray03 Apr 12, 2021
402afcc
ランチプレートのサンプルで未使用のサンプルクラスを削除
akiray03 Apr 12, 2021
a014b67
PlateとDishCollectionの toString() を整理
akiray03 Apr 12, 2021
1b5df13
Rank に isStrongerThan() を実装
akiray03 Apr 14, 2021
18bf4a9
Card に isStrongerThan() を実装
akiray03 Apr 14, 2021
3937c31
Pair のコンストラクタでカードの強い順に並び替える処理を整理
akiray03 Apr 14, 2021
7f3f850
Triple のコンストラクタでカードの強い順に並び替える
akiray03 Apr 14, 2021
4e26ca1
Chapter2 完了時のポーカーの解答例を実装
akiray03 Apr 14, 2021
aa4dd72
Pair, Triple を利用しない形で OnePair, ThreeCard を構成する
akiray03 Apr 14, 2021
e81b496
Chapter2 ポーカー解答例の取りうる役を全て列挙する
akiray03 Apr 14, 2021
8c96edf
FullHousePokerHandFactory で 2枚と3枚 の組であることをチェックする
akiray03 Apr 18, 2021
7b6ad0b
Rename PokerHandName -> PokerHandType
akiray03 Apr 18, 2021
b950117
未知のSuitが指定されたときに例外を投げるようにする
akiray03 Apr 18, 2021
5c372ab
CardCollection を Card の強さ順に並び替える & 一致比較をソート済みであることを前提に書き換える
akiray03 Apr 18, 2021
cec5cf7
ignore .idea directory
akiray03 May 4, 2021
f27d051
AvailableDiscountCollection と finxMaxDiscount() を実装
akiray03 May 4, 2021
28d91a0
Discount#amount() を (いったん) number に変更
akiray03 May 4, 2021
84468e3
割引金額の計算処理を実装
akiray03 May 5, 2021
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.eslintrc.js
78 changes: 78 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"use strict";

module.exports = {
root: true,
env: {
browser: true,
node: true,
es6: true,
},

parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module",
project: "./tsconfig.json",
tsconfigRootDir: __dirname, // TODO: https://github.com/typescript-eslint/typescript-eslint/issues/251
useJSXTextNode: true,
},

plugins: ["@typescript-eslint", "prettier" ],

extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier",
],

rules: {
"prettier/prettier": [
"warn",
{
bracketSpacing: true,
printWidth: 80,
singleQuote: true,
tabWidth: 4,
trailingComma: "es5", // EcmaScript5 において、validな場合には末尾カンマを許可する
arrowParens: "always", // アロー関数の引数に対する括弧を必須にする
useTabs: false,
jsxBracketSameLine: false,
parser: "typescript",
},
],
"@typescript-eslint/no-namespace": "off",
// '@typescript-eslint/indent': 'off',
// '@typescript-eslint/interface-name-prefix': ['warn', 'always'],
// '@typescript-eslint/no-empty-interface': 'off',
// '@typescript-eslint/no-object-literal-type-assertion': 'off',
// '@typescript-eslint/no-unused-vars': 'warn',
// '@typescript-eslint/no-explicit-any': 'off',
// "@typescript-eslint/no-empty-function": [2, {"allow": ["arrowFunctions", "constructors"]}],
// // 'no-console': ['warn', { allow: ['error', 'warn'] }],
// // TSLintの例外対応
// '@typescript-eslint/array-type': 'warn', // 配列を[]で定義(Array<>は許可しない)
// '@typescript-eslint/camelcase': 'off', // キャメルケースを許可しない
// '@typescript-eslint/explicit-function-return-type': ['off'], // 関数の戻り値の型の指定
// '@typescript-eslint/explicit-member-accessibility': 'warn', // TODO: https://github.com/typescript-eslint/typescript-eslint/issues/214
// 'import/no-extraneous-dependencies': 'off', // package.jsonのdevDependencies import問題
// 'import/no-unresolved': 'off', // TODO: aliasの時だけ拡張子が解決出来ずエラーになるので対策
// 'import/order': 'off', // importの順序
// 'import/prefer-default-export': 'off', // exportが1つしかない場合はdefaultにする
// 'no-irregular-whitespace': ['error', { skipRegExps: true }], // 正規表現のみスペースの使用を許可する
// 'no-nested-ternary': 'off', // 三項演算子のネストを許可しない
},

settings: {
propWrapperFunctions: [
// The names of any function used to wrap propTypes, e.g. `forbidExtraProps`. If this isn't set, any propTypes wrapped in a function will be skipped.
"forbidExtraProps",
{ property: "freeze", object: "Object" },
{ property: "myFavoriteWrapper" },
],
linkComponents: [
// Components used as alternatives to <a> for linking, eg. <Link to={ url } />
"Hyperlink",
{ name: "Link", linkAttribute: "to" },
],
},
};
119 changes: 119 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@

# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test
.env*.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# End of https://www.toptal.com/developers/gitignore/api/node

# JetBrains IDE
.idea/
55 changes: 55 additions & 0 deletions cafe/chapter1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Dish, Nutrition, Plate, Price } from './index';

describe('チャプター1', () => {
it('Price', () => {
const price = new Price(150);
expect(price.toString()).toEqual('Price(150円)');
});

it('Nutrition', () => {
const nutrition = new Nutrition(1, 2, 3);
expect(nutrition.toString()).toEqual('Nutrition(赤:1, 緑:2, 黄:3)');
});

it('Dish', () => {
const pasta = new Dish(
'パスタ&サラダ',
new Price(250),
new Nutrition(1, 1, 3)
);
expect(pasta.toString()).toEqual(
'Dish(パスタ&サラダ, Nutrition(赤:1, 緑:1, 黄:3), Price(250円))'
);
});

it('太郎のプレート', () => {
const pasta = new Dish(
'パスタ&ランチ',
new Price(250),
new Nutrition(1, 1, 3)
);
const bread = new Dish(
'くるみパン',
new Price(150),
new Nutrition(0, 0, 3)
);
const dessert = new Dish(
'フルーツ',
new Price(150),
new Nutrition(0, 1, 0)
);
const taroPlate = new Plate('太郎のプレート', [pasta, bread, dessert]);

expect(taroPlate).toBeInstanceOf(Plate);
expect(taroPlate.dishItems()).toHaveLength(3);
expect(taroPlate.toString()).toEqual(
`Plate 太郎のプレート
DishCollection(
Dish(パスタ&ランチ, Nutrition(赤:1, 緑:1, 黄:3), Price(250円)),
Dish(くるみパン, Nutrition(赤:0, 緑:0, 黄:3), Price(150円)),
Dish(フルーツ, Nutrition(赤:0, 緑:1, 黄:0), Price(150円))
)`
);
// expect(taroPlate.dishes[0]).toEqual('パスタ&サラダ');
});
});
55 changes: 55 additions & 0 deletions cafe/chapter2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Discount, DiscountName, Dish, Nutrition, Plate, Price } from './index';

it('Chapter2: カフェ (太郎のプレート)', () => {
const pasta = new Dish(
'パスタ&ランチ',
new Price(250),
new Nutrition(1, 1, 3)
);
const bread = new Dish(
'くるみパン',
new Price(150),
new Nutrition(0, 0, 3)
);
const dessert = new Dish(
'フルーツ',
new Price(150),
new Nutrition(0, 1, 0)
);
const taroPlate = new Plate('太郎のプレート', [pasta, bread, dessert]);

const taroDiscounts_1 = [
new Discount(DiscountName.LowCarbon, taroPlate),
new Discount(DiscountName.NiceCalorie, taroPlate),
new Discount(DiscountName.NutritionGoodBalance, taroPlate),
];

// const taroDiscounts_2 = [
// new LowCarbonDiscount(taroPlate),
// new NiceCalorieDiscount(taroPlate),
// new NutritionBalanceDiscount(taroPlate),
// ];

// 太郎のプレートに対する割引の候補の中から、有効なものだけを取り出す
// taroDiscounts_2.filter((discount) => discount.available());
});

it('Chapter2: カフェ (次郎のプレート)', () => {
const pasta = new Dish(
'パスタ&ランチ',
new Price(250),
new Nutrition(1, 1, 3)
);
// FIXME: パンの種類を変える
const bread = new Dish(
'くるみパン',
new Price(150),
new Nutrition(0, 0, 3)
);
const dessert = new Dish(
'フルーツ',
new Price(150),
new Nutrition(0, 1, 0)
);
const taroPlate = new Plate('太郎のプレート', [pasta, bread, dessert]);
});
Loading