Skip to content

Commit

Permalink
✨ 【第1章 仮実装】TODOリストの中で一番簡単に実装できなそうな times メソッドのテストを追加
Browse files Browse the repository at this point in the history
<テスト駆動開発(TDD)の流れ>
✅ 1. まずはテストを1つ書く
 2. すべてのテストを走らせ、新しいテストの失敗を確認する
 3. 小さな変更を行う
 4. すべてのテストを走らせ、すべて成功することを確認する
 5. リファクタリングを行って重複を除去する

・問題点は気にせず、まずはテストから書いていくこと
・コンパイルすらできないが、まずはテストから書いていくこと
  • Loading branch information
dodonki1223 committed Dec 6, 2021
1 parent ac99b62 commit 33bbf98
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- [ ] $5 + 10 CHF = $10(レートが 2:1 の場合)
- [ ] $5 * 2 = $10
- [ ] amount を private にする
- [ ] Dollar の副作用どうする?
- [ ] Money の丸め処理どうする?
14 changes: 14 additions & 0 deletions src/__tests__/dollar.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Dollar } from '../dollar';

test('times', () => {
/*
「$5 * 2 = $10」のテスト
現状では以下の問題点あり
・フィールドは public
・コードには副作用がある
・金額なのに int型を使っている
*/
const five = new Dollar(5);
five.times(2)
expect(five.amount).toBe(10);
});

0 comments on commit 33bbf98

Please sign in to comment.