File tree Expand file tree Collapse file tree 6 files changed +42
-38
lines changed
Expand file tree Collapse file tree 6 files changed +42
-38
lines changed Original file line number Diff line number Diff line change 11mod drone_repository;
22mod flight_controller;
3+ mod simulation_controller;
34
45pub use drone_repository:: * ;
56pub use flight_controller:: * ;
7+ pub use simulation_controller:: * ;
Original file line number Diff line number Diff line change 1+ use crate :: model:: { Drone , Location } ;
2+
3+ pub struct SimulationController < ' a > {
4+ drones : Vec < Drone < ' a > > ,
5+ }
6+
7+ impl < ' a > SimulationController < ' a > {
8+ pub fn new ( ) -> Self {
9+ SimulationController { drones : Vec :: new ( ) }
10+ }
11+ pub fn load ( & mut self , drone_count : i32 ) -> bool {
12+ for i in 0 ..drone_count {
13+ self . drones . push ( Drone {
14+ id : 1 ,
15+ energy_level : 100.0 ,
16+ model : "MODEL X" ,
17+ is_alive : true ,
18+ location : Location {
19+ x : 0.0 ,
20+ y : 0.0 ,
21+ z : 0.0 ,
22+ caption : "" ,
23+ } ,
24+ } )
25+ }
26+ true
27+ }
28+ pub fn get_count ( & self ) -> usize {
29+ self . drones . len ( )
30+ }
31+ pub fn get_random ( & self ) -> Drone {
32+ self . drones [ 0 ]
33+ }
34+ }
Original file line number Diff line number Diff line change @@ -4,4 +4,4 @@ pub struct Location<'a> {
44 pub x : f32 ,
55 pub y : f32 ,
66 pub z : f32 ,
7- }
7+ }
Original file line number Diff line number Diff line change @@ -2,4 +2,4 @@ mod drone;
22mod location;
33
44pub use drone:: Drone ;
5- pub use location:: Location ;
5+ pub use location:: Location ;
Original file line number Diff line number Diff line change 11mod drone_repository_tests;
22mod flight_controller_tests;
3- mod simulation_loader_tests;
3+ mod simulation_loader_tests;
Original file line number Diff line number Diff line change 11#[ cfg( test) ]
22mod tests {
3- use crate :: model:: { Drone , Location } ;
4-
5- struct Simulation < ' a > {
6- drones : Vec < Drone < ' a > > ,
7- }
8- impl < ' a > Simulation < ' a > {
9- fn new ( ) -> Self {
10- Simulation { drones : Vec :: new ( ) }
11- }
12- fn load ( & mut self , drone_count : i32 ) -> bool {
13- for i in 0 ..drone_count {
14- self . drones . push ( Drone {
15- id : 1 ,
16- energy_level : 100.0 ,
17- model : "MODEL X" ,
18- is_alive : true ,
19- location : Location {
20- x : 0.0 ,
21- y : 0.0 ,
22- z : 0.0 ,
23- caption : "" ,
24- } ,
25- } )
26- }
27- true
28- }
29- fn get_count ( & self ) -> usize {
30- self . drones . len ( )
31- }
32- fn get_random ( & self ) -> Drone {
33- self . drones [ 0 ]
34- }
35- }
3+ use crate :: controller:: SimulationController ;
364
375 #[ test]
386 fn should_allocate_one_drone_test ( ) {
39- let mut simulation = Simulation :: new ( ) ;
7+ let mut simulation = SimulationController :: new ( ) ;
408 let actual = simulation. load ( 1 ) ;
419 let expected = true ;
4210 assert_eq ! ( actual, expected) ;
4311 }
4412
4513 #[ test]
4614 fn should_allocate_ten_drone_returns_ten_test ( ) {
47- let mut simulation = Simulation :: new ( ) ;
15+ let mut simulation = SimulationController :: new ( ) ;
4816 let _ = simulation. load ( 10 ) ;
4917 let actual = simulation. get_count ( ) ;
5018 assert_eq ! ( actual, 10 ) ;
You can’t perform that action at this time.
0 commit comments