diff --git a/CMakeLists.txt b/CMakeLists.txt index 3da115a24..cbf0d5cfc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ set(FAKER_SOURCES src/modules/company/Company.cpp src/modules/company/CompanyData.cpp src/modules/computer/Computer.cpp + src/modules/computer/ComputerData.cpp src/modules/crypto/Crypto.cpp src/modules/database/Database.cpp src/modules/datatype/Datatype.cpp diff --git a/include/faker-cxx/Computer.h b/include/faker-cxx/Computer.h index d29ea885a..3c6d3af4b 100644 --- a/include/faker-cxx/Computer.h +++ b/include/faker-cxx/Computer.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace faker { @@ -16,7 +16,7 @@ class Computer * Computer::type() // Laptop * @endcode */ - static std::string type(); + static std::string_view type(); /** * @brief Returns a random computer manufacture name. @@ -27,7 +27,7 @@ class Computer * Computer::manufacture() // HP * @endcode */ - static std::string manufacture(); + static std::string_view manufacture(); /** * @brief Returns a random computer model. @@ -38,7 +38,7 @@ class Computer * Computer::model() // MacBook Air * @endcode */ - static std::string model(); + static std::string_view model(); /** * @brief Returns a random CPU manufacture name. @@ -49,7 +49,7 @@ class Computer * Computer::cpuManufacture() // Intel * @endcode */ - static std::string cpuManufacture(); + static std::string_view cpuManufacture(); /** * @brief Returns a random CPU type. @@ -60,7 +60,7 @@ class Computer * Computer::cpuType() // x86 * @endcode */ - static std::string cpuType(); + static std::string_view cpuType(); /** * @brief Returns a random CPU model. @@ -71,7 +71,7 @@ class Computer * Computer::cpuModel() // Core i9-11900k * @endcode */ - static std::string cpuModel(); + static std::string_view cpuModel(); /** * @brief Returns a random GPU manufacture name. @@ -82,7 +82,7 @@ class Computer * Computer::gpuManufacture() // NVIDIA * @endcode */ - static std::string gpuManufacture(); + static std::string_view gpuManufacture(); /** * @brief Returns a random GPU type. @@ -93,7 +93,7 @@ class Computer * Computer::gpuType() // Integrated * @endcode */ - static std::string gpuType(); + static std::string_view gpuType(); /** * @brief Returns a random GPU model. @@ -104,7 +104,7 @@ class Computer * Computer::gpuModel() // NVIDIA GeForce RTX 3080 * @endcode */ - static std::string gpuModel(); + static std::string_view gpuModel(); }; } diff --git a/src/modules/computer/Computer.cpp b/src/modules/computer/Computer.cpp index 65853d605..859991796 100644 --- a/src/modules/computer/Computer.cpp +++ b/src/modules/computer/Computer.cpp @@ -1,54 +1,52 @@ #include "faker-cxx/Computer.h" -#include - -#include "data/ComputerData.h" +#include "ComputerData.h" #include "faker-cxx/Helper.h" namespace faker { -std::string Computer::type() +std::string_view Computer::type() { - return Helper::arrayElement(data::ComputerTypes); + return Helper::arrayElement(computerTypes); } -std::string Computer::manufacture() +std::string_view Computer::manufacture() { - return Helper::arrayElement(data::ComputerManufactures); + return Helper::arrayElement(computerManufacturers); } -std::string Computer::model() +std::string_view Computer::model() { - return Helper::arrayElement(data::ComputerModels); + return Helper::arrayElement(computerModels); } -std::string Computer::cpuManufacture() +std::string_view Computer::cpuManufacture() { - return Helper::arrayElement(data::ComputerCPUManufactures); + return Helper::arrayElement(cpuManufacturers); } -std::string Computer::cpuType() +std::string_view Computer::cpuType() { - return Helper::arrayElement(data::ComputerCPUTypes); + return Helper::arrayElement(cpuTypes); } -std::string Computer::cpuModel() +std::string_view Computer::cpuModel() { - return Helper::arrayElement(data::ComputerCPUModels); + return Helper::arrayElement(cpuModels); } -std::string Computer::gpuManufacture() +std::string_view Computer::gpuManufacture() { - return Helper::arrayElement(data::ComputerGPUManufactures); + return Helper::arrayElement(gpuManufacturers); } -std::string Computer::gpuType() +std::string_view Computer::gpuType() { - return Helper::arrayElement(data::ComputerGPUTypes); + return Helper::arrayElement(gpuTypes); } -std::string Computer::gpuModel() +std::string_view Computer::gpuModel() { - return Helper::arrayElement(data::ComputerGPUModels); + return Helper::arrayElement(gpuModels); } } diff --git a/src/modules/computer/data/ComputerData.h b/src/modules/computer/ComputerData.cpp similarity index 80% rename from src/modules/computer/data/ComputerData.h rename to src/modules/computer/ComputerData.cpp index bef14429e..9f361069b 100644 --- a/src/modules/computer/data/ComputerData.h +++ b/src/modules/computer/ComputerData.cpp @@ -1,19 +1,14 @@ -#pragma once -#include -#include +#include "ComputerData.h" namespace faker { -namespace data -{ -const std::vector ComputerTypes = {"Desktop", "Laptop", "Mainframe", "Supercomputer"}; +const std::array computerTypes = {"Desktop", "Laptop", "Mainframe", "Supercomputer"}; -const std::vector ComputerManufactures = { +const std::array computerManufacturers = { "Apple", "Dell", "HP", "Lenovo", "Acer", "Asus", "Microsoft", "Samsung", "Toshiba", "Sony", "MSI", "Gateway", "Fujitsu", "HCL", "Panasonic", "LG", "IBM", "Compaq", "Alienware", "Razer"}; -// todo - it is possible to link the models to brands in the future. -const std::vector ComputerModels = { +const std::array computerModels = { "MacBook Air", "MacBook Pro", "iMac", "Mac mini", "Inspiron", "XPS", "Alienware", "Latitude", "Precision", "Spectre", "Envy", "Pavilion", "EliteBook", "ThinkPad", "Yoga", "Legion", "IdeaPad", "Aspire", "Predator", "TravelMate", "Swift", @@ -22,26 +17,24 @@ const std::vector ComputerModels = { "GL Series", "ThinkCentre", "ThinkStation", "Presario", "Area-51", "m15", "Aurora", "Blade", "Blade Stealth", "NUC"}; -const std::vector ComputerCPUManufactures = {"Intel", "AMD", "ARM", "IBM", "Apple"}; +const std::array cpuManufacturers = {"Intel", "AMD", "ARM", "IBM", "Apple"}; -const std::vector ComputerCPUTypes = { +const std::array cpuTypes = { "Dual-Core", "Quad-Core", "Hexa-Core", "Octa-Core", "Deca-Core", "Heterogeneous System Architecture", "ARM", "x86", "64-bit", "32-bit", "RISC", "CISC"}; -const std::vector ComputerCPUModels = { +const std::array cpuModels = { "Core i9-11900K", "Core i7-11700K", "Core i5-11600K", "Core i3-10100", "Xeon E-2278G", "Pentium Gold G6400", "Ryzen 9 5950X", "Ryzen 7 5800X", "Ryzen 5 5600X", "Ryzen 3 3300X", "EPYC 7763", "Athlon 3000G", "Apple M1", "Apple M1 Max", "Apple M1 Ultra", "Apple M2", "Apple M2 Pro", "Apple M2 Max", "Apple M3 Ultra", "Apple M3 Pro", "Apple M3 Max", "Apple M3 Ultra", "IBM POWER9", "ARM Cortex-A78", "ARM Cortex-A76", "ARM Cortex-A55"}; -const std::vector ComputerGPUManufactures = { - "NVIDIA", "AMD", "Intel", "ARM", "Qualcomm", -}; +const std::array gpuManufacturers = {"NVIDIA", "AMD", "Intel", "ARM", "Qualcomm"}; -const std::vector ComputerGPUTypes = {"Integrated", "Discrete"}; +const std::array gpuTypes = {"Integrated", "Discrete"}; -const std::vector ComputerGPUModels = {"NVIDIA GeForce RTX 3090", +const std::array gpuModels = {"NVIDIA GeForce RTX 3090", "NVIDIA GeForce RTX 3080", "NVIDIA GeForce RTX 3070", "NVIDIA GeForce GTX 1660 Ti", @@ -65,7 +58,4 @@ const std::vector ComputerGPUModels = {"NVIDIA GeForce RTX 3090", "Trident Blade3D", "ATI Radeon 9800 Pro"}; -// todo - add more component names - -} } diff --git a/src/modules/computer/ComputerData.h b/src/modules/computer/ComputerData.h new file mode 100644 index 000000000..1b07f7ef4 --- /dev/null +++ b/src/modules/computer/ComputerData.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +namespace faker +{ +extern const std::array computerTypes; +extern const std::array computerManufacturers; +extern const std::array computerModels; +extern const std::array cpuManufacturers; +extern const std::array cpuTypes; +extern const std::array cpuModels; +extern const std::array gpuManufacturers; +extern const std::array gpuTypes; +extern const std::array gpuModels; +} diff --git a/tests/modules/computer/ComputerTest.cpp b/tests/modules/computer/ComputerTest.cpp index 6c2c24583..710586ad2 100644 --- a/tests/modules/computer/ComputerTest.cpp +++ b/tests/modules/computer/ComputerTest.cpp @@ -1,87 +1,93 @@ #include "faker-cxx/Computer.h" #include -#include -#include #include "gtest/gtest.h" -#include "computer/data/ComputerData.h" +#include "computer/ComputerData.h" using namespace ::testing; using namespace faker; + class ComputerTest : public Test { }; TEST_F(ComputerTest, ComputerTypeGeneration) { - std::string generatedType = Computer::type(); - ASSERT_TRUE(std::ranges::any_of(faker::data::ComputerTypes.begin(), faker::data::ComputerTypes.end(), - [generatedType](const std::string& type) { return type == generatedType; })); + const auto generatedType = Computer::type(); + ASSERT_TRUE(std::ranges::any_of(computerTypes.begin(), computerTypes.end(), + [generatedType](const std::string_view& type) { return type == generatedType; })); } TEST_F(ComputerTest, ComputerManufactureGeneration) { - std::string generatedManufacture = Computer::manufacture(); - ASSERT_TRUE(std::ranges::any_of(faker::data::ComputerManufactures.begin(), faker::data::ComputerManufactures.end(), - [generatedManufacture](const std::string& manufacture) + const auto generatedManufacture = Computer::manufacture(); + + ASSERT_TRUE(std::ranges::any_of(computerManufacturers.begin(), computerManufacturers.end(), + [generatedManufacture](const std::string_view& manufacture) { return manufacture == generatedManufacture; })); } TEST_F(ComputerTest, ComputerModelGeneration) { - std::string generatedModel = Computer::model(); - ASSERT_TRUE(std::ranges::any_of(faker::data::ComputerModels.begin(), faker::data::ComputerModels.end(), - [generatedModel](const std::string& model) { return model == generatedModel; })); + const auto generatedModel = Computer::model(); + + ASSERT_TRUE(std::ranges::any_of(computerModels.begin(), computerModels.end(), + [generatedModel](const std::string_view& model) + { return model == generatedModel; })); } TEST_F(ComputerTest, ComputerCPUManufactureGeneration) { - std::string generatedCPUManufacture = Computer::cpuManufacture(); - ASSERT_TRUE(std::ranges::any_of(faker::data::ComputerCPUManufactures.begin(), - faker::data::ComputerCPUManufactures.end(), - [generatedCPUManufacture](const std::string& cpuManufacture) + const auto generatedCPUManufacture = Computer::cpuManufacture(); + + ASSERT_TRUE(std::ranges::any_of(cpuManufacturers.begin(), cpuManufacturers.end(), + [generatedCPUManufacture](const std::string_view& cpuManufacture) { return cpuManufacture == generatedCPUManufacture; })); } TEST_F(ComputerTest, ComputerCPUTypeGeneration) { - std::string generatedCPUType = Computer::cpuType(); - ASSERT_TRUE(std::ranges::any_of(faker::data::ComputerCPUTypes.begin(), faker::data::ComputerCPUTypes.end(), - [generatedCPUType](const std::string& cpuType) + const auto generatedCPUType = Computer::cpuType(); + + ASSERT_TRUE(std::ranges::any_of(cpuTypes.begin(), cpuTypes.end(), + [generatedCPUType](const std::string_view& cpuType) { return cpuType == generatedCPUType; })); } TEST_F(ComputerTest, ComputerCPUModelGeneration) { - std::string generatedCPUModel = Computer::cpuModel(); - ASSERT_TRUE(std::ranges::any_of(faker::data::ComputerCPUModels.begin(), faker::data::ComputerCPUModels.end(), - [generatedCPUModel](const std::string& cpuModel) + const auto generatedCPUModel = Computer::cpuModel(); + + ASSERT_TRUE(std::ranges::any_of(cpuModels.begin(), cpuModels.end(), + [generatedCPUModel](const std::string_view& cpuModel) { return cpuModel == generatedCPUModel; })); } TEST_F(ComputerTest, ComputerGPUManufactureGeneration) { - std::string generatedGPUManufacture = Computer::gpuManufacture(); - ASSERT_TRUE(std::ranges::any_of(faker::data::ComputerGPUManufactures.begin(), - faker::data::ComputerGPUManufactures.end(), - [generatedGPUManufacture](const std::string& gpuManufacture) + const auto generatedGPUManufacture = Computer::gpuManufacture(); + + ASSERT_TRUE(std::ranges::any_of(gpuManufacturers.begin(), gpuManufacturers.end(), + [generatedGPUManufacture](const std::string_view& gpuManufacture) { return gpuManufacture == generatedGPUManufacture; })); } TEST_F(ComputerTest, ComputerGPUTypeGeneration) { - std::string generatedGPUType = Computer::gpuType(); - ASSERT_TRUE(std::ranges::any_of(faker::data::ComputerGPUTypes.begin(), faker::data::ComputerGPUTypes.end(), - [generatedGPUType](const std::string& gpuType) + const auto generatedGPUType = Computer::gpuType(); + + ASSERT_TRUE(std::ranges::any_of(gpuTypes.begin(), gpuTypes.end(), + [generatedGPUType](const std::string_view& gpuType) { return gpuType == generatedGPUType; })); } TEST_F(ComputerTest, ComputerGPUModelGeneration) { - std::string generatedGPUModel = Computer::gpuModel(); - ASSERT_TRUE(std::ranges::any_of(faker::data::ComputerGPUModels.begin(), faker::data::ComputerGPUModels.end(), - [generatedGPUModel](const std::string& gpuModel) + const auto generatedGPUModel = Computer::gpuModel(); + + ASSERT_TRUE(std::ranges::any_of(gpuModels.begin(), gpuModels.end(), + [generatedGPUModel](const std::string_view& gpuModel) { return gpuModel == generatedGPUModel; })); }