View raw

1 " 2 A MFTTraineeTest is a test class for testing the behavior of MFTTrainee 3 " 4 Class { 5 #name : 'MFTTraineeTest', 6 #superclass : 'TestCase', 7 #category : 'MyFitnessTracker-Core-Tests-Base', 8 #package : 'MyFitnessTracker-Core-Tests', 9 #tag : 'Base' 10 } 11 12 { #category : 'tests' } 13 MFTTraineeTest >> newWorkoutPrescriptionNamed: aString [ 14 15 ^ MFTWorkoutPrescription new 16 title: aString; 17 yourself 18 ] 19 20 { #category : 'tests' } 21 MFTTraineeTest >> testCanonicalName [ 22 23 self assert: MFTTrainee new canonicalName equals: 'trainee' 24 ] 25 26 { #category : 'tests' } 27 MFTTraineeTest >> testInitializeCreatesRoutineAndLogBook [ 28 29 | trainee | 30 trainee := MFTTrainee new. 31 32 self assert: trainee currentRoutine class equals: MFTRoutine. 33 self assert: trainee currentRoutine workouts isEmpty. 34 self assert: trainee logBook class equals: MFTWorkoutLogBook. 35 self assert: trainee logBook workoutLogs isEmpty 36 ] 37 38 { #category : 'tests' } 39 MFTTraineeTest >> testIsRecoveredAnswersFalseWhenLastWorkoutFinishedLessThanTwoDaysAgo [ 40 41 | trainee log | 42 trainee := MFTTrainee new. 43 log := MFTWorkoutLog new. 44 log finish: DateAndTime now - 1 day. 45 trainee logWorkout: log. 46 47 self deny: trainee isRecovered 48 ] 49 50 { #category : 'tests' } 51 MFTTraineeTest >> testIsRecoveredAnswersTrueWhenLastWorkoutFinishedMoreThanTwoDaysAgo [ 52 53 | trainee log | 54 trainee := MFTTrainee new. 55 log := MFTWorkoutLog new. 56 log finish: DateAndTime now - 3 days. 57 trainee logWorkout: log. 58 59 self assert: trainee isRecovered 60 ] 61 62 { #category : 'tests' } 63 MFTTraineeTest >> testIsRecoveredAnswersTrueWithoutWorkoutLogs [ 64 65 self assert: MFTTrainee new isRecovered 66 ] 67 68 { #category : 'tests' } 69 MFTTraineeTest >> testLogBookAccessorCanReplaceLogBook [ 70 71 | trainee logBook | 72 trainee := MFTTrainee new. 73 logBook := MFTWorkoutLogBook new. 74 75 trainee logBook: logBook. 76 77 self assert: trainee logBook identicalTo: logBook 78 ] 79 80 { #category : 'tests' } 81 MFTTraineeTest >> testLogWorkoutAddsWorkoutToLogBook [ 82 83 | trainee log | 84 trainee := MFTTrainee new. 85 log := MFTWorkoutLog new. 86 87 trainee logWorkout: log. 88 89 self assert: trainee logBook workoutLogs size equals: 1. 90 self assert: trainee logBook workoutLogs first identicalTo: log 91 ] 92 93 { #category : 'tests' } 94 MFTTraineeTest >> testNextWorkoutPrescriptionAnswersFirstWorkoutWhenNoWorkoutHasBeenLogged [ 95 96 | trainee routine firstWorkout secondWorkout | 97 trainee := MFTTrainee new. 98 firstWorkout := self newWorkoutPrescriptionNamed: 'Day 1'. 99 secondWorkout := self newWorkoutPrescriptionNamed: 'Day 2'. 100 routine := MFTRoutine new. 101 routine workouts: { 102 firstWorkout. 103 secondWorkout }. 104 trainee currentRoutine: routine. 105 106 self 107 assert: trainee nextWorkoutPrescription 108 identicalTo: firstWorkout 109 ] 110 111 { #category : 'tests' } 112 MFTTraineeTest >> testNextWorkoutPrescriptionAnswersNilForEmptyRoutine [ 113 114 self assert: MFTTrainee new nextWorkoutPrescription isNil 115 ] 116 117 { #category : 'tests' } 118 MFTTraineeTest >> testNextWorkoutPrescriptionFollowsLastLoggedPrescription [ 119 120 | trainee routine firstWorkout secondWorkout log | 121 trainee := MFTTrainee new. 122 firstWorkout := self newWorkoutPrescriptionNamed: 'Day 1'. 123 secondWorkout := self newWorkoutPrescriptionNamed: 'Day 2'. 124 routine := MFTRoutine new. 125 routine workouts: { 126 firstWorkout. 127 secondWorkout }. 128 trainee currentRoutine: routine. 129 log := MFTWorkoutLog new. 130 log prescription: firstWorkout. 131 log finish: DateAndTime now. 132 trainee logWorkout: log. 133 134 self 135 assert: trainee nextWorkoutPrescription 136 identicalTo: secondWorkout 137 ] 138 139 { #category : 'tests' } 140 MFTTraineeTest >> testNextWorkoutPrescriptionWrapsAfterLastWorkout [ 141 142 | trainee routine firstWorkout secondWorkout log | 143 trainee := MFTTrainee new. 144 firstWorkout := self newWorkoutPrescriptionNamed: 'Day 1'. 145 secondWorkout := self newWorkoutPrescriptionNamed: 'Day 2'. 146 routine := MFTRoutine new. 147 routine workouts: { 148 firstWorkout. 149 secondWorkout }. 150 trainee currentRoutine: routine. 151 log := MFTWorkoutLog new. 152 log prescription: secondWorkout. 153 log finish: DateAndTime now. 154 trainee logWorkout: log. 155 156 self 157 assert: trainee nextWorkoutPrescription 158 identicalTo: firstWorkout 159 ] 160 161 { #category : 'tests' } 162 MFTTraineeTest >> testRoutineAccessorCanReplaceRoutine [ 163 164 | trainee routine | 165 trainee := MFTTrainee new. 166 routine := MFTRoutine new. 167 168 trainee currentRoutine: routine. 169 170 self assert: trainee currentRoutine identicalTo: routine 171 ] 172