Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/drone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
//!
//! Author: Rustastic (Andrea Carzeri, Alessandro Busola, Andrea Denina, Giulio Bosio)

use crate::packet_buffer;
use colored::Colorize;
use crossbeam_channel::{select_biased, Receiver, Sender};
use log::{error, info, warn};
use rand::Rng;
use std::collections::{HashMap, HashSet};

use wg_2024::{
controller::{DroneCommand, DroneEvent},
drone::Drone,
network::{NodeId, SourceRoutingHeader},
packet::{FloodRequest, FloodResponse, Fragment, Nack, NackType, NodeType, Packet, PacketType},
};

use crate::packet_buffer;
#[cfg(test)]
mod tests;

#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone)]
Expand Down
3 changes: 3 additions & 0 deletions src/drone/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod test_flooding;
mod test_fragment_ack_nack;
mod test_handle_command;
3 changes: 1 addition & 2 deletions tests/test_flooding.rs → src/drone/tests/test_flooding.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::RustasticDrone;
use crossbeam_channel::{select_biased, unbounded, Receiver, Sender};
use std::{
collections::{HashMap, HashSet},
Expand All @@ -12,8 +13,6 @@ use wg_2024::{
packet::{FloodRequest, FloodResponse, NodeType, Packet, PacketType},
};

use rustastic_drone::RustasticDrone;

struct Host {
id: NodeId,
controller_send: Sender<DroneEvent>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use rustastic_drone::RustasticDrone;

use crate::RustasticDrone;
use crossbeam_channel::{unbounded, Receiver, Sender};
use std::{
collections::HashMap,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use rustastic_drone::RustasticDrone;

use crate::RustasticDrone;
use crossbeam_channel::unbounded;
use std::{
collections::HashMap,
Expand All @@ -22,7 +21,7 @@ fn test_add_sender() {
HashMap::new(),
0f32,
)));
println!("{drone_thread:?}");
// println!("{drone_thread:?}");
let drone = drone_thread.clone();

let handler = thread::spawn(move || drone_thread.lock().unwrap().run());
Expand All @@ -35,9 +34,8 @@ fn test_add_sender() {
controller_to_drone.send(DroneCommand::Crash).unwrap();
handler.join().unwrap();
let drone = drone.lock().unwrap();
println!("{drone:?}");
//TODO cannot access private field because test is not a submodule of drone
// assert_ne!(drone.packet_send.iter().last().0, 15);
// println!("{drone:?}");
assert_eq!(*drone.packet_send.iter().last().unwrap().0, 15u8);
}

#[test]
Expand All @@ -53,7 +51,7 @@ fn test_set_pdr() {
HashMap::new(),
0f32,
)));
println!("{drone_thread:?}");
// println!("{drone_thread:?}");
let drone = drone_thread.clone();

let handler = thread::spawn(move || drone_thread.lock().unwrap().run());
Expand All @@ -67,15 +65,18 @@ fn test_set_pdr() {
handler.join().unwrap();

let drone = drone.lock().unwrap();
println!("{drone:?}");
//TODO cannot access private field because test is not a submodule of drone
// assert_ne!(drone.pdr, 0.05);
// println!("{drone:?}");
#[allow(clippy::float_cmp)]
{
assert_eq!(drone.pdr, 0.05);
}
}
#[test]
fn test_remove_sender() {
let (drone_to_controller, _controller_from_drone) = unbounded();
let (controller_to_drone, drone_from_controller) = unbounded();
let mut sender = HashMap::new();
sender.insert(3, unbounded().0);
sender.insert(2, unbounded().0);
let drone_thread = Arc::new(Mutex::new(RustasticDrone::new(
1,
Expand All @@ -85,7 +86,7 @@ fn test_remove_sender() {
sender,
0f32,
)));
println!("{drone_thread:?}");
// println!("{drone_thread:?}");
let drone = drone_thread.clone();

let handler = thread::spawn(move || drone_thread.lock().unwrap().run());
Expand All @@ -98,7 +99,6 @@ fn test_remove_sender() {
handler.join().unwrap();

let drone = drone.lock().unwrap();
println!("{drone:?}");
//TODO cannot access private field because test is not a submodule of drone
// assert_eq!( drone.packet_send.iter().last().1, 2 ) ;
// println!("{drone:?}");
assert_ne!(*drone.packet_send.iter().last().unwrap().0, 2);
}
Loading