@@ -346,16 +346,20 @@ mod tests {
346
346
PwmTransaction :: get_max_duty_cycle ( max_duty) ,
347
347
PwmTransaction :: set_duty_cycle ( 0 ) ,
348
348
] ;
349
- let motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
350
- let motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
351
- let motor_pwm = PwmMock :: new ( & motor_pwm_expectations) ;
349
+ let mut motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
350
+ let mut motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
351
+ let mut motor_pwm = PwmMock :: new ( & motor_pwm_expectations) ;
352
352
353
- let mut motor = Motor :: new ( motor_in1, motor_in2, motor_pwm) ;
353
+ let mut motor = Motor :: new ( motor_in1. clone ( ) , motor_in2. clone ( ) , motor_pwm. clone ( ) ) ;
354
354
355
355
motor. stop ( ) ;
356
356
357
357
assert_eq ! ( * motor. current_drive_command( ) , DriveCommand :: Stop ) ;
358
358
assert_eq ! ( motor. current_speed( ) , 0 ) ;
359
+
360
+ motor_in1. done ( ) ;
361
+ motor_in2. done ( ) ;
362
+ motor_pwm. done ( ) ;
359
363
}
360
364
361
365
#[ test]
@@ -374,16 +378,20 @@ mod tests {
374
378
PwmTransaction :: get_max_duty_cycle ( max_duty) ,
375
379
PwmTransaction :: set_duty_cycle ( 0 ) ,
376
380
] ;
377
- let motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
378
- let motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
379
- let motor_pwm = PwmMock :: new ( & motor_pwm_expectations) ;
381
+ let mut motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
382
+ let mut motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
383
+ let mut motor_pwm = PwmMock :: new ( & motor_pwm_expectations) ;
380
384
381
- let mut motor = Motor :: new ( motor_in1, motor_in2, motor_pwm) ;
385
+ let mut motor = Motor :: new ( motor_in1. clone ( ) , motor_in2. clone ( ) , motor_pwm. clone ( ) ) ;
382
386
383
387
motor. brake ( ) ;
384
388
385
389
assert_eq ! ( * motor. current_drive_command( ) , DriveCommand :: Brake ) ;
386
390
assert_eq ! ( motor. current_speed( ) , 0 ) ;
391
+
392
+ motor_in1. done ( ) ;
393
+ motor_in2. done ( ) ;
394
+ motor_pwm. done ( ) ;
387
395
}
388
396
389
397
#[ test]
@@ -403,16 +411,20 @@ mod tests {
403
411
PwmTransaction :: get_max_duty_cycle ( max_duty) ,
404
412
PwmTransaction :: set_duty_cycle ( speed as u16 ) ,
405
413
] ;
406
- let motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
407
- let motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
408
- let motor_pwm = PwmMock :: new ( & motor_pwm_expectations) ;
414
+ let mut motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
415
+ let mut motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
416
+ let mut motor_pwm = PwmMock :: new ( & motor_pwm_expectations) ;
409
417
410
- let mut motor = Motor :: new ( motor_in1, motor_in2, motor_pwm) ;
418
+ let mut motor = Motor :: new ( motor_in1. clone ( ) , motor_in2. clone ( ) , motor_pwm. clone ( ) ) ;
411
419
412
420
motor. drive_forward ( speed) . expect ( "speed can be set" ) ;
413
421
414
422
assert_eq ! ( * motor. current_drive_command( ) , DriveCommand :: Forward ( 100 ) ) ;
415
423
assert_eq ! ( motor. current_speed( ) , speed as i8 ) ;
424
+
425
+ motor_in1. done ( ) ;
426
+ motor_in2. done ( ) ;
427
+ motor_pwm. done ( ) ;
416
428
}
417
429
418
430
#[ test]
@@ -432,39 +444,35 @@ mod tests {
432
444
PwmTransaction :: get_max_duty_cycle ( max_duty) ,
433
445
PwmTransaction :: set_duty_cycle ( speed as u16 ) ,
434
446
] ;
435
- let motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
436
- let motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
437
- let motor_pwm = PwmMock :: new ( & motor_pwm_expectations) ;
447
+ let mut motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
448
+ let mut motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
449
+ let mut motor_pwm = PwmMock :: new ( & motor_pwm_expectations) ;
438
450
439
- let mut motor = Motor :: new ( motor_in1, motor_in2, motor_pwm) ;
451
+ let mut motor = Motor :: new ( motor_in1. clone ( ) , motor_in2. clone ( ) , motor_pwm. clone ( ) ) ;
440
452
441
453
motor. drive_backwards ( speed) . expect ( "speed can be set" ) ;
442
454
443
455
assert_eq ! ( * motor. current_drive_command( ) , DriveCommand :: Backwards ( 100 ) ) ;
444
456
assert_eq ! ( motor. current_speed( ) , -( speed as i8 ) ) ;
457
+
458
+ motor_in1. done ( ) ;
459
+ motor_in2. done ( ) ;
460
+ motor_pwm. done ( ) ;
445
461
}
446
462
447
463
#[ test]
448
464
fn test_motor_drive_invalid_speed ( ) {
449
- let max_duty = 100 ;
450
- let motor_in1_expectations = [ PinTransaction :: set ( Low ) ] ;
451
- let motor_in2_expectations = [ PinTransaction :: set ( High ) ] ;
465
+ let motor_in1_expectations = [ ] ;
466
+ let motor_in2_expectations = [ ] ;
452
467
#[ cfg( feature = "hal_v02" ) ]
453
- let motor_pwm_expectations = [
454
- PinTransaction :: enable ( ) ,
455
- PinTransaction :: get_max_duty ( max_duty) ,
456
- PinTransaction :: set_duty ( 100 ) ,
457
- ] ;
468
+ let motor_pwm_expectations = [ PinTransaction :: enable ( ) ] ;
458
469
#[ cfg( feature = "hal_v1" ) ]
459
- let motor_pwm_expectations = [
460
- PwmTransaction :: get_max_duty_cycle ( max_duty) ,
461
- PwmTransaction :: set_duty_cycle ( 100 ) ,
462
- ] ;
463
- let motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
464
- let motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
465
- let motor_pwm = PwmMock :: new ( & motor_pwm_expectations) ;
470
+ let motor_pwm_expectations = [ ] ;
471
+ let mut motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
472
+ let mut motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
473
+ let mut motor_pwm = PwmMock :: new ( & motor_pwm_expectations) ;
466
474
467
- let mut motor = Motor :: new ( motor_in1, motor_in2, motor_pwm) ;
475
+ let mut motor = Motor :: new ( motor_in1. clone ( ) , motor_in2. clone ( ) , motor_pwm. clone ( ) ) ;
468
476
469
477
let current_drive_command = motor. current_drive_command ( ) . clone ( ) ;
470
478
let current_speed = motor. current_speed ( ) ;
@@ -479,5 +487,9 @@ mod tests {
479
487
// this should still be what was set before the invalid command
480
488
assert_eq ! ( * motor. current_drive_command( ) , current_drive_command) ;
481
489
assert_eq ! ( motor. current_speed( ) , current_speed) ;
490
+
491
+ motor_in1. done ( ) ;
492
+ motor_in2. done ( ) ;
493
+ motor_pwm. done ( ) ;
482
494
}
483
495
}
0 commit comments