Skip to content

Commit

Permalink
refactor computer module data
Browse files Browse the repository at this point in the history
  • Loading branch information
cieslarmichal committed May 27, 2024
1 parent 80c9ae6 commit 6d23538
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 83 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions include/faker-cxx/Computer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <string>
#include <string_view>

namespace faker
{
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -104,7 +104,7 @@ class Computer
* Computer::gpuModel() // NVIDIA GeForce RTX 3080
* @endcode
*/
static std::string gpuModel();
static std::string_view gpuModel();
};

}
40 changes: 19 additions & 21 deletions src/modules/computer/Computer.cpp
Original file line number Diff line number Diff line change
@@ -1,54 +1,52 @@
#include "faker-cxx/Computer.h"

#include <string>

#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);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
#pragma once
#include <string>
#include <vector>
#include "ComputerData.h"

namespace faker
{
namespace data
{
const std::vector<std::string> ComputerTypes = {"Desktop", "Laptop", "Mainframe", "Supercomputer"};
const std::array<std::string_view, 4> computerTypes = {"Desktop", "Laptop", "Mainframe", "Supercomputer"};

const std::vector<std::string> ComputerManufactures = {
const std::array<std::string_view, 20> 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<std::string> ComputerModels = {
const std::array<std::string_view, 45> 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",
Expand All @@ -22,26 +17,24 @@ const std::vector<std::string> ComputerModels = {
"GL Series", "ThinkCentre", "ThinkStation", "Presario", "Area-51", "m15", "Aurora",
"Blade", "Blade Stealth", "NUC"};

const std::vector<std::string> ComputerCPUManufactures = {"Intel", "AMD", "ARM", "IBM", "Apple"};
const std::array<std::string_view, 5> cpuManufacturers = {"Intel", "AMD", "ARM", "IBM", "Apple"};

const std::vector<std::string> ComputerCPUTypes = {
const std::array<std::string_view, 12> 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<std::string> ComputerCPUModels = {
const std::array<std::string_view, 26> 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<std::string> ComputerGPUManufactures = {
"NVIDIA", "AMD", "Intel", "ARM", "Qualcomm",
};
const std::array<std::string_view, 5> gpuManufacturers = {"NVIDIA", "AMD", "Intel", "ARM", "Qualcomm"};

const std::vector<std::string> ComputerGPUTypes = {"Integrated", "Discrete"};
const std::array<std::string_view, 2> gpuTypes = {"Integrated", "Discrete"};

const std::vector<std::string> ComputerGPUModels = {"NVIDIA GeForce RTX 3090",
const std::array<std::string_view, 23> gpuModels = {"NVIDIA GeForce RTX 3090",
"NVIDIA GeForce RTX 3080",
"NVIDIA GeForce RTX 3070",
"NVIDIA GeForce GTX 1660 Ti",
Expand All @@ -65,7 +58,4 @@ const std::vector<std::string> ComputerGPUModels = {"NVIDIA GeForce RTX 3090",
"Trident Blade3D",
"ATI Radeon 9800 Pro"};

// todo - add more component names

}
}
17 changes: 17 additions & 0 deletions src/modules/computer/ComputerData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <array>
#include <string_view>

namespace faker
{
extern const std::array<std::string_view, 4> computerTypes;
extern const std::array<std::string_view, 20> computerManufacturers;
extern const std::array<std::string_view, 45> computerModels;
extern const std::array<std::string_view, 5> cpuManufacturers;
extern const std::array<std::string_view, 12> cpuTypes;
extern const std::array<std::string_view, 26> cpuModels;
extern const std::array<std::string_view, 5> gpuManufacturers;
extern const std::array<std::string_view, 2> gpuTypes;
extern const std::array<std::string_view, 23> gpuModels;
}
70 changes: 38 additions & 32 deletions tests/modules/computer/ComputerTest.cpp
Original file line number Diff line number Diff line change
@@ -1,87 +1,93 @@
#include "faker-cxx/Computer.h"

#include <algorithm>
#include <string>
#include <vector>

#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; }));
}

0 comments on commit 6d23538

Please sign in to comment.