Skip to content

Commit

Permalink
第四章 意図を語るテスト
Browse files Browse the repository at this point in the history
  • Loading branch information
say3no committed Nov 4, 2017
1 parent 49b0199 commit c5f5df5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion part01/chap01/Doller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Doller
{
public $amount;
private $amount;

function __construct(int $amount)
{
Expand Down
11 changes: 5 additions & 6 deletions part01/chap01/MoneyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@ class MoneyTest extends \PHPUnit\Framework\TestCase
* TODO: 1. 通貨の異なる2つの金額を足し、通貨感の為替レートにもとづいて換算された金額を得る
* 2. 金額(通貨単位あたりの額)に数値(通貨単位数)を掛け、金額を得る
* ➔ 1ドル100円の時5ドルを円で買う場合、100*5=500となる
* TODO: 2.1. amountをprivateにする
* 2.1. amountをprivateにする
* 2.2. Dollarの副作用どうする?(副作用ってなに)
* TODO: 2.3. Moneyの丸め処理はどうする?
* 2.4. equals()
* TODO: 2.5. hashCode()
* TODO: nullとの透過性比較
* TODO: たのオブジェクトのとの等価性比較
*/

// 1.(足し算)と2.(掛け算)では、掛け算のほうが簡単っぽいので2.から始める
// ➔ 1ドル100円の時5ドルを円で買う場合、100*5=500となる
public function testMultiplication()
{
$five = new Doller(5);
$product = $five->times(2);
$this->assertEquals(10, $product->amount);
$product = $five->times(3);
$this->assertEquals(15, $product->amount);
$this->assertEquals((new Doller(10)), $five->times(2));
$this->assertEquals((new Doller(15)), $five->times(3));
}


// 5ドルオブジェクトはいつでも等価であることを示すテスト
public function testEquality()
{
Expand Down

0 comments on commit c5f5df5

Please sign in to comment.