Skip to content

Commit f4baaf8

Browse files
committed
Refactored structure
1 parent 3926e25 commit f4baaf8

File tree

6 files changed

+42
-38
lines changed

6 files changed

+42
-38
lines changed

drone-lab/src/controller/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
mod drone_repository;
22
mod flight_controller;
3+
mod simulation_controller;
34

45
pub use drone_repository::*;
56
pub use flight_controller::*;
7+
pub use simulation_controller::*;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

drone-lab/src/model/location.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ pub struct Location<'a> {
44
pub x: f32,
55
pub y: f32,
66
pub z: f32,
7-
}
7+
}

drone-lab/src/model/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ mod drone;
22
mod location;
33

44
pub use drone::Drone;
5-
pub use location::Location;
5+
pub use location::Location;

drone-lab/src/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
mod drone_repository_tests;
22
mod flight_controller_tests;
3-
mod simulation_loader_tests;
3+
mod simulation_loader_tests;

drone-lab/src/tests/simulation_loader_tests.rs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,18 @@
11
#[cfg(test)]
22
mod 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);

0 commit comments

Comments
 (0)