From 72e7ad43e582c685f93d2a8250e28cf797abd313 Mon Sep 17 00:00:00 2001 From: Erb3 <49862976+Erb3@users.noreply.github.com> Date: Tue, 16 Jul 2024 10:16:03 +0200 Subject: [PATCH] tests: improve datasource unit tests --- src/datasource.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/datasource.rs b/src/datasource.rs index 6d26280..0488f13 100644 --- a/src/datasource.rs +++ b/src/datasource.rs @@ -19,7 +19,7 @@ impl City { } } -#[derive(Serialize)] +#[derive(Serialize, Clone)] pub struct AnonymizedCity { pub country: String, pub name: String, @@ -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); } }