Skip to content

Commit 06e1889

Browse files
authored
increase code coverage (#68)
* antex/pcv: add more tests * channel: add more tests * navigation/ionmessage: add more tests * navigation/health: add more tests * hardware/: add more tests * antex: add coordinates conversion methods Signed-off-by: Guillaume W. Bres <[email protected]>
1 parent 00ccf92 commit 06e1889

File tree

10 files changed

+270
-26
lines changed

10 files changed

+270
-26
lines changed

rinex/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ wkt = { version = "0.10.0", default-features = false, optional = true }
3636
serde = { version = "1.0", optional = true, default-features = false, features = ["derive"] }
3737
flate2 = { version = "1.0.24", optional = true, default-features = false, features = ["zlib"] }
3838
hifitime = { version = "3.7.0", features = ["serde", "std"] }
39+
map_3d = "0.1.4"
3940

4041
[dev-dependencies]
4142
criterion = "0.4"

rinex/src/antex/frequency.rs

+69-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Antex - special RINEX type specific structures
2-
use crate::channel;
2+
use crate::channel::Channel;
33

44
#[derive(Debug, Clone, PartialEq, PartialOrd)]
55
#[cfg_attr(feature = "serde", derive(Serialize))]
@@ -48,7 +48,7 @@ impl Pattern {
4848
#[cfg_attr(feature = "serde", derive(Serialize))]
4949
pub struct Frequency {
5050
/// Channel, example: L1, L2 for GPS, E1, E5 for GAL...
51-
pub channel: channel::Channel,
51+
pub channel: Channel,
5252
/// Northern component of the mean antenna phase center
5353
/// relative to the antenna reference point (ARP),
5454
/// in [mm]
@@ -70,7 +70,7 @@ pub struct Frequency {
7070
impl Default for Frequency {
7171
fn default() -> Self {
7272
Self {
73-
channel: channel::Channel::default(),
73+
channel: Channel::default(),
7474
north: 0.0_f64,
7575
east: 0.0_f64,
7676
up: 0.0_f64,
@@ -80,7 +80,53 @@ impl Default for Frequency {
8080
}
8181

8282
impl Frequency {
83-
pub fn with_channel(&self, channel: channel::Channel) -> Self {
83+
/// Returns ARP coordinates in Geodetic system.
84+
/// Ref. position must be given in (lat, lon, altitude) [m]
85+
pub fn arp_geodetic(&self, ref_pos: (f64, f64, f64)) -> (f64, f64, f64) {
86+
map_3d::enu2geodetic(
87+
self.east * 10.0E-3,
88+
self.north * 10.0E-3,
89+
self.up * 10.0E-3,
90+
ref_pos.0,
91+
ref_pos.1,
92+
ref_pos.2,
93+
map_3d::Ellipsoid::WGS84,
94+
)
95+
}
96+
/// Returns ARP coordinates in ECEF system.
97+
pub fn arp_ecef(&self, ref_pos: (f64, f64, f64)) -> (f64, f64, f64) {
98+
map_3d::enu2ecef(
99+
self.east * 10.0E-3,
100+
self.north * 10.0E-3,
101+
self.up * 10.0E-3,
102+
ref_pos.0,
103+
ref_pos.1,
104+
ref_pos.2,
105+
map_3d::Ellipsoid::WGS84,
106+
)
107+
}
108+
/// Returns ARP coordinates as North Earth Down coordinates
109+
pub fn arp_ned(&self, ref_pos: (f64, f64, f64)) -> (f64, f64, f64) {
110+
let ecef = map_3d::enu2ecef(
111+
self.east * 10.0E-3,
112+
self.north * 10.0E-3,
113+
self.up * 10.0E-3,
114+
ref_pos.0,
115+
ref_pos.1,
116+
ref_pos.2,
117+
map_3d::Ellipsoid::WGS84,
118+
);
119+
map_3d::ecef2ned(
120+
ecef.0,
121+
ecef.1,
122+
ecef.2,
123+
ref_pos.0,
124+
ref_pos.1,
125+
ref_pos.2,
126+
map_3d::Ellipsoid::WGS84,
127+
)
128+
}
129+
pub fn with_channel(&self, channel: Channel) -> Self {
84130
let mut f = self.clone();
85131
f.channel = channel.clone();
86132
f
@@ -106,3 +152,22 @@ impl Frequency {
106152
f
107153
}
108154
}
155+
156+
#[cfg(test)]
157+
mod test {
158+
use super::*;
159+
#[test]
160+
fn test_pattern() {
161+
let default = Pattern::default();
162+
assert_eq!(default, Pattern::NonAzimuthDependent(Vec::new()));
163+
assert_eq!(default.is_azimuth_dependent(), false);
164+
}
165+
#[test]
166+
fn test_frequency() {
167+
let default = Frequency::default();
168+
assert_eq!(default.channel, Channel::default());
169+
assert_eq!(default.north, 0.0_f64);
170+
assert_eq!(default.east, 0.0_f64);
171+
assert_eq!(default.up, 0.0_f64);
172+
}
173+
}

rinex/src/antex/pcv.rs

+22
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,25 @@ impl Pcv {
5454
s
5555
}
5656
}
57+
58+
#[cfg(test)]
59+
mod test {
60+
use super::*;
61+
use std::str::FromStr;
62+
#[test]
63+
fn test_pcv() {
64+
assert_eq!(Pcv::default(), Pcv::Absolute);
65+
assert!(Pcv::Absolute.is_absolute());
66+
assert_eq!(Pcv::Relative(String::from("AOAD/M_T")).is_absolute(), false);
67+
68+
let pcv = Pcv::from_str("A");
69+
assert!(pcv.is_ok());
70+
let pcv = pcv.unwrap();
71+
assert_eq!(pcv, Pcv::Absolute);
72+
73+
let pcv = Pcv::from_str("R");
74+
assert!(pcv.is_ok());
75+
let pcv = pcv.unwrap();
76+
assert_eq!(pcv, Pcv::Relative(String::from("AOAD/M_T")));
77+
}
78+
}

rinex/src/channel.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,18 @@ impl Channel {
278278
mod test {
279279
use super::*;
280280
use std::str::FromStr;
281-
/*#[test]
282-
fn test_code() {
283-
assert_eq!(Code::from_str("C1").is_ok(), true);
284-
assert_eq!(Code::from_str("L1").is_err(), true);
285-
assert_eq!(Code::from_str("P1").is_ok(), true);
286-
}*/
287281
#[test]
288282
fn test_channel() {
289-
assert_eq!(Channel::from_str("L1").is_ok(), true);
290-
assert_eq!(Channel::from_str("C1").is_err(), true);
291-
assert_eq!(Channel::from_str("L5").is_ok(), true);
283+
assert!(Channel::from_str("L1").is_ok());
284+
assert!(Channel::from_str("C1").is_err());
285+
assert!(Channel::from_str("L5").is_ok());
286+
287+
let l1 = Channel::from_str("L1").unwrap();
288+
assert_eq!(l1.carrier_frequency_mhz(), 1575.42_f64);
289+
assert_eq!(l1.carrier_wavelength(), 299792458.0 / 1575.42_f64 / 10.0E6);
290+
let channel = Channel::from_observable(Constellation::GPS, "L1C");
291+
assert!(channel.is_ok());
292+
let channel = channel.unwrap();
293+
assert_eq!(channel, Channel::L1);
292294
}
293295
}

rinex/src/epoch/flag.rs

+10
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,14 @@ mod test {
101101
assert_eq!(EpochFlag::from_str("6").unwrap(), EpochFlag::CycleSlip);
102102
assert!(EpochFlag::from_str("7").is_err());
103103
}
104+
#[test]
105+
fn to_str() {
106+
assert_eq!(format!("{}", EpochFlag::Ok), "0");
107+
assert_eq!(format!("{}", EpochFlag::PowerFailure), "1");
108+
assert_eq!(format!("{}", EpochFlag::AntennaBeingMoved), "2");
109+
assert_eq!(format!("{}", EpochFlag::NewSiteOccupation), "3");
110+
assert_eq!(format!("{}", EpochFlag::HeaderInformationFollows), "4");
111+
assert_eq!(format!("{}", EpochFlag::ExternalEvent), "5");
112+
assert_eq!(format!("{}", EpochFlag::CycleSlip), "6");
113+
}
104114
}

rinex/src/hardware.rs

+16
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,19 @@ impl SvAntenna {
138138
s
139139
}
140140
}
141+
142+
#[cfg(test)]
143+
mod test {
144+
use super::*;
145+
use std::str::FromStr;
146+
#[test]
147+
fn rcvr_parser() {
148+
let content = "2090088 LEICA GR50 4.51 ";
149+
let rcvr = Rcvr::from_str(content);
150+
assert!(rcvr.is_ok());
151+
let rcvr = rcvr.unwrap();
152+
assert_eq!(rcvr.model, "LEICA GR50");
153+
assert_eq!(rcvr.sn, "2090088");
154+
assert_eq!(rcvr.firmware, "4.51");
155+
}
156+
}

rinex/src/ionex/grid.rs

+31-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#[cfg(feature = "serde")]
2-
use serde::Serialize;
31
use std::ops::Rem;
42
use thiserror::Error;
53

4+
#[cfg(feature = "serde")]
5+
use serde::Serialize;
6+
67
/// Grid definition Error
78
#[derive(Error, Debug)]
89
pub enum Error {
@@ -18,18 +19,21 @@ pub enum Error {
1819
#[derive(Debug, Clone, Default, PartialEq, PartialOrd)]
1920
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2021
pub struct GridLinspace {
21-
/// Grid start value, in km
22+
/// Grid start coordinates [ddeg]
2223
pub start: f32,
23-
/// Grid end value, in km
24+
/// Grid end coordinates [ddeg]
2425
pub end: f32,
25-
/// Grid scaping / increment value, in km
26+
/// Grid spacing (inncrement value), [ddeg]
2627
pub spacing: f32,
2728
}
2829

2930
impl GridLinspace {
3031
/// Builds a new Linspace definition
3132
pub fn new(start: f32, end: f32, spacing: f32) -> Result<Self, Error> {
3233
let r = end.rem(start);
34+
/*
35+
* End / Start must be multiple of one another
36+
*/
3337
if r == 0.0 {
3438
if end.rem(spacing) == 0.0 {
3539
Ok(Self {
@@ -44,10 +48,9 @@ impl GridLinspace {
4448
Err(Error::GridStartEndError)
4549
}
4650
}
47-
// Returns total distance, in km, covered by
48-
// this Grid linear space
49-
pub fn total_distance(&self) -> f32 {
50-
(self.end - self.start) * self.spacing
51+
// Returns grid length, in terms of data points
52+
pub fn length(&self) -> usize {
53+
(self.end / self.spacing).floor() as usize
5154
}
5255
/// Returns true if self is a single point space
5356
pub fn is_single_point(&self) -> bool {
@@ -91,8 +94,24 @@ impl Grid {
9194
pub fn is_2d_grid(&self) -> bool {
9295
self.height.is_single_point()
9396
}
94-
/// Returns total projected 2D area covered [km²]
95-
pub fn total_area(&self) -> f32 {
96-
self.latitude.total_distance() * self.longitude.total_distance()
97+
}
98+
99+
#[cfg(test)]
100+
mod test {
101+
use super::*;
102+
#[test]
103+
fn test_grid() {
104+
let default = GridLinspace::default();
105+
assert_eq!(
106+
default,
107+
GridLinspace {
108+
start: 0.0,
109+
end: 0.0,
110+
spacing: 0.0,
111+
}
112+
);
113+
let grid = GridLinspace::new(1.0, 10.0, 1.0).unwrap();
114+
assert_eq!(grid.length(), 10);
115+
assert_eq!(grid.is_single_point(), false);
97116
}
98117
}

rinex/src/ionex/system.rs

+13
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,16 @@ impl FromStr for RefSystem {
114114
}
115115
}
116116
}
117+
118+
#[cfg(test)]
119+
mod test {
120+
use super::*;
121+
#[test]
122+
fn test_refsystem() {
123+
let default = RefSystem::default();
124+
assert_eq!(
125+
default,
126+
RefSystem::GnssConstellation(Constellation::default())
127+
);
128+
}
129+
}

rinex/src/navigation/health.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub enum GloHealth {
9191

9292
impl Default for GloHealth {
9393
fn default() -> Self {
94-
Self::Healthy
94+
Self::Unhealthy
9595
}
9696
}
9797

@@ -119,3 +119,32 @@ bitflags! {
119119
const E5B_HS1 = 0x80;
120120
}
121121
}
122+
123+
#[cfg(test)]
124+
mod test {
125+
use super::*;
126+
#[test]
127+
fn test_gps() {
128+
assert_eq!(Health::default(), Health::Unhealthy);
129+
assert_eq!(format!("{:E}", Health::default()), "0E0");
130+
}
131+
#[test]
132+
fn test_irnss() {
133+
assert_eq!(IrnssHealth::default(), IrnssHealth::Unknown);
134+
assert_eq!(format!("{:E}", IrnssHealth::default()), "1E0");
135+
}
136+
#[test]
137+
fn test_geo_sbas() {
138+
assert_eq!(GeoHealth::default(), GeoHealth::Unknown);
139+
assert_eq!(format!("{:E}", Health::default()), "0E0");
140+
}
141+
#[test]
142+
fn test_glo() {
143+
assert_eq!(GloHealth::default(), GloHealth::Unhealthy);
144+
assert_eq!(format!("{:E}", GloHealth::default()), "4E0");
145+
}
146+
#[test]
147+
fn test_gal() {
148+
assert_eq!(GalHealth::default(), GalHealth::empty());
149+
}
150+
}

0 commit comments

Comments
 (0)