File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22著書「テスト駆動開発」の第1章〜第17章の写経をrustで書いたものです。
33
44- [ 書籍「テスト駆動開発」をRustで書く #1 (chapter1...3)] ( https://qiita.com/Khigashiguchi/items/dfc382d9d2f988522721 )
5- - [ 書籍「テスト駆動開発」をRustで書く #2 (chapter4...11)] ( )
5+ - [ 書籍「テスト駆動開発」をRustで書く #2 (chapter4...11)] ( https://qiita.com/Khigashiguchi/items/6041308a46b30e849648 )
6+ - [ 書籍「テスト駆動開発」をRustで書く #3 (chapter7...11)] ( https://qiita.com/Khigashiguchi/items/61ffa5da34d957df01f1 )
67
7- # Chapters
8+ # 著書内容
9+ ## Chapters
810
911- Chapter/1 仮実装
1012- Chapter/2 明白な実装
1820- Chapter/10 テストに聞いてみる
1921- Chapter/11 不要になったら消す
2022
21- ## TODO LIST in Chapters
22- - [ ] $5 + 10CHF = $10
23- - [ x] $5 * 2 = $10
24- - [ x] amountをprivateにする(すでにprivateだった)
25- - [ x] Dollarの副作用どうする
26- - [ ] Moneyの丸め処理どうする
27- - [ x] equals()の実装
28- - [ ] hashCode()の実装
29- - [ ] nullとの等価性比較
30- - [ ] 他のオブジェクトとの等価性比較
31- - [ x] 5CHF * 2 = 10CHF
32- - [ x] DollarとFrancの重複
33- - [ x] equalsの一般化
34- - [ x] timesの一般化
35- - [ x] FrancとDollarを比較する
36- - [ x] 通貨の概念
37- - [ x] testFrancMultiplicationを削除する?
23+ ### TODO LIST in Chapters
24+ 著書内でTDD進めていく際のTODOリストです。
25+
26+ #### TODO After chapter/12
27+ - [ ] $5 + 10CHF = $10
28+ - [ ] $5 + $5 = $10
29+
30+ #### TODO Before chapter/11
31+ - [ ] $5 + 10CHF = $10
32+ - [x] $5 * 2 = $10
33+ - [x] amountをprivateにする(すでにprivateだった)
34+ - [x] Dollarの副作用どうする
35+ - [ ] Moneyの丸め処理どうする
36+ - [x] equals()の実装
37+ - [ ] hashCode()の実装
38+ - [ ] nullとの等価性比較
39+ - [ ] 他のオブジェクトとの等価性比較
40+ - [x] 5CHF * 2 = 10CHF
41+ - [x] DollarとFrancの重複
42+ - [x] equalsの一般化
43+ - [x] timesの一般化
44+ - [x] FrancとDollarを比較する
45+ - [x] 通貨の概念
46+ - [x] testFrancMultiplicationを削除する?
Original file line number Diff line number Diff line change 11use std:: ops:: Mul ;
2+ use std:: ops:: Add ;
3+
4+ pub trait Bank {
5+ fn reduce ( source : Money , to : & ' static str ) -> Money ;
6+ }
27
38#[ derive( Debug ) ]
49pub struct Money {
@@ -41,6 +46,25 @@ impl Mul<u32> for Money {
4146 }
4247}
4348
49+ impl Add for Money {
50+ type Output = Self ;
51+
52+ fn add ( self , other : Self ) -> Self {
53+ Self {
54+ amount : self . amount + other. amount ,
55+ currency : self . currency
56+ }
57+ }
58+ }
59+
60+ impl Bank for Money {
61+ fn reduce ( source : Self , to : & ' static str ) -> Self {
62+ Self {
63+ amount : 10 ,
64+ currency : "USD"
65+ }
66+ }
67+ }
4468#[ cfg( test) ]
4569mod tests {
4670 use super :: * ;
@@ -62,4 +86,10 @@ mod tests {
6286 assert_eq ! ( "USD" , Money :: dollar( 1 ) . currency( ) ) ;
6387 assert_eq ! ( "CHF" , Money :: franc( 1 ) . currency( ) ) ;
6488 }
89+ #[ test]
90+ fn test_simple_addition ( ) {
91+ let sum = Money :: dollar ( 5 ) + Money :: dollar ( 5 ) ;
92+ let reduced = Money :: reduce ( sum, "USD" ) ;
93+ assert_eq ! ( Money :: dollar( 10 ) , reduced) ;
94+ }
6595}
You can’t perform that action at this time.
0 commit comments