File tree Expand file tree Collapse file tree 6 files changed +56
-3
lines changed
Expand file tree Collapse file tree 6 files changed +56
-3
lines changed Original file line number Diff line number Diff line change 1- use crate :: model:: { Drone , Location } ;
1+ use crate :: data:: * ;
2+ use crate :: model:: * ;
23
34pub struct SimulationController < ' a > {
45 drones : Vec < Drone < ' a > > ,
@@ -10,10 +11,11 @@ impl<'a> SimulationController<'a> {
1011 }
1112 pub fn load ( & mut self , drone_count : i32 ) -> bool {
1213 for i in 0 ..drone_count {
14+ let model = DRONE_MODELS [ get_random_number ( DRONE_MODELS . len ( ) ) ] ;
1315 self . drones . push ( Drone {
1416 id : 1 ,
1517 energy_level : 100.0 ,
16- model : "MODEL X" ,
18+ model,
1719 is_alive : true ,
1820 location : Location {
1921 x : 0.0 ,
Original file line number Diff line number Diff line change 1+ use std:: time:: { SystemTime , UNIX_EPOCH } ;
2+
3+ pub fn get_random_number ( max : usize ) -> usize {
4+ let duration = SystemTime :: now ( )
5+ . duration_since ( UNIX_EPOCH )
6+ . expect ( "Error at duration calculation" ) ;
7+
8+ let nanos = duration. subsec_nanos ( ) as usize ;
9+
10+ if max == 0 { 0 } else { nanos % max }
11+ }
Original file line number Diff line number Diff line change 1+ pub const DRONE_MODELS : [ & str ; 10 ] = [
2+ "T-1000" ,
3+ "Quick-90" ,
4+ "Analyzer" ,
5+ "T-800" ,
6+ "Cyberdine-10" ,
7+ "Class-A" ,
8+ "Engineer" ,
9+ "Temp-BOT" ,
10+ "T-1001" ,
11+ "Acrobat-K" ,
12+ ] ;
13+
14+ mod generator;
15+
16+ pub use generator:: * ;
Original file line number Diff line number Diff line change 1+ use data:: { DRONE_MODELS , get_random_number} ;
2+
13mod controller;
4+ mod data;
25mod model;
36mod tests;
47
58fn main ( ) {
69 //todo@buraksenyurt Derste yapılacaklar
710
8- // Eksik birim test fonksiyonlarını yazalım
911 // Başlangıçta sahaya belli sayıda rastgele ama makul koordinatlara çıkacak drone'lar yerleştirelim
1012 // Belirli periyotlarda sahadaki drone konumlarını terminale loglayalım
1113 // Terminal loglarını fiziki dosyaya kaydedelim
1214 // Programın bir sonraki açılışında son konumları dosyadan okuyalım
15+
16+ for _ in 0 ..10 {
17+ let max_value = DRONE_MODELS . len ( ) ;
18+ println ! ( "{}" , DRONE_MODELS [ get_random_number( max_value) ] ) ;
19+ }
1320}
Original file line number Diff line number Diff line change 1+ #[ cfg( test) ]
2+ mod test {
3+ use crate :: data:: { DRONE_MODELS , get_random_number} ;
4+
5+ #[ test]
6+ fn random_drone_model_test ( ) {
7+ let max_value = DRONE_MODELS . len ( ) ;
8+ let random_number = get_random_number ( max_value) ;
9+ let model = DRONE_MODELS [ random_number] ;
10+ assert ! (
11+ DRONE_MODELS
12+ . iter( )
13+ . any( |m| m. to_string( ) == model. to_string( ) )
14+ ) ;
15+ }
16+ }
Original file line number Diff line number Diff line change 11mod drone_repository_tests;
22mod flight_controller_tests;
33mod simulation_loader_tests;
4+ mod generator_tests;
You can’t perform that action at this time.
0 commit comments