Skip to content

Commit

Permalink
cleaned up test and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Martinez authored and Juan Martinez committed Nov 8, 2024
1 parent 2b61bf5 commit c05dc4a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/modules/location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ CountryAddressesInfo getAddresses(const Locale& locale)
return portugalAddresses;
case Locale::he_IL:
return israelAddresses;
case Locale::mx_MX:
case Locale::es_MX:
return mexicoAddresses;
default:
return usaAddresses;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/location_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -8093,7 +8093,7 @@ const auto mexicoCities = std::to_array<std::string_view>({
"Morelia",
"Nogales",
"Pachuca",
"Puebla".
"Puebla",
"Puerto Vallarta",
"Querétaro",
"Reynosa",
Expand Down Expand Up @@ -8226,7 +8226,7 @@ const CountryAddressesInfo mexicoAddresses{
(mexicoStreetFormats),
{},
{mexicoStreetNames},
(mexicoStreetSuffixes),
(mexicoStreetPrefixes),
(mexicoBuildingNumberFormats),
(mexicoCityFormats),
{},
Expand Down
35 changes: 5 additions & 30 deletions tests/modules/location_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ CountryAddressesInfo getAddresses(const Locale& locale)
return portugalAddresses;
case Locale::he_IL:
return israelAddresses;
case Locale::mx_MX:
case Locale::es_MX:
return mexicoAddresses;
default:
return usaAddresses;
Expand Down Expand Up @@ -1108,41 +1108,16 @@ TEST_F(LocationTest, shouldGenerateIsraelStreetAddress)

TEST_F(LocationTest, shouldGenerateMexicoStreet)
{
const auto generatedStreet = street(Locale::mx_MX);
const auto generatedStreet = street(Locale::es_MX);

ASSERT_TRUE(std::ranges::any_of(mexicoStreetNames, [&generatedStreet](const std::string_view& street)
{ return generatedStreet.find(street) != std::string::npos; }));
}

TEST_F(LocationTest, shouldGenerateMexicoStreetAddress)
{
const auto generatedStreetAddress = streetAddress(Locale::mx_MX);
const auto generatedStreetAddress = streetAddress(Locale::es_MX);

const auto generatedAddresses = common::split(generatedStreetAddress, ", ");
const auto generatedStreetAddressElements = common::split(generatedAddresses[0], " ");

const auto& generatedBuildingNumber = generatedStreetAddressElements[generatedStreetAddressElements.size() - 1];
const auto& generatedStreetSuffix = generatedStreetAddressElements[generatedStreetAddressElements.size() - 2];
const auto& generatedStreet =
common::join({generatedStreetAddressElements.begin(), generatedStreetAddressElements.end() - 2});

if (generatedAddresses.size() > 1)
{
const auto& generatedSecondaryAddressParts = common::split(generatedAddresses[1], " ");

const auto& generatedUnitNumber = generatedSecondaryAddressParts[generatedSecondaryAddressParts.size() - 1];

ASSERT_TRUE(generatedUnitNumber.size() == 1 || generatedUnitNumber.size() == 3);
ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedUnitNumber));
}

ASSERT_TRUE(!generatedBuildingNumber.empty() && generatedBuildingNumber.size() <= 3);
ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber));

ASSERT_TRUE(std::ranges::any_of(mexicoStreetNames, [&generatedStreet](const std::string_view& streetName)
{ return generatedStreet.find(streetName) != std::string::npos; }));

ASSERT_TRUE(std::ranges::any_of(mexicoStreetSuffixes,
[&generatedStreetSuffix](const std::string_view& streetSuffix)
{ return generatedStreetSuffix.find(streetSuffix) != std::string::npos; }));
ASSERT_TRUE(std::ranges::any_of(mexicoStreetNames, [&generatedStreetAddress](const std::string_view& streetName)
{ return generatedStreetAddress.find(streetName) != std::string::npos; }));
}

0 comments on commit c05dc4a

Please sign in to comment.