1
1
var proxyquire = require ( 'proxyquire' )
2
2
var five = require ( '../../stubs/five' )
3
- var expect = require ( 'chai' ) . expect
4
3
var async = require ( 'async' )
5
4
var exercise = require ( 'workshopper-exercise' ) ( )
6
5
var filecheck = require ( 'workshopper-exercise/filecheck' )
7
6
var path = require ( 'path' )
8
- var notifier = require ( '../../lib/notifier' )
9
- var broadcaster = require ( '../../lib/broadcaster' )
7
+ var verifyProcessor = require ( '../../lib/verify-processor' )
10
8
11
9
// checks that the submission file actually exists
12
10
exercise = filecheck ( exercise )
@@ -17,7 +15,7 @@ exercise.addProcessor(function (mode, callback) {
17
15
proxyquire ( path . join ( process . cwd ( ) , exercise . args [ 0 ] ) , { 'johnny-five' : five } )
18
16
19
17
setTimeout ( function ( ) {
20
- console . log ( 'Please wait while your solution is tested...' )
18
+ console . log ( exercise . __ ( 'please_wait' ) )
21
19
} , 1000 )
22
20
23
21
// need a better way of detecting when we are done..
@@ -34,46 +32,63 @@ const pins = {
34
32
}
35
33
36
34
// add a processor only for 'verify' calls
37
- exercise . addVerifyProcessor ( function ( callback ) {
38
- try {
39
- var io = five . stubs . firmata . singleton
35
+ exercise . addVerifyProcessor ( verifyProcessor ( exercise , function ( test , done ) {
36
+ var io = five . stubs . firmata . singleton
40
37
41
- expect ( io , 'no board instance created' ) . to . exist
38
+ test . truthy ( io , 'create_board_instance' )
42
39
43
- // Get the listener that is listening for reads on pin A0
44
- var analogReadListener = null
40
+ /*
41
+ var piezo = five.Piezo.instances[0]
42
+ var btn = five.Button.instances[0]
43
+ var led = five.Led.instances[0]
44
+ var temp = five.Thermometer.instances[0]
45
45
46
- for ( var i = 0 ; i < io . analogRead . callCount ; i ++ ) {
47
- var call = io . analogRead . getCall ( i )
48
- if ( call . args [ 0 ] === pins . temp ) {
49
- analogReadListener = call . args [ 1 ]
50
- break
51
- }
46
+ test.truthy('create_speaker_instance', piezo)
47
+ test.equals('connect_speaker_to_pin', piezo.pin, pins.piezo, {pin: pins.piezo})
48
+
49
+ test.truthy('create_button_instance', btn)
50
+ test.equals('connect_button_to_pin', btn.pin, pins.btn, {pin: pins.btn})
51
+
52
+ test.truthy('create_led_instance', led)
53
+ test.equals('connect_led_to_pin', led.pin, pins.led, {pin: pins.led})
54
+
55
+ test.truthy('create_thermometer_instance', temp)
56
+ test.equals('connect_thermometer_to_pin', temp.pin, pins.temp, {pin: pins.temp})
57
+ */
58
+
59
+ // Get the listener that is listening for reads on pin A0
60
+ var analogReadListener = null
61
+
62
+ for ( var i = 0 ; i < io . analogRead . callCount ; i ++ ) {
63
+ var call = io . analogRead . getCall ( i )
64
+ if ( call . args [ 0 ] === pins . temp ) {
65
+ analogReadListener = call . args [ 1 ]
66
+ break
52
67
}
68
+ }
53
69
54
- expect ( analogReadListener , 'No values were read from A0' ) . to . not . be . null
55
- expect ( io . digitalWrite . called , 'Fire alarm went off before a temperature was received!' ) . to . be . false
70
+ test . truthy ( analogReadListener , 'read_analogue_values' , { pin : ' A0'} )
71
+ test . falsey ( io . digitalWrite . called , 'premature_fire_alarm' )
56
72
57
- testAlarmTurnsOff ( analogReadListener , io , function ( error ) {
58
- if ( error ) return broadcaster ( exercise ) ( error , function ( er ) { notifier ( exercise ) ( er , callback ) } )
73
+ testAlarmTurnsOff ( test , analogReadListener , io , function ( error ) {
74
+ if ( error ) {
75
+ return done ( error )
76
+ }
59
77
60
- testAlarmResets ( analogReadListener , io , function ( error ) {
61
- broadcaster ( exercise ) ( error , function ( er ) { notifier ( exercise ) ( er , callback ) } )
62
- } )
78
+ testAlarmResets ( test , analogReadListener , io , function ( error ) {
79
+ return done ( error )
63
80
} )
64
- } catch ( error ) {
65
- broadcaster ( exercise ) ( error , function ( er ) { notifier ( exercise ) ( er , callback ) } )
66
- }
67
- } )
81
+ } )
82
+ } ) )
68
83
69
- function testAlarmTurnsOff ( analogReadListener , io , cb ) {
84
+ function testAlarmTurnsOff ( test , analogReadListener , io , cb ) {
70
85
analogReadListener ( random ( tempToVoltage ( 50.1 ) , tempToVoltage ( 100 ) ) )
71
86
72
87
// Within 2 seconds, the piezo should have sounded and the LED turned on
73
88
setTimeout ( function ( ) {
74
89
try {
75
- expect ( io . digitalWrite . calledWith ( pins . piezo , io . HIGH ) , 'Piezo was not turned on when fire started' ) . to . be . true
76
- expect ( io . digitalWrite . calledWith ( pins . led , io . HIGH ) , 'LED was not turned on when fire started' ) . to . be . true
90
+ test . truthy ( io . digitalWrite . calledWith ( pins . piezo , io . HIGH ) , 'speaker_turned_on' )
91
+ test . truthy ( io . digitalWrite . calledWith ( pins . led , io . HIGH ) , 'led_turned_on' )
77
92
} catch ( er ) {
78
93
return cb ( er )
79
94
}
@@ -83,8 +98,8 @@ function testAlarmTurnsOff (analogReadListener, io, cb) {
83
98
// Within 2 seconds the last call to digitalWrite should have been with io.LOW
84
99
setTimeout ( function ( ) {
85
100
try {
86
- expect ( io . digitalWrite . calledWith ( pins . piezo , io . LOW ) , 'Piezo was not turned off when fire stopped' ) . to . be . true
87
- expect ( io . digitalWrite . calledWith ( pins . led , io . LOW ) , 'LED was not turned off when fire stopped' ) . to . be . true
101
+ test . truthy ( io . digitalWrite . calledWith ( pins . piezo , io . LOW ) , 'speaker_turned_off' )
102
+ test . truthy ( io . digitalWrite . calledWith ( pins . led , io . LOW ) , 'led_turned_off' )
88
103
} catch ( er ) {
89
104
return cb ( er )
90
105
}
@@ -99,15 +114,9 @@ function testAlarmTurnsOff (analogReadListener, io, cb) {
99
114
100
115
try {
101
116
// TODO: We can't currently test this as there is no way to stop a piezo from playing a tune
102
- /*expect(
103
- lastPiezoLowCall.calledAfter(lastPiezoHighCall),
104
- 'Piezo was not turned off after it was turned on and fire stopped'
105
- ).to.be.true*/
117
+ //test.truthy(lastPiezoLowCall.calledAfter(lastPiezoHighCall), 'speaker_turned_off')
106
118
107
- expect (
108
- lastLedLowCall . calledAfter ( lastLedHighCall ) ,
109
- 'LED was not turned off after it was turned on and fire stopped'
110
- ) . to . be . true
119
+ test . truthy ( lastLedLowCall . calledAfter ( lastLedHighCall ) , 'speaker_turned_off' )
111
120
112
121
cb ( )
113
122
} catch ( er ) {
@@ -120,7 +129,7 @@ function testAlarmTurnsOff (analogReadListener, io, cb) {
120
129
} , 2000 )
121
130
}
122
131
123
- function testAlarmResets ( analogReadListener , io , cb ) {
132
+ function testAlarmResets ( test , analogReadListener , io , cb ) {
124
133
io . digitalWrite . reset ( )
125
134
126
135
analogReadListener ( random ( tempToVoltage ( 50.1 ) , tempToVoltage ( 100 ) ) )
@@ -130,8 +139,8 @@ function testAlarmResets (analogReadListener, io, cb) {
130
139
var tests = [
131
140
function ( callback ) {
132
141
try {
133
- expect ( io . digitalWrite . calledWith ( pins . piezo , io . HIGH ) , 'Piezo was not turned on when fire started' ) . to . be . true
134
- expect ( io . digitalWrite . calledWith ( pins . led , io . HIGH ) , 'LED was not turned on when fire started' ) . to . be . true
142
+ test . truthy ( io . digitalWrite . calledWith ( pins . piezo , io . HIGH ) , 'speaker_turned_on' )
143
+ test . truthy ( io . digitalWrite . calledWith ( pins . led , io . HIGH ) , 'led_turned_on' )
135
144
} catch ( er ) {
136
145
return callback ( er )
137
146
}
@@ -159,15 +168,8 @@ function testAlarmResets (analogReadListener, io, cb) {
159
168
} ,
160
169
function ( callback ) {
161
170
try {
162
- expect (
163
- io . digitalWrite . calledWith ( pins . piezo , io . LOW ) ,
164
- 'Piezo was not turned off when reset button pressed'
165
- ) . to . be . true
166
-
167
- expect (
168
- io . digitalWrite . calledWith ( pins . led , io . LOW ) ,
169
- 'LED was not turned off when reset button pressed'
170
- ) . to . be . true
171
+ test . truthy ( io . digitalWrite . calledWith ( pins . piezo , io . LOW ) , 'speaker_reset' )
172
+ test . truthy ( io . digitalWrite . calledWith ( pins . led , io . LOW ) , 'led_reset' )
171
173
} catch ( er ) {
172
174
return callback ( er )
173
175
}
@@ -184,15 +186,9 @@ function testAlarmResets (analogReadListener, io, cb) {
184
186
185
187
try {
186
188
// TODO: We can't currently test this as there is no way to stop a piezo from playing a tune
187
- /*expect(
188
- lastPiezoLowCall.calledAfter(lastPiezoHighCall),
189
- 'Piezo was not turned off after it was turned on and reset button pressed'
190
- ).to.be.true*/
191
-
192
- expect (
193
- lastLedLowCall . calledAfter ( lastLedHighCall ) ,
194
- 'LED was not turned off after it was turned on and reset button pressed'
195
- ) . to . be . true
189
+ //test.truthy('speaker_turned_off_after_reset', lastPiezoLowCall.calledAfter(lastPiezoHighCall))
190
+
191
+ test . truthy ( lastLedLowCall . calledAfter ( lastLedHighCall ) , 'led_turned_off_after_reset' )
196
192
} catch ( er ) {
197
193
return callback ( er )
198
194
}
@@ -206,14 +202,10 @@ function testAlarmResets (analogReadListener, io, cb) {
206
202
} ,
207
203
function ( callback ) {
208
204
try {
209
- expect (
210
- io . digitalWrite . calledWith ( pins . piezo , io . HIGH ) ,
211
- 'Piezo turned back on after reset button pressed before temperature dropped below 50'
212
- ) . to . be . false
213
-
214
- expect ( io . digitalWrite . calledWith ( pins . led , io . HIGH ) ,
215
- 'LED turned back on after reset button pressed before temperature dropped below 50'
216
- ) . to . be . false
205
+ test . falsey ( io . digitalWrite . calledWith ( pins . piezo , io . HIGH ) ,
206
+ 'speaker_stayed_off_after_reset_before_temperature_drops' )
207
+ test . falsey ( io . digitalWrite . calledWith ( pins . led , io . HIGH ) ,
208
+ 'led_stayed_off_after_reset_before_temperature_drops' )
217
209
} catch ( er ) {
218
210
return callback ( er )
219
211
}
@@ -230,15 +222,8 @@ function testAlarmResets (analogReadListener, io, cb) {
230
222
} ,
231
223
function ( callback ) {
232
224
try {
233
- expect (
234
- io . digitalWrite . calledWith ( pins . piezo , io . HIGH ) ,
235
- 'Piezo was not turned on when fire started after reset button was pressed'
236
- ) . to . be . true
237
-
238
- expect (
239
- io . digitalWrite . calledWith ( pins . led , io . HIGH ) ,
240
- 'LED was not turned on when fire started after reset button was pressed'
241
- ) . to . be . true
225
+ test . truthy ( io . digitalWrite . calledWith ( pins . piezo , io . HIGH ) , 'speaker_stayed_off_after_fire_after_reset' )
226
+ test . truthy ( io . digitalWrite . calledWith ( pins . led , io . HIGH ) , 'led_stayed_off_after_fire_after_reset' )
242
227
243
228
// Reset
244
229
analogReadListener ( random ( tempToVoltage ( 0 ) , tempToVoltage ( 50 ) ) )
0 commit comments