Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
By switching to assert + contains, we're reducing the risk of updates
to the results randomly breaking our tests
  • Loading branch information
urschrei committed Aug 12, 2021
1 parent 67c3553 commit 38b3e27
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
36 changes: 15 additions & 21 deletions src/opencage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<'a> Opencage<'a> {
/// let res = oc.forward_full(&address, bbox).unwrap();
/// let first_result = &res.results[0];
/// // the first result is correct
/// assert_eq!(first_result.formatted, "UCL, 188 Tottenham Court Road, London W1T 7PQ, United Kingdom");
/// assert!(first_result.formatted.contains("UCL, 188 Tottenham Court Road"));
///```
///
/// ```
Expand Down Expand Up @@ -237,10 +237,10 @@ impl<'a> Opencage<'a> {
/// );
/// let res = oc.forward_full(&address, bbox).unwrap();
/// let first_result = &res.results[0];
/// assert_eq!(
/// first_result.formatted,
/// "UCL, 188 Tottenham Court Road, London W1T 7PQ, United Kingdom"
/// );
/// assert!(
/// first_result.formatted.contains(
/// "UCL, 188 Tottenham Court Road"
/// ));
/// ```
pub fn forward_full<T, U>(
&self,
Expand Down Expand Up @@ -680,10 +680,7 @@ mod test {
};
let res = oc.forward_full(&address, bbox).unwrap();
let first_result = &res.results[0];
assert_eq!(
first_result.formatted,
"UCL, 188 Tottenham Court Road, London W1T 7PQ, United Kingdom"
);
assert!(first_result.formatted.contains("UCL"));
}
#[test]
fn forward_full_test_floats() {
Expand All @@ -695,10 +692,9 @@ mod test {
);
let res = oc.forward_full(&address, bbox).unwrap();
let first_result = &res.results[0];
assert_eq!(
first_result.formatted,
"UCL, 188 Tottenham Court Road, London W1T 7PQ, United Kingdom"
);
assert!(first_result
.formatted
.contains("UCL, 188 Tottenham Court Road"));
}
#[test]
fn forward_full_test_pointfrom() {
Expand All @@ -710,10 +706,9 @@ mod test {
);
let res = oc.forward_full(&address, bbox).unwrap();
let first_result = &res.results[0];
assert_eq!(
first_result.formatted,
"UCL, 188 Tottenham Court Road, London W1T 7PQ, United Kingdom"
);
assert!(first_result
.formatted
.contains("UCL, 188 Tottenham Court Road"));
}
#[test]
fn forward_full_test_pointinto() {
Expand All @@ -725,10 +720,9 @@ mod test {
);
let res = oc.forward_full(&address, bbox).unwrap();
let first_result = &res.results[0];
assert_eq!(
first_result.formatted,
"UCL, 188 Tottenham Court Road, London W1T 7PQ, United Kingdom"
);
assert!(first_result
.formatted
.contains("Tottenham Court Road, London"));
}
#[test]
fn forward_full_test_nobox() {
Expand Down
8 changes: 3 additions & 5 deletions src/openstreetmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ impl Openstreetmap {
/// (-0.13806939125061035, 51.51989264641164),
/// (-0.13427138328552246, 51.52319711775629),
/// );
/// let params = OpenstreetmapParams::new(&"University College London")
/// let params = OpenstreetmapParams::new(&"UCL CASA")
/// .with_addressdetails(true)
/// .with_viewbox(&viewbox)
/// .build();
/// let res: OpenstreetmapResponse<f64> = osm.forward_full(&params).unwrap();
/// let result = res.features[0].properties.clone();
/// assert!(result.display_name.contains("London Borough of Camden, London, Greater London"));
/// assert!(result.display_name.contains("Gordon Square"));
/// ```
pub fn forward_full<T>(
&self,
Expand Down Expand Up @@ -369,9 +369,7 @@ mod test {
.build();
let res: OpenstreetmapResponse<f64> = osm.forward_full(&params).unwrap();
let result = res.features[0].properties.clone();
assert!(result
.display_name
.contains("London Borough of Camden, London, Greater London"));
assert!(result.display_name.contains("Gordon Square"));
assert_eq!(result.address.unwrap().city.unwrap(), "London");
}

Expand Down

0 comments on commit 38b3e27

Please sign in to comment.