diff --git a/CMakeLists.txt b/CMakeLists.txt index e5d2e8e0b..dd6e4e488 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,6 @@ set(FAKER_SOURCES src/modules/medicine/Medicine.cpp src/modules/movie/Movie.cpp src/modules/music/Music.cpp - src/modules/number/Number.cpp src/modules/person/Person.cpp src/modules/phone/Phone.cpp src/modules/plant/Plant.cpp diff --git a/include/faker-cxx/Science.h b/include/faker-cxx/Science.h index 9507839d3..9cc4b53e7 100644 --- a/include/faker-cxx/Science.h +++ b/include/faker-cxx/Science.h @@ -2,104 +2,99 @@ #include -namespace faker +namespace faker::science { -class Science +struct ChemicalElement { -public: - struct ChemicalElement - { - std::string_view name; - std::string_view symbol; - int atomicNumber; - }; - - /** - * @brief Returns a random chemical element from the periodic table. - * - * @returns ChemicalElement - * - * @code - * Science::chemicalElement() // Object of ChemicalElement containing info about a random element in the periodic - * table. - * @endcode - */ - static ChemicalElement chemicalElement(); + std::string_view name; + std::string_view symbol; + int atomicNumber; +}; - struct Unit - { - std::string_view name; - std::string_view symbol; - std::string_view usedToMeasure; - }; +/** + * @brief Returns a random chemical element from the periodic table. + * + * @returns ChemicalElement + * + * @code + * Science::chemicalElement() // Object of ChemicalElement containing info about a random element in the periodic + * table. + * @endcode + */ +ChemicalElement chemicalElement(); - /** - * @brief Returns a unit of measurement for either distance, mass, time, temp, current. - * - * @returns Unit - * - * @code - * Science::unit() // Object of Unit containing info about a random unit of measurement. - * @endcode - */ - static Unit unit(); +struct Unit +{ + std::string_view name; + std::string_view symbol; + std::string_view usedToMeasure; +}; - /** - * @brief Returns a unit of measurement for either distance. - * - * @returns Unit - * - * @code - * Science::distanceUnit() // Object of Unit containing info about a random unit of measurement used to measure - * distance. - * @endcode - */ - static Unit distanceUnit(); +/** + * @brief Returns a unit of measurement for either distance, mass, time, temp, current. + * + * @returns Unit + * + * @code + * Science::unit() // Object of Unit containing info about a random unit of measurement. + * @endcode + */ +Unit unit(); - /** - * @brief Returns a unit of measurement for either time. - * - * @returns Unit - * - * @code - * Science::timeUnit() // Object of Unit containing info about a random unit of measurement used to measure time. - * @endcode - */ - static Unit timeUnit(); +/** + * @brief Returns a unit of measurement for either distance. + * + * @returns Unit + * + * @code + * Science::distanceUnit() // Object of Unit containing info about a random unit of measurement used to measure + * distance. + * @endcode + */ +Unit distanceUnit(); - /** - * @brief Returns a unit of measurement for either mass. - * - * @returns Unit - * - * @code - * Science::massUnit() // Object of Unit containing info about a random unit of measurement used to measure mass. - * @endcode - */ - static Unit massUnit(); +/** + * @brief Returns a unit of measurement for either time. + * + * @returns Unit + * + * @code + * Science::timeUnit() // Object of Unit containing info about a random unit of measurement used to measure time. + * @endcode + */ +Unit timeUnit(); - /** - * @brief Returns a unit of measurement for either temp. - * - * @returns Unit - * - * @code - * Science::tempUnit() // Object of Unit containing info about a random unit of measurement used to measure temp. - * @endcode - */ - static Unit tempUnit(); +/** + * @brief Returns a unit of measurement for either mass. + * + * @returns Unit + * + * @code + * Science::massUnit() // Object of Unit containing info about a random unit of measurement used to measure mass. + * @endcode + */ +Unit massUnit(); - /** - * @brief Returns a unit of measurement for either current. - * - * @returns Unit - * - * @code - * Science::currentUnit() // Object of Unit containing info about a random unit of measurement used to measure - * current. - * @endcode - */ - static Unit currentUnit(); -}; +/** + * @brief Returns a unit of measurement for either temp. + * + * @returns Unit + * + * @code + * Science::tempUnit() // Object of Unit containing info about a random unit of measurement used to measure temp. + * @endcode + */ +Unit tempUnit(); +/** + * @brief Returns a unit of measurement for either current. + * + * @returns Unit + * + * @code + * Science::currentUnit() // Object of Unit containing info about a random unit of measurement used to measure + * current. + * @endcode + */ +Unit currentUnit(); } diff --git a/src/modules/number/Number.cpp b/src/modules/number/Number.cpp deleted file mode 100644 index 891132779..000000000 --- a/src/modules/number/Number.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "faker-cxx/Number.h" diff --git a/src/modules/science/Science.cpp b/src/modules/science/Science.cpp index a533e0a18..52ffc6cfe 100644 --- a/src/modules/science/Science.cpp +++ b/src/modules/science/Science.cpp @@ -3,46 +3,47 @@ #include "faker-cxx/Helper.h" #include "ScienceData.h" -namespace faker +namespace faker::science { -Science::ChemicalElement Science::chemicalElement() +ChemicalElement chemicalElement() { return helper::arrayElement(chemicalElements); } -Science::Unit Science::unit() +Unit unit() { - std::vector units; + std::vector units; + units.insert(units.end(), distanceUnits.begin(), distanceUnits.end()); units.insert(units.end(), massUnits.begin(), massUnits.end()); units.insert(units.end(), timeUnits.begin(), timeUnits.end()); units.insert(units.end(), currentUnits.begin(), currentUnits.end()); units.insert(units.end(), temperatureUnits.begin(), temperatureUnits.end()); - return helper::arrayElement(units); + return helper::arrayElement(units); } -Science::Unit Science::distanceUnit() +Unit distanceUnit() { return helper::arrayElement(distanceUnits); } -Science::Unit Science::timeUnit() +Unit timeUnit() { return helper::arrayElement(timeUnits); } -Science::Unit Science::massUnit() +Unit massUnit() { return helper::arrayElement(massUnits); } -Science::Unit Science::tempUnit() +Unit tempUnit() { return helper::arrayElement(temperatureUnits); } -Science::Unit Science::currentUnit() +Unit currentUnit() { return helper::arrayElement(currentUnits); } diff --git a/src/modules/science/ScienceData.h b/src/modules/science/ScienceData.h index e56ac73b1..f313a1b86 100644 --- a/src/modules/science/ScienceData.h +++ b/src/modules/science/ScienceData.h @@ -4,42 +4,41 @@ #include "faker-cxx/Science.h" -namespace faker +namespace faker::science { -const auto chemicalElements = std::to_array({ - {"Hydrogen", "H", 1}, {"Helium", "He", 2}, {"Lithium", "Li", 3}, {"Beryllium", "Be", 4}, - {"Boron", "B", 5}, {"Carbon", "C", 6}, {"Nitrogen", "N", 7}, {"Oxygen", "O", 8}, - {"Fluorine", "F", 9}, {"Neon", "Ne", 10}, {"Sodium", "Na", 11}, {"Magnesium", "Mg", 12}, - {"Aluminum", "Al", 13}, {"Silicon", "Si", 14}, {"Phosphorus", "P", 15}, {"Sulfur", "S", 16}, - {"Chlorine", "Cl", 17}, {"Argon", "Ar", 18}, {"Potassium", "K", 19}, {"Calcium", "Ca", 20}, - {"Scandium", "Sc", 21}, {"Titanium", "Ti", 22}, {"Vanadium", "V", 23}, {"Chromium", "Cr", 24}, - {"Manganese", "Mn", 25}, {"Iron", "Fe", 26}, {"Cobalt", "Co", 27}, {"Nickel", "Ni", 28}, - {"Copper", "Cu", 29}, {"Zinc", "Zn", 30}, {"Gallium", "Ga", 31}, {"Germanium", "Ge", 32}, - {"Arsenic", "As", 33}, {"Selenium", "Se", 34}, {"Bromine", "Br", 35}, {"Krypton", "Kr", 36}, - {"Rubidium", "Rb", 37}, {"Strontium", "Sr", 38}, {"Yttrium", "Y", 39}, {"Zirconium", "Zr", 40}, - {"Niobium", "Nb", 41}, {"Molybdenum", "Mo", 42}, {"Technetium", "Tc", 43}, {"Ruthenium", "Ru", 44}, - {"Rhodium", "Rh", 45}, {"Palladium", "Pd", 46}, {"Silver", "Ag", 47}, {"Cadmium", "Cd", 48}, - {"Indium", "In", 49}, {"Tin", "Sn", 50}, {"Antimony", "Sb", 51}, {"Tellurium", "Te", 52}, - {"Iodine", "I", 53}, {"Xenon", "Xe", 54}, {"Cesium", "Cs", 55}, {"Barium", "Ba", 56}, - {"Lanthanum", "La", 57}, {"Cerium", "Ce", 58}, {"Praseodymium", "Pr", 59}, {"Neodymium", "Nd", 60}, - {"Promethium", "Pm", 61}, {"Samarium", "Sm", 62}, {"Europium", "Eu", 63}, {"Gadolinium", "Gd", 64}, - {"Terbium", "Tb", 65}, {"Dysprosium", "Dy", 66}, {"Holmium", "Ho", 67}, {"Erbium", "Er", 68}, - {"Thulium", "Tm", 69}, {"Ytterbium", "Yb", 70}, {"Lutetium", "Lu", 71}, {"Hafnium", "Hf", 72}, - {"Tantalum", "Ta", 73}, {"Tungsten", "W", 74}, {"Rhenium", "Re", 75}, {"Osmium", "Os", 76}, - {"Iridium", "Ir", 77}, {"Platinum", "Pt", 78}, {"Gold", "Au", 79}, {"Mercury", "Hg", 80}, - {"Thallium", "Tl", 81}, {"Lead", "Pb", 82}, {"Bismuth", "Bi", 83}, {"Polonium", "Po", 84}, - {"Astatine", "At", 85}, {"Radon", "Rn", 86}, {"Francium", "Fr", 87}, {"Radium", "Ra", 88}, - {"Actinium", "Ac", 89}, {"Thorium", "Th", 90}, {"Protactinium", "Pa", 91}, {"Uranium", "U", 92}, - {"Neptunium", "Np", 93}, {"Plutonium", "Pu", 94}, {"Americium", "Am", 95}, {"Curium", "Cm", 96}, - {"Berkelium", "Bk", 97}, {"Californium", "Cf", 98}, {"Einsteinium", "Es", 99}, {"Fermium", "Fm", 100}, - {"Mendelevium", "Md", 101}, {"Nobelium", "No", 102}, {"Lawrencium", "Lr", 103}, {"Rutherfordium", "Rf", 104}, - {"Dubnium", "Db", 105}, {"Seaborgium", "Sg", 106}, {"Bohrium", "Bh", 107}, {"Hassium", "Hs", 108}, - {"Meitnerium", "Mt", 109}, {"Darmstadtium", "Ds", 110}, {"Roentgenium", "Rg", 111}, {"Copernicium", "Cn", 112}, - {"Nihonium", "Nh", 113}, {"Flerovium", "Fl", 114}, {"Moscovium", "Mc", 115}, {"Livermorium", "Lv", 116}, - {"Tennessine", "Ts", 117}, {"Oganesson", "Og", 118} -}); +const auto chemicalElements = std::to_array( + {{"Hydrogen", "H", 1}, {"Helium", "He", 2}, {"Lithium", "Li", 3}, {"Beryllium", "Be", 4}, + {"Boron", "B", 5}, {"Carbon", "C", 6}, {"Nitrogen", "N", 7}, {"Oxygen", "O", 8}, + {"Fluorine", "F", 9}, {"Neon", "Ne", 10}, {"Sodium", "Na", 11}, {"Magnesium", "Mg", 12}, + {"Aluminum", "Al", 13}, {"Silicon", "Si", 14}, {"Phosphorus", "P", 15}, {"Sulfur", "S", 16}, + {"Chlorine", "Cl", 17}, {"Argon", "Ar", 18}, {"Potassium", "K", 19}, {"Calcium", "Ca", 20}, + {"Scandium", "Sc", 21}, {"Titanium", "Ti", 22}, {"Vanadium", "V", 23}, {"Chromium", "Cr", 24}, + {"Manganese", "Mn", 25}, {"Iron", "Fe", 26}, {"Cobalt", "Co", 27}, {"Nickel", "Ni", 28}, + {"Copper", "Cu", 29}, {"Zinc", "Zn", 30}, {"Gallium", "Ga", 31}, {"Germanium", "Ge", 32}, + {"Arsenic", "As", 33}, {"Selenium", "Se", 34}, {"Bromine", "Br", 35}, {"Krypton", "Kr", 36}, + {"Rubidium", "Rb", 37}, {"Strontium", "Sr", 38}, {"Yttrium", "Y", 39}, {"Zirconium", "Zr", 40}, + {"Niobium", "Nb", 41}, {"Molybdenum", "Mo", 42}, {"Technetium", "Tc", 43}, {"Ruthenium", "Ru", 44}, + {"Rhodium", "Rh", 45}, {"Palladium", "Pd", 46}, {"Silver", "Ag", 47}, {"Cadmium", "Cd", 48}, + {"Indium", "In", 49}, {"Tin", "Sn", 50}, {"Antimony", "Sb", 51}, {"Tellurium", "Te", 52}, + {"Iodine", "I", 53}, {"Xenon", "Xe", 54}, {"Cesium", "Cs", 55}, {"Barium", "Ba", 56}, + {"Lanthanum", "La", 57}, {"Cerium", "Ce", 58}, {"Praseodymium", "Pr", 59}, {"Neodymium", "Nd", 60}, + {"Promethium", "Pm", 61}, {"Samarium", "Sm", 62}, {"Europium", "Eu", 63}, {"Gadolinium", "Gd", 64}, + {"Terbium", "Tb", 65}, {"Dysprosium", "Dy", 66}, {"Holmium", "Ho", 67}, {"Erbium", "Er", 68}, + {"Thulium", "Tm", 69}, {"Ytterbium", "Yb", 70}, {"Lutetium", "Lu", 71}, {"Hafnium", "Hf", 72}, + {"Tantalum", "Ta", 73}, {"Tungsten", "W", 74}, {"Rhenium", "Re", 75}, {"Osmium", "Os", 76}, + {"Iridium", "Ir", 77}, {"Platinum", "Pt", 78}, {"Gold", "Au", 79}, {"Mercury", "Hg", 80}, + {"Thallium", "Tl", 81}, {"Lead", "Pb", 82}, {"Bismuth", "Bi", 83}, {"Polonium", "Po", 84}, + {"Astatine", "At", 85}, {"Radon", "Rn", 86}, {"Francium", "Fr", 87}, {"Radium", "Ra", 88}, + {"Actinium", "Ac", 89}, {"Thorium", "Th", 90}, {"Protactinium", "Pa", 91}, {"Uranium", "U", 92}, + {"Neptunium", "Np", 93}, {"Plutonium", "Pu", 94}, {"Americium", "Am", 95}, {"Curium", "Cm", 96}, + {"Berkelium", "Bk", 97}, {"Californium", "Cf", 98}, {"Einsteinium", "Es", 99}, {"Fermium", "Fm", 100}, + {"Mendelevium", "Md", 101}, {"Nobelium", "No", 102}, {"Lawrencium", "Lr", 103}, {"Rutherfordium", "Rf", 104}, + {"Dubnium", "Db", 105}, {"Seaborgium", "Sg", 106}, {"Bohrium", "Bh", 107}, {"Hassium", "Hs", 108}, + {"Meitnerium", "Mt", 109}, {"Darmstadtium", "Ds", 110}, {"Roentgenium", "Rg", 111}, {"Copernicium", "Cn", 112}, + {"Nihonium", "Nh", 113}, {"Flerovium", "Fl", 114}, {"Moscovium", "Mc", 115}, {"Livermorium", "Lv", 116}, + {"Tennessine", "Ts", 117}, {"Oganesson", "Og", 118}}); -const auto distanceUnits = std::to_array({ +const auto distanceUnits = std::to_array({ {"Millimeter", "mm", "Length"}, {"Centimeter", "cm", "Length"}, {"Meter", "m", "Length"}, @@ -50,7 +49,7 @@ const auto distanceUnits = std::to_array({ {"Mile", "mi", "Length"}, }); -const auto massUnits = std::to_array({ +const auto massUnits = std::to_array({ {"Gram", "g", "Mass"}, {"Kilogram", "kg", "Mass"}, {"Milligram", "mg", "Mass"}, @@ -61,7 +60,7 @@ const auto massUnits = std::to_array({ {"Slug", "sl", "Mass"}, }); -const auto timeUnits = std::to_array({ +const auto timeUnits = std::to_array({ {"Second", "s", "Time"}, {"Minute", "min", "Time"}, {"Hour", "hr", "Time"}, @@ -71,13 +70,13 @@ const auto timeUnits = std::to_array({ {"Year", "yr", "Time"}, }); -const auto currentUnits = std::to_array({ +const auto currentUnits = std::to_array({ {"Ampere", "A", "Electric Current"}, {"Milliampere", "mA", "Electric Current"}, {"Microampere", "μA", "Electric Current"}, }); -const auto temperatureUnits = std::to_array({ +const auto temperatureUnits = std::to_array({ {"Celcius", "°C", "Temperature"}, {"Fahrenheit", "°F", "Temperature"}, {"Kelvin", "K", "Temperature"}, diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index 38d2ac36d..e4724edf2 100644 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -1,6 +1,5 @@ #include "faker-cxx/System.h" -#include #include #include #include diff --git a/src/modules/vehicle/Vehicle.cpp b/src/modules/vehicle/Vehicle.cpp index a856c3808..9949fce60 100644 --- a/src/modules/vehicle/Vehicle.cpp +++ b/src/modules/vehicle/Vehicle.cpp @@ -11,7 +11,6 @@ namespace faker::vehicle { - std::string_view bicycle() { return helper::arrayElement(bicycle_types); diff --git a/tests/modules/science/ScienceTest.cpp b/tests/modules/science/ScienceTest.cpp index e8e23c4f2..4d7b4aeac 100644 --- a/tests/modules/science/ScienceTest.cpp +++ b/tests/modules/science/ScienceTest.cpp @@ -9,18 +9,18 @@ using namespace ::testing; using namespace faker; +using namespace science; class ScienceTest : public Test { public: - static bool chemicalElementsAreEqual(const Science::ChemicalElement& chemElement1, - const Science::ChemicalElement& chemElement2) + static bool chemicalElementsAreEqual(const ChemicalElement& chemElement1, const ChemicalElement& chemElement2) { return chemElement1.name == chemElement2.name && chemElement1.symbol == chemElement2.symbol && chemElement1.atomicNumber == chemElement2.atomicNumber; } - static bool unitsAreEqual(const Science::Unit& unit1, const Science::Unit& unit2) + static bool unitsAreEqual(const Unit& unit1, const Unit& unit2) { return unit1.name == unit2.name && unit1.symbol == unit2.symbol && unit1.usedToMeasure == unit2.usedToMeasure; } @@ -28,57 +28,63 @@ class ScienceTest : public Test TEST_F(ScienceTest, shouldGenerateChemElement) { - const auto generatedChemElement = Science::chemicalElement(); - ASSERT_TRUE(std::ranges::any_of(chemicalElements, - [generatedChemElement](const Science::ChemicalElement& chemElement) + const auto generatedChemElement = chemicalElement(); + + ASSERT_TRUE(std::ranges::any_of(chemicalElements, [generatedChemElement](const ChemicalElement& chemElement) { return chemicalElementsAreEqual(generatedChemElement, chemElement); })); } TEST_F(ScienceTest, shouldGenerateAnyUnit) { - const auto generatedAnyUnit = Science::unit(); - std::vector units; + std::vector units; units.insert(units.end(), distanceUnits.begin(), distanceUnits.end()); units.insert(units.end(), massUnits.begin(), massUnits.end()); units.insert(units.end(), timeUnits.begin(), timeUnits.end()); units.insert(units.end(), currentUnits.begin(), currentUnits.end()); units.insert(units.end(), temperatureUnits.begin(), temperatureUnits.end()); - ASSERT_TRUE(std::ranges::any_of(units, [generatedAnyUnit](const Science::Unit& unit) + const auto generatedAnyUnit = unit(); + + ASSERT_TRUE(std::ranges::any_of(units, [generatedAnyUnit](const Unit& unit) { return unitsAreEqual(generatedAnyUnit, unit); })); } TEST_F(ScienceTest, shouldGenerateDistanceUnit) { - const auto generatedDistanceUnit = Science::distanceUnit(); - ASSERT_TRUE(std::ranges::any_of(distanceUnits, [generatedDistanceUnit](const Science::Unit& distanceUnit) + const auto generatedDistanceUnit = distanceUnit(); + + ASSERT_TRUE(std::ranges::any_of(distanceUnits, [generatedDistanceUnit](const Unit& distanceUnit) { return unitsAreEqual(generatedDistanceUnit, distanceUnit); })); } TEST_F(ScienceTest, shouldGenerateMassUnit) { - const auto generatedMassUnit = Science::massUnit(); - ASSERT_TRUE(std::ranges::any_of(massUnits, [generatedMassUnit](const Science::Unit& massUnit) + const auto generatedMassUnit = massUnit(); + + ASSERT_TRUE(std::ranges::any_of(massUnits, [generatedMassUnit](const Unit& massUnit) { return unitsAreEqual(generatedMassUnit, massUnit); })); } TEST_F(ScienceTest, shouldGenerateTimeUnit) { - const auto generatedTimeUnit = Science::timeUnit(); - ASSERT_TRUE(std::ranges::any_of(timeUnits, [generatedTimeUnit](const Science::Unit& timeUnit) + const auto generatedTimeUnit = timeUnit(); + + ASSERT_TRUE(std::ranges::any_of(timeUnits, [generatedTimeUnit](const Unit& timeUnit) { return unitsAreEqual(generatedTimeUnit, timeUnit); })); } TEST_F(ScienceTest, shouldGenerateTempUnit) { - const auto generatedTempUnit = Science::tempUnit(); - ASSERT_TRUE(std::ranges::any_of(temperatureUnits, [generatedTempUnit](const Science::Unit& tempUnit) + const auto generatedTempUnit = tempUnit(); + + ASSERT_TRUE(std::ranges::any_of(temperatureUnits, [generatedTempUnit](const Unit& tempUnit) { return unitsAreEqual(generatedTempUnit, tempUnit); })); } TEST_F(ScienceTest, shouldGenerateCurrentUnit) { - const auto generatedCurrentUnit = Science::currentUnit(); - ASSERT_TRUE(std::ranges::any_of(currentUnits, [generatedCurrentUnit](const Science::Unit& currentUnit) + const auto generatedCurrentUnit = currentUnit(); + + ASSERT_TRUE(std::ranges::any_of(currentUnits, [generatedCurrentUnit](const Unit& currentUnit) { return unitsAreEqual(generatedCurrentUnit, currentUnit); })); }