Skip to content

Commit

Permalink
Added more unit tests to metar.rs.
Browse files Browse the repository at this point in the history
  • Loading branch information
RRArny committed Nov 3, 2024
1 parent 4beb707 commit 06fb927
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ For wxfetch to work you will need a free account on https://avwx.rest/. Once you

Wxfetch is written in Rust. In order to build it, run `cargo build` for a debug build, for a production build run `cargo build --release`. This will generate a binary file within the `target` directory in the `debug` and `release` subdirectories respectively.

For working on Wxfetch this repository includes a bacon configuration. Run `bacon` to have a variety of jobs at your disposal. `bacon clippy` (or using the 'c' key) will run the clippy linter at a pedantic level. `bacon test` (or 't') will run the unit tests. `bacon tarpaulin` (or 'alt-t') will calculate the code coverage using the `tarpaulin` plugin. You can install bacon using `cargo install bacon`.
For working on Wxfetch this repository includes a bacon configuration. Run `bacon` to have a variety of jobs at your disposal. `bacon clippy` (or using the 'c' key) will run the clippy linter at a pedantic level. `bacon test` (or 't') will run the unit tests. `bacon tarpaulin` (or 'alt-t') will calculate the code coverage using the `tarpaulin` plugin. You can install bacon using `cargo install bacon` and tarpaulin with `cargo install cargo-tarpaulin`.

# Contributing

Expand Down
105 changes: 105 additions & 0 deletions src/metar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,109 @@ mod tests {
let actual = get_visibility(&json, Units::default());
assert!(actual.is_some_and(|v| v == expected));
}

#[test]
fn test_colourise_vis() {
let config = Config::default();
let vis = WxField::Visibility(9999);
let expected = colourise_visibility(9999, &config);
let actual = vis.colourise(&config);
assert_eq!(actual, expected);
}

#[test]
fn test_colourise_wind() {
let config = Config::default();
let wind = WxField::Wind {
direction: 0,
strength: 0,
gusts: 0,
unit: SpeedUnit::Kt,
};
let expected = colourise_wind(0, 0, 0, SpeedUnit::Kt, &config);
let actual = wind.colourise(&config);
assert_eq!(actual, expected);
}

#[test]
fn test_colourise_wind_var() {
let config = Config::default();
let wind = WxField::WindVariability {
low_dir: 0,
hi_dir: 10,
};
let expected = colourise_wind_var(0, 10, &config);
let actual = wind.colourise(&config);
assert_eq!(actual, expected);
}

#[test]
fn test_colourise_temp() {
let config = Config::default();
let temp = WxField::Temperature {
temp: 20,
dewpoint: 10,
unit: TemperatureUnit::C,
};
let expected = colourise_temperature(20, 10, TemperatureUnit::C, &config);
let actual = temp.colourise(&config);
assert_eq!(actual, expected);
}

#[test]
fn test_colourise_qnh() {
let config = Config::default();
let qnh = WxField::Qnh(1013, PressureUnit::Hpa);
let expected = colourise_qnh(1013, PressureUnit::Hpa, &config);
let actual = qnh.colourise(&config);
assert_eq!(actual, expected);
}

#[test]
fn test_colourise_wxcode() {
let config = Config::default();
let wxcode = WxField::WxCode(
WxCode::Ra,
WxCodeIntensity::Moderate,
WxCodeProximity::OnStation,
WxCodeDescription::None,
);
let expected = colourise_wx_code(
&WxCode::Ra,
&WxCodeIntensity::Moderate,
&WxCodeProximity::OnStation,
&WxCodeDescription::None,
&config,
);
let actual = wxcode.colourise(&config);
assert_eq!(actual, expected);
}

#[test]
fn test_colourise_rmk() {
let config = Config::default();
let rmk = WxField::Remarks("NONE".to_string());
let expected = "NONE".black().on_white();
let actual = rmk.colourise(&config);
assert_eq!(actual, expected);
}

#[test]
fn test_colourise_clouds() {
let config = Config::default();
let clouds = WxField::Clouds(Clouds::Sct, 5000);
let expected = colourise_clouds(&Clouds::Sct, 5000, &config);
let actual = clouds.colourise(&config);
assert_eq!(actual, expected);
}

#[test]
fn test_colourise_timestamp() {
let config = Config::default();
let fixed_offset = Utc::now().fixed_offset();
let timestamp = WxField::TimeStamp(fixed_offset);
let expected = colourize_timestamp(&fixed_offset, &config);
let actual = timestamp.colourise(&config);
assert_eq!(actual, expected);
}
}

0 comments on commit 06fb927

Please sign in to comment.