Skip to content

Commit

Permalink
Adding new module called Computer (#360)
Browse files Browse the repository at this point in the history
* add Persian people names

* add convertToUFT8 test

* add locale header to StringHelper.cpp

* add updated converter for convertToUTF8 function

* add updated converter for convertToUTF8 function

* suppress Wdeprecated-declarations warning

* Update the encoding of PersianNames headers and eliminate the wstring to string conversion

* remove test for wstring to string conversion

* Update the encoding of PersianNames headers and eliminate the wstring to string conversion

* add computer module

* fix ComputerData.h

* add comment to Computer.h
  • Loading branch information
alisedighmoghadam authored Dec 1, 2023
1 parent 09400ed commit 95e54dc
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 2 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ set(FAKER_SOURCES
src/common/WeatherHelper.cpp
src/modules/airline/Airline.cpp
src/modules/image/Image.cpp
src/modules/crypto/Crypto.cpp)
src/modules/crypto/Crypto.cpp
src/modules/computer/Computer.cpp)

set(FAKER_UT_SOURCES
src/modules/animal/AnimalTest.cpp
Expand Down Expand Up @@ -93,7 +94,8 @@ set(FAKER_UT_SOURCES
src/common/WeatherHelperTest.cpp
src/modules/airline/AirlineTest.cpp
src/modules/image/ImageTest.cpp
src/modules/crypto/CryptoTest.cpp)
src/modules/crypto/CryptoTest.cpp
src/modules/computer/ComputerTest.cpp)

add_library(${LIBRARY_NAME} ${FAKER_SOURCES})

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ int main()
- 🎨 Color - color names, rgb, hex, hcl
- 🛒 Commerce - commerce department, product name, sku, price
- 🏢 Company - company name, type, industry, catch phrase, buzz phrase
- 🖥️ Computer - type, manufacturer, model, CPU info, GPU info
- 💾 Database - column names, column types, database engines
- ℹ️ Datatype - booleans
- 📅 Date - past, future dates
Expand All @@ -84,6 +85,7 @@ int main()
- 💬 Word - sample words, nouns, verbs



## 📖 Documentation

https://cieslarmichal.github.io/faker-cxx/
Expand Down
95 changes: 95 additions & 0 deletions include/faker-cxx/Computer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#pragma once

#include <string>


namespace faker
{
class Computer
{
public:
/*
* @brief Returns a random computer type.
*
* @returns computer type
*
* @code
* Computer::type() // Laptop
*/
static std::string type();
/*
* @brief Returns a random computer manufacture name.
*
* @returns manufacture name
*
* @code
* Computer::manufacture() // HP
*/
static std::string manufacture();
/*
* @brief Returns a random computer model.
*
* @returns computer model
*
* @code
* Computer::model() // MacBook Air
*/
static std::string model();
/*
* @brief Returns a random CPU manufacture name.
*
* @returns CPU manufacture name
*
* @code
* Computer::cpuManufacture() // Intel
*/
static std::string cpuManufacture();
/*
* @brief Returns a random CPU type.
*
* @returns CPU type
*
* @code
* Computer::cpuType() // x86
*/
static std::string cpuType();
/*
* @brief Returns a random CPU model.
*
* @returns computer CPU model
*
* @code
* Computer::cpuModel() // Core i9-11900k
*/
static std::string cpuModel();
/*
* @brief Returns a random GPU manufacture name.
*
* @returns GPU manufacture name
*
* @code
* Computer::gpuManufacture() // NVIDIA
*/
static std::string gpuManufacture();
/*
* @brief Returns a random GPU type.
*
* @returns GPU type
*
* @code
* Computer::gpuType() // Integrated
*/
static std::string gpuType();
/*
* @brief Returns a random GPU model.
*
* @returns computer GPU model
*
* @code
* Computer::gpuModel() // NVIDIA GeForce RTX 3080
*/
static std::string gpuModel();

};

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

#include <string>

#include "data/ComputerData.h"
#include "faker-cxx/Helper.h"

std::string faker::Computer::type()
{
return Helper::arrayElement(faker::data::ComputerTypes);
}

std::string faker::Computer::manufacture()
{
return Helper::arrayElement(faker::data::ComputerManufactures);
}

std::string faker::Computer::model()
{
return Helper::arrayElement(faker::data::ComputerModels);
}

std::string faker::Computer::cpuManufacture()
{
return Helper::arrayElement(faker::data::ComputerCPUManufactures);
}

std::string faker::Computer::cpuType()
{
return Helper::arrayElement(faker::data::ComputerCPUTypes);
}

std::string faker::Computer::cpuModel()
{
return Helper::arrayElement(faker::data::ComputerCPUModels);
}

std::string faker::Computer::gpuManufacture()
{
return Helper::arrayElement(faker::data::ComputerGPUManufactures);
}

std::string faker::Computer::gpuType()
{
return Helper::arrayElement(faker::data::ComputerGPUTypes);
}

std::string faker::Computer::gpuModel()
{
return Helper::arrayElement(faker::data::ComputerGPUModels);
}
85 changes: 85 additions & 0 deletions src/modules/computer/ComputerTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "faker-cxx/Computer.h"

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

#include "gtest/gtest.h"

#include "data/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; }));
}

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

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) { 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)
{ 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)
{ 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)
{ 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)
{ 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)
{ return gpuModel == generatedGPUModel; }));
}
72 changes: 72 additions & 0 deletions src/modules/computer/data/ComputerData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#pragma once
#include <string>
#include <vector>

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

const std::vector<std::string> ComputerManufactures = {
"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 = {
"MacBook Air", "MacBook Pro", "iMac", "Mac mini", "Inspiron", "XPS", "Alienware",
"Latitude", "Precision", "Spectre", "Envy", "Pavilion", "EliteBook", "ThinkPad",
"Yoga", "Legion", "IdeaPad", "Aspire", "Predator", "TravelMate", "Swift",
"ZenBook", "ROG", "VivoBook", "TUF", "Surface Laptop", "Surface Pro", "Surface Book",
"Galaxy Book", "Notebook", "Odyssey", "Satellite", "VAIO", "GS Series", "GE Series",
"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::vector<std::string> ComputerCPUTypes = {
"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 = {"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::vector<std::string> ComputerGPUTypes = {"Integrated", "Discrete"};

const std::vector<std::string> ComputerGPUModels = {"NVIDIA GeForce RTX 3090",
"NVIDIA GeForce RTX 3080",
"NVIDIA GeForce RTX 3070",
"NVIDIA GeForce GTX 1660 Ti",
"NVIDIA GeForce GTX 1660 Super",
"NVIDIA GeForce GTX 1660",
"NVIDIA GeForce GTX 1650 Super",
"NVIDIA GeForce GTX 1650",
"AMD Radeon RX 6900 XT",
"AMD Radeon RX 6800 XT",
"AMD Radeon RX 6700 XT",
"Intel Xe Graphics",
"ARM Mali-G78 MP14",
"Qualcomm Adreno 660",
"Imagination PowerVR GT7600",
"VIA S3 Graphics Chrome 520",
"Matrox Millennium G200",
"SiS 315",
"3dfx Voodoo3",
"S3 Graphics Savage4",
"XGI Volari V8",
"Trident Blade3D",
"ATI Radeon 9800 Pro"};

// todo - add more component names

}
}

0 comments on commit 95e54dc

Please sign in to comment.