Skip to content

Commit

Permalink
tests: improve datasource unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Erb3 committed Jul 16, 2024
1 parent fbd6fcc commit 692f76e
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/datasource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl City {
}
}

#[derive(Serialize)]
#[derive(Serialize, Clone)]
pub struct AnonymizedCity {
pub country: String,
pub name: String,
Expand Down Expand Up @@ -56,10 +56,23 @@ mod tests {

// Check if both the first and second city in the datasources matches
// If it does, this suggests that the cities are not randomized
assert!(
datasource1.cities.get(0).unwrap().name != datasource2.cities.get(0).unwrap().name
&& (datasource1.cities.get(1).unwrap().name
!= datasource2.cities.get(1).unwrap().name)
assert_ne!(
datasource1.cities.get(0).unwrap().name,
datasource2.cities.get(0).unwrap().name
);
assert_ne!(
datasource1.cities.get(1).unwrap().latitude,
datasource2.cities.get(1).unwrap().latitude
)
}

#[tokio::test]
async fn can_anonymize_city() {
let datasource = Datasource::new().await;
let city = datasource.cities.get(0).unwrap();
let anonymized = city.clone().anonymize();

assert_eq!(city.name, anonymized.name);
assert_eq!(city.country, anonymized.country);
}
}

0 comments on commit 692f76e

Please sign in to comment.