use ::quickcheck::Arbitrary;
pub(crate) fn loudness(g: &mut ::quickcheck::Gen) -> crate::audio::Loudness {
fn finite(g: &mut ::quickcheck::Gen) -> f32 {
(i32::arbitrary(g).rem_euclid(20_000_001) - 10_000_000) as f32 / 100.0
}
crate::audio::Loudness::new(finite(g), finite(g), finite(g), finite(g))
}
pub(crate) fn fingerprint(g: &mut ::quickcheck::Gen) -> crate::audio::Fingerprint {
let algo_s = <::std::string::String as Arbitrary>::arbitrary(g);
let algo: ::smol_str::SmolStr = if algo_s.is_empty() {
::smol_str::SmolStr::new_inline("x")
} else {
algo_s.into()
};
let value = ::bytes::Bytes::from(<::std::vec::Vec<u8> as Arbitrary>::arbitrary(g));
crate::audio::Fingerprint::try_new(algo, value).expect("algo non-empty by construction")
}
pub(crate) fn cover_art(g: &mut ::quickcheck::Gen) -> crate::audio::CoverArt {
let mime_s = <::std::string::String as Arbitrary>::arbitrary(g);
let mime: ::smol_str::SmolStr = if mime_s.is_empty() {
::smol_str::SmolStr::new_static("application/octet-stream")
} else {
mime_s.into()
};
let data_v = <::std::vec::Vec<u8> as Arbitrary>::arbitrary(g);
let data = ::bytes::Bytes::from(if data_v.is_empty() {
::std::vec![0u8]
} else {
data_v
});
crate::audio::CoverArt::try_new(mime, data).expect("mime + data non-empty by construction")
}
pub(crate) fn tags(g: &mut ::quickcheck::Gen) -> crate::audio::Tags {
crate::audio::Tags::new()
.with_title(::smol_str::SmolStr::from(
<::std::string::String as Arbitrary>::arbitrary(g),
))
.with_artist(::smol_str::SmolStr::from(
<::std::string::String as Arbitrary>::arbitrary(g),
))
.with_album_artist(::smol_str::SmolStr::from(
<::std::string::String as Arbitrary>::arbitrary(g),
))
.with_album(::smol_str::SmolStr::from(
<::std::string::String as Arbitrary>::arbitrary(g),
))
.with_composer(::smol_str::SmolStr::from(
<::std::string::String as Arbitrary>::arbitrary(g),
))
.with_genre(::smol_str::SmolStr::from(
<::std::string::String as Arbitrary>::arbitrary(g),
))
.with_comment(::smol_str::SmolStr::from(
<::std::string::String as Arbitrary>::arbitrary(g),
))
.with_year(<u16 as Arbitrary>::arbitrary(g))
.with_track_number(<u16 as Arbitrary>::arbitrary(g))
.with_track_total(<u16 as Arbitrary>::arbitrary(g))
.with_disc_number(<u16 as Arbitrary>::arbitrary(g))
.with_disc_total(<u16 as Arbitrary>::arbitrary(g))
.maybe_language(if bool::arbitrary(g) {
Some(language(g))
} else {
None
})
}
pub(crate) fn capture_device(g: &mut ::quickcheck::Gen) -> crate::capture::Device {
crate::capture::Device::new()
.with_make(::smol_str::SmolStr::from(
<::std::string::String as Arbitrary>::arbitrary(g),
))
.with_model(::smol_str::SmolStr::from(
<::std::string::String as Arbitrary>::arbitrary(g),
))
}
pub(crate) fn geo_location(g: &mut ::quickcheck::Gen) -> crate::capture::GeoLocation {
let lat = (i32::arbitrary(g).rem_euclid(18_001) - 9_000) as f64 / 100.0;
let lon = (i32::arbitrary(g).rem_euclid(36_001) - 18_000) as f64 / 100.0;
let altitude = if bool::arbitrary(g) {
Some((i32::arbitrary(g).rem_euclid(101_001) - 1_000) as f32)
} else {
None
};
crate::capture::GeoLocation::try_new(lat, lon, altitude)
.expect("lat/lon in-range and altitude finite by construction")
}
pub(crate) fn language(g: &mut ::quickcheck::Gen) -> crate::lang::Language {
const TAGS: &[&str] = &[
"und",
"en",
"en-US",
"es",
"fr",
"de",
"ja",
"zh-Hant-TW",
"pt-BR",
"ar",
"ru",
"ko",
];
let tag: &&str = g.choose(TAGS).expect("non-empty curated TAGS slice");
crate::lang::Language::from_bcp47(tag).expect("curated BCP-47 tag must parse")
}