Skip to content

Commit

Permalink
Add test for outdoor radios
Browse files Browse the repository at this point in the history
  • Loading branch information
maplant committed May 31, 2024
1 parent a85e9eb commit 496d228
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
1 change: 1 addition & 0 deletions coverage_map/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pub struct RankedCoverage {

/// Rank of the hex coverage.
// TODO(map): Should this be split into Indoor and OutdoorRank?
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Rank {
First,
Second,
Expand Down
76 changes: 74 additions & 2 deletions coverage_map/src/outdoor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ impl Ord for OutdoorCoverageLevel {
}

pub fn insert_outdoor_coverage_object(
indoor: &mut OutdoorCellTree,
outdoor: &mut OutdoorCellTree,
coverage_object: CoverageObject,
) {
for hex_coverage in coverage_object.coverage.into_iter() {
insert_outdoor_coverage(
indoor,
outdoor,
&coverage_object.hotspot_key,
&coverage_object.cbsd_id,
coverage_object.seniority_timestamp,
Expand Down Expand Up @@ -123,3 +123,75 @@ pub fn into_outdoor_coverage_map(
})
})
}

#[cfg(test)]
mod test {
use super::*;
use crate::*;
use chrono::NaiveDate;
use hex_assignments::Assignment;
use hextree::Cell;

#[test]
fn ensure_outdoor_radios_ranked_by_power() {
let mut outdoor_coverage = OutdoorCellTree::default();
for cov_obj in vec![
outdoor_cbrs_coverage("1", -946, date(2022, 8, 1)),
outdoor_cbrs_coverage("2", -936, date(2022, 12, 5)),
outdoor_cbrs_coverage("3", -887, date(2022, 12, 2)),
outdoor_cbrs_coverage("4", -887, date(2022, 12, 1)),
outdoor_cbrs_coverage("5", -773, date(2023, 5, 1)),
]
.into_iter()
{
insert_outdoor_coverage_object(&mut outdoor_coverage, cov_obj);
}
let ranked: HashMap<_, _> =
into_outdoor_coverage_map(outdoor_coverage, &BoostedHexes::default(), Utc::now())
.map(|x| (x.cbsd_id.clone().unwrap(), x))
.collect();
assert_eq!(ranked.get("5").unwrap().rank, Rank::First);
assert_eq!(ranked.get("4").unwrap().rank, Rank::Second);
assert_eq!(ranked.get("3").unwrap().rank, Rank::Third);
assert!(ranked.get("1").is_none());
assert!(ranked.get("2").is_none());
}

fn hex_assignments_mock() -> HexAssignments {
HexAssignments {
footfall: Assignment::A,
urbanized: Assignment::A,
landtype: Assignment::A,
}
}

fn date(year: i32, month: u32, day: u32) -> DateTime<Utc> {
NaiveDate::from_ymd_opt(year, month, day)
.unwrap()
.and_hms_opt(0, 0, 0)
.unwrap()
.and_utc()
}

fn outdoor_cbrs_coverage(
cbsd_id: &str,
signal_power: i32,
seniority_timestamp: DateTime<Utc>,
) -> CoverageObject {
let owner: PublicKeyBinary = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6"
.parse()
.expect("failed owner parse");
CoverageObject {
indoor: false,
hotspot_key: owner,
seniority_timestamp,
cbsd_id: Some(cbsd_id.to_string()),
coverage: vec![UnrankedCoverage {
location: Cell::from_raw(0x8a1fb46622dffff).expect("valid h3 cell"),
signal_power,
signal_level: SignalLevel::High,
assignments: hex_assignments_mock(),
}],
}
}
}

0 comments on commit 496d228

Please sign in to comment.