Object subclass: #Frame instanceVariableNames: 'rolls' classVariableNames: '' poolDictionaries: '' category: 'Tddbc2d3-Bowling'! !Frame methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 14:57'! = other other class = self class ifFalse: [^false]. ^rolls = other rolls! ! !Frame methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 14:39'! hash ^rolls hash! ! !Frame methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 15:54'! printOn: stream rolls printOn: stream ! ! !Frame methodsFor: 'accessing' stamp: 't_hachinohe 12/10/2011 14:02'! rolls ^rolls! ! !Frame methodsFor: 'initialization' stamp: 't_hachinohe 12/10/2011 14:26'! setRolls: rollArray rollArray replaceAll: #- with: 0. rollArray replaceAll: #X with: 10. (rollArray size > 1 and: [rollArray second = #/]) ifTrue: [rollArray at: 2 put: 10 - rollArray first]. rolls := rollArray! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! Frame class instanceVariableNames: ''! !Frame class methodsFor: 'instance creation' stamp: 't_hachinohe 12/10/2011 13:56'! withRolls: rollArray ^self new setRolls: rollArray; yourself! ! TestCase subclass: #FrameTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Tddbc2d3-Bowling'! !FrameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 13:42'! test001 "フレームのインスタンスを生成できること" self assert: Frame new class = Frame !]lang[(10 19 41)0,5,0! ! !FrameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 13:46'! test002 "インスタンスを生成する際に配列を受け取ることができる" self shouldnt: (Frame withRolls: #(2 3)) raise: Error!]lang[(10 26 57)0,5,0! ! !FrameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 13:54'! test003 "インスタンスを生成する際に配列を受け取ることができる" self assert: (Frame withRolls: #(2 3)) class = Frame!]lang[(10 26 56)0,5,0! ! !FrameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 14:10'! test004 "インスタンスを生成する際に配列の2番目がスラッシュならばスペアとして処理する" | frame | frame := Frame withRolls: #(2 /). self assert: frame rolls = #(2 8) !]lang[(10 38 86)0,5,0! ! !FrameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 14:03'! test005 "インスタンスを生成する際にストライクを表す配列を受け取とるとインスタンス変数rollsに代入されていること" | frame | frame := Frame withRolls: #(X). self assert: frame rolls = #(10) !]lang[(10 38 5 10 83)0,5,0,5,0! ! !FrameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 14:21'! test006 "インスタンスを生成する際にマイナスを含む配列を受け取とると0として代入されていること" | frame | frame := Frame withRolls: #(- -). self assert: frame rolls = #(0 0) !]lang[(10 29 1 12 86)0,5,0,5,0! ! !FrameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 14:38'! test007 "おなじrollsで作られたFrameが等しいこと" | frame1 frame2 | frame1 := Frame withRolls: #(2 3). frame2 := Frame withRolls: #(2 3). self assert: frame1 = frame2 !]lang[(10 3 5 5 5 6 126)0,5,0,5,0,5,0! ! Object subclass: #Game instanceVariableNames: 'frames' classVariableNames: '' poolDictionaries: '' category: 'Tddbc2d3-Bowling'! !Game methodsFor: 'accessing' stamp: 't_hachinohe 12/10/2011 14:58'! frames ^frames! ! !Game methodsFor: 'calculation' stamp: 't_hachinohe 12/10/2011 16:30'! score | sum | sum := 0. 1 to: 10 do:[:index | | frame frameSum nextFrameRolls| frame := frames at:index. frameSum := frame rolls sum. sum := sum + frameSum. nextFrameRolls := index = 10 ifTrue: [#(0 0)] ifFalse: [(frames at:index + 1) rolls]. frameSum = 10 ifTrue: [ (frame rolls size = 1 ifTrue: [ nextFrameRolls size = 1 ifTrue: [sum := sum + (frames at:index + 2) rolls first]. sum := sum + (nextFrameRolls first:(2 min:nextFrameRolls size)) sum ] ifFalse: [sum := sum + nextFrameRolls first] ) ]. ]. ^sum! ! !Game methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 14:59'! setScore: scoreArray frames := scoreArray collect: [:rolls | Frame withRolls: rolls]! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! Game class instanceVariableNames: ''! !Game class methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 13:38'! new: scoreArray ^Game new setScore: scoreArray; yourself! ! TestCase subclass: #GameTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Tddbc2d3-Bowling'! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 16:33'! test000 "9フレームでスペアを出した場合に最終フレームの1投目が0以外の場合に重複加算されること" | game scoreArray | scoreArray := #((5 3) (7 2) (8 /) (X) (7 1) (9 -) (6 2) (X) (6 /) (8 -)). game := Game new: scoreArray. self assert: game score = 126!]lang[(11 42 161)0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 13:19'! test001 "Gameのインスタンスをつくることが出来る" self assert: Game new notNil !]lang[(14 17 33)0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 13:28'! test002 "Gameのインスタンスをつくる際にスコアの配列をうけとれる" self shouldnt: (Game new: #((5 3) (7 2) (8 /) (X) (7 1) (9 -) (6 2) (X) (6 /) (8 -))) raise: Error !]lang[(14 25 103)0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 13:33'! test003 "Gameのインスタンスをつくることが出来る" self assert: (Game new: #((5 3) (7 2) (8 /) (X) (7 1) (9 -) (6 2) (X) (6 /) (8 -))) class = Game!]lang[(14 17 100)0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 14:35'! test004 "Gameはスコア配列を受け取ると各フレームに倒したピンを割り振る" | game frames scoreArray | scoreArray := #((5 3) (7 2) (8 /) (X) (7 1) (9 -) (6 2) (X) (6 /) (8 -)). game := Game new: scoreArray. frames := scoreArray collect: [:rolls | Frame withRolls: rolls]. self assert: game frames = frames!]lang[(14 28 239)0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 15:24'! test005 "Gameがすべて0ての配列でインスタンス化した場合scoreは0となること" | game scoreArray | scoreArray := #((- -) (- -) (- -) (- -) (- -) (- -) (- -) (- -) (- -) (- -)). game := Game new: scoreArray. self assert: game score = 0!]lang[(14 4 1 16 5 1 1 5 163)0,5,0,5,0,5,0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 15:07'! test006 "Gameがすべて0ての配列でインスタンス化した場合scoreは0となること" | game scoreArray | scoreArray := #((2 3) (- -) (- -) (- -) (- -) (- -) (- -) (- -) (- -) (- -)). game := Game new: scoreArray. self assert: game score = 5!]lang[(14 4 1 16 5 1 1 5 163)0,5,0,5,0,5,0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 15:30'! test007 "Gameがスペアの後にピンを倒している配列でインスタンス化した場合次のフレームの1投目が加算されること" | game scoreArray | scoreArray := #((2 /) (1 -) (- -) (- -) (- -) (- -) (- -) (- -) (- -) (- -)). game := Game new: scoreArray. self assert: game score = 12!]lang[(14 36 1 10 164)0,5,0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 15:35'! test008 "ストライクの後にストライクではない場合に次のフレームの合計が加算されること" | game scoreArray | scoreArray := #((X) (1 2) (- -) (- -) (- -) (- -) (- -) (- -) (- -) (- -)). game := Game new: scoreArray. self assert: game score = 16!]lang[(10 37 162)0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 15:44'! test009 "ストライクの後にストライクだった場合に次のフレームの合計が加算されること" | game scoreArray | scoreArray := #((X) (X) (2 3) (- -) (- -) (- -) (- -) (- -) (- -) (- -)). game := Game new: scoreArray. self assert: game score = (22 + 15 + 5)!]lang[(10 36 171)0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 16:14'! test010 "9フレームでストライクの後にピンを倒した場合に次のフレームの合計が加算されること" | game scoreArray | scoreArray := #((- -) (- -) (- -) (- -) (- -) (- -) (- -) (- -) (X) (2 3)). game := Game new: scoreArray. self assert: game score = (15 + 5)!]lang[(10 40 168)0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 16:16'! test011 "最終フレームでスペアを出した場合にその合計が計算されること" | game scoreArray | scoreArray := #((- -) (- -) (- -) (- -) (- -) (- -) (- -) (- -) (- -) (2 / 4)). game := Game new: scoreArray. self assert: game score = (14)!]lang[(10 29 168)0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 16:18'! test012 "9フレームでスペアを出した場合に最終フレームの1投目が0以外の場合に重複加算されること" | game scoreArray | scoreArray := #((- -) (- -) (- -) (- -) (- -) (- -) (- -) (- -) (- /) (2 / 4)). game := Game new: scoreArray. self assert: game score = (12 + 14)!]lang[(11 42 173)0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 16:28'! test013 "9フレームでスペアを出した場合に最終フレームの1投目が0以外の場合に重複加算されること" | game scoreArray | scoreArray := #((- -) (- -) (- -) (- -) (- -) (- -) (- -) (- -) (X) (2 / 4)). game := Game new: scoreArray. self assert: game score = (20 + 14)!]lang[(11 42 171)0,5,0! ! !GameTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 16:29'! test014 "9フレームでスペアを出した場合に最終フレームの1投目が0以外の場合に重複加算されること" | game scoreArray | scoreArray := #((- -) (- -) (- -) (- -) (- -) (- -) (- -) (- -) (X) (2 / -)). game := Game new: scoreArray. self assert: game score = (20 + 10)!]lang[(11 42 171)0,5,0! ! TestCase subclass: #ScoreTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Tddbc2d3-Bowling'! !ScoreTest methodsFor: 'as yet unclassified' stamp: 't_hachinohe 12/10/2011 18:00'! test001 "配列にscoreメッセージを送るとボーリングのスコアを返すこと" self assert:#((5 3) (7 2) (8 /) (X) (7 1) (9 -) (6 2) (X) (6 /) (8 -)) score = 126!]lang[(10 3 5 23 86)0,5,0,5,0! !