Skip to content

Commit

Permalink
Add tests for #30 and #32
Browse files Browse the repository at this point in the history
  • Loading branch information
noritada committed Jan 24, 2023
1 parent 44a1c1f commit 6d46e30
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 5 deletions.
25 changes: 23 additions & 2 deletions cli/tests/cli/commands/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,33 @@ test_operation_with_data_without_nan_values_and_byte_order_options! {
utils::testdata::flat_binary::jma_kousa_le()?
),
(
decoding_complex_packing_as_little_endian,
decoding_complex_packing_with_num_descriptor_octet_being_1_as_little_endian,
utils::testdata::grib2::noaa_gdas_12()?,
"0.0",
"-l",
utils::testdata::flat_binary::noaa_gdas_12_le()?
),
(
decoding_complex_packing_with_num_descriptor_octet_being_2_as_little_endian,
utils::testdata::grib2::jma_meps()?,
"0.2",
"-l",
utils::testdata::flat_binary::jma_meps_le()?
),
(
decoding_complex_packing_with_num_descriptor_octet_being_3_as_little_endian,
utils::testdata::grib2::noaa_gdas_0_10()?,
"0.0",
"-l",
utils::testdata::flat_binary::noaa_gdas_0_le()?
),
(
decoding_complex_packing_with_all_values_being_0_as_little_endian,
utils::testdata::grib2::noaa_gdas_46()?,
"0.0",
"-l",
utils::testdata::flat_binary::noaa_gdas_46_le()?
),
}

#[test]
Expand Down Expand Up @@ -243,7 +264,7 @@ test_operation_with_data_without_nan_values_compared_using_simple_packing! {
),
(
decoding_complex_packing_with_zero_width_groups_as_little_endian,
utils::testdata::grib2::noaa_gdas()?,
utils::testdata::grib2::noaa_gdas_0_10()?,
"2.0",
"-l",
f32::from_be_bytes([0x00, 0x00, 0x00, 0x00]),
Expand Down
22 changes: 21 additions & 1 deletion cli/tests/cli/utils/testdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@ pub(crate) mod grib2 {
)
}

pub(crate) fn noaa_gdas() -> Result<NamedTempFile, io::Error> {
pub(crate) fn noaa_gdas_0_10() -> Result<NamedTempFile, io::Error> {
unxz_to_tempfile(testdata_dir().join("gdas.t12z.pgrb2.0p25.f000.0-10.xz"))
}

pub(crate) fn noaa_gdas_12() -> Result<NamedTempFile, io::Error> {
unxz_to_tempfile(testdata_dir().join("gdas.t12z.pgrb2.0p25.f000.12.xz"))
}

pub(crate) fn noaa_gdas_46() -> Result<NamedTempFile, io::Error> {
unxz_to_tempfile(testdata_dir().join("gdas.t12z.pgrb2.0p25.f000.46.xz"))
}

pub(crate) fn multi_message_data(n: usize) -> Result<NamedTempFile, io::Error> {
let mut buf = Vec::new();
let mut out = NamedTempFile::new()?;
Expand Down Expand Up @@ -120,7 +128,19 @@ pub(crate) mod flat_binary {
unxz_as_bytes(testdata_dir().join("gen").join("tornado-wgrib2-le.bin.xz"))
}

pub(crate) fn noaa_gdas_0_le() -> Result<Vec<u8>, io::Error> {
unxz_as_bytes(testdata_dir().join("gen").join("gdas-0-wgrib2-le.bin.xz"))
}

pub(crate) fn noaa_gdas_2_le() -> Result<Vec<u8>, io::Error> {
unxz_as_bytes(testdata_dir().join("gen").join("gdas-2-wgrib2-le.bin.xz"))
}

pub(crate) fn noaa_gdas_12_le() -> Result<Vec<u8>, io::Error> {
unxz_as_bytes(testdata_dir().join("gen").join("gdas-12-wgrib2-le.bin.xz"))
}

pub(crate) fn noaa_gdas_46_le() -> Result<Vec<u8>, io::Error> {
unxz_as_bytes(testdata_dir().join("gen").join("gdas-46-wgrib2-le.bin.xz"))
}
}
12 changes: 10 additions & 2 deletions testdata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ Following data files are downloaded from [NOAA Operational Model Archive and Dis
The disclaimer is [available online](https://www.weather.gov/disclaimer).

- `gdas.t12z.pgrb2.0p25.f000.0-10.xz`
(Only the first 10 messages of 696 messages in a data file downloaded from
https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gdas.20230111/12/atmos/gdas.t12z.pgrb2.0p25.f000 )
(Only the first 10 messages of 696 messages in a data file downloaded from
https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gdas.20230111/12/atmos/gdas.t12z.pgrb2.0p25.f000 )
- `gdas.t12z.pgrb2.0p25.f000.12.xz`
(Only the 13th message of 696 messages in a data file downloaded from the same URL)
- `gdas.t12z.pgrb2.0p25.f000.46.xz`
(Only the 47th message of 696 messages in a data file downloaded from the same URL)

## Data files from JMA

Expand Down Expand Up @@ -75,4 +79,8 @@ $ wgrib2 -d 1 -order raw -no_header -bin cmc-glb-wgrib2-le.bin CMC_glb_TMP_ISBL_
$ wgrib2 -d 1 -order raw -no_header -bin gdas-0-wgrib2-le.bin gdas.t12z.pgrb2.0p25.f000.0-10
$ wgrib2 -d 3 -order raw -no_header -bin gdas-2-wgrib2-le.bin gdas.t12z.pgrb2.0p25.f000.0-10
$ wgrib2 -d 1 -order raw -no_header -bin gdas-12-wgrib2-le.bin gdas.t12z.pgrb2.0p25.f000.12
$ wgrib2 -d 1 -order raw -no_header -bin gdas-46-wgrib2-le.bin gdas.t12z.pgrb2.0p25.f000.46
```
Binary file added testdata/gdas.t12z.pgrb2.0p25.f000.12.xz
Binary file not shown.
Binary file added testdata/gdas.t12z.pgrb2.0p25.f000.46.xz
Binary file not shown.
Binary file added testdata/gen/gdas-12-wgrib2-le.bin.xz
Binary file not shown.
Binary file added testdata/gen/gdas-46-wgrib2-le.bin.xz
Binary file not shown.

0 comments on commit 6d46e30

Please sign in to comment.