-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
052d127
commit 1671e03
Showing
6 changed files
with
316 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <optional> | ||
#include <string> | ||
|
||
namespace faker | ||
{ | ||
|
||
class ChemicalElement | ||
{ | ||
public: | ||
std::string name; | ||
std::string symbol; | ||
int atomic_number; | ||
|
||
ChemicalElement() = default; | ||
|
||
ChemicalElement(std::string name_, std::string symbol_, int atomic_number_) | ||
: name(name_), symbol(symbol_), atomic_number(atomic_number_) | ||
{ | ||
} | ||
|
||
ChemicalElement(std::string info) : name(""), symbol(""), atomic_number(-1) | ||
{ | ||
|
||
auto idx1 = info.find_first_of('-'); | ||
auto idx2 = info.find_last_of('-'); | ||
|
||
std::string name_ = info.substr(0, idx1 - 1); | ||
std::string symbol_ = info.substr(idx1 + 2, idx2 - idx1 - 3); | ||
std::string atomic_number = info.substr(idx2 + 2, info.length() - idx2 - 2); | ||
} | ||
|
||
~ChemicalElement() = default; | ||
|
||
bool operator==(const ChemicalElement& obj) const | ||
{ | ||
return (this->name == obj.name && this->symbol == obj.symbol && this->atomic_number == obj.atomic_number); | ||
} | ||
}; | ||
|
||
class Unit | ||
{ | ||
public: | ||
std::string name; | ||
std::string symbol; | ||
std::string usedToMeasure; | ||
|
||
Unit(std::string name_, std::string symbol_, std::string usedToMeasure_) : name(name_), symbol(symbol_) {} | ||
|
||
bool operator==(const Unit& obj) const | ||
{ | ||
return (this->name == obj.name && this->symbol == obj.symbol && this->usedToMeasure == obj.usedToMeasure); | ||
} | ||
}; | ||
|
||
class Science | ||
{ | ||
public: | ||
static ChemicalElement chemicalElement(); | ||
static Unit unit(); | ||
static Unit distanceUnit(); | ||
static Unit timeUnit(); | ||
static Unit massUnit(); | ||
static Unit tempUnit(); | ||
static Unit currentUnit(); | ||
|
||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "faker-cxx/Science.h" | ||
|
||
#include "data/elements.h" | ||
#include "data/units.h" | ||
#include "faker-cxx/Helper.h" | ||
|
||
#include <vector> | ||
|
||
namespace faker | ||
{ | ||
|
||
ChemicalElement Science::chemicalElement() | ||
{ | ||
return Helper::arrayElement<ChemicalElement>(elements); | ||
} | ||
|
||
Unit Science::unit() | ||
{ | ||
std::vector<faker::Unit> units = distanceUnits; | ||
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<Unit>(units); | ||
} | ||
|
||
Unit Science::distanceUnit() | ||
{ | ||
return Helper::arrayElement<Unit>(distanceUnits); | ||
} | ||
|
||
Unit Science::timeUnit() | ||
{ | ||
return Helper::arrayElement<Unit>(timeUnits); | ||
} | ||
|
||
Unit Science::massUnit() | ||
{ | ||
return Helper::arrayElement<Unit>(massUnits); | ||
} | ||
|
||
Unit Science::tempUnit() | ||
{ | ||
return Helper::arrayElement<Unit>(temperatureUnits); | ||
} | ||
|
||
Unit Science::currentUnit() | ||
{ | ||
return Helper::arrayElement<Unit>(currentUnits); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#pragma once | ||
|
||
#include "faker-cxx/Science.h" | ||
|
||
#include <algorithm> | ||
|
||
#include "gtest/gtest.h" | ||
|
||
#include "data/elements.h" | ||
#include "data/units.h" | ||
|
||
using namespace ::testing; | ||
using namespace faker; | ||
|
||
class ScienceTest : public Test | ||
{ | ||
public: | ||
}; | ||
|
||
TEST_F(ScienceTest, shouldGenerateChemElement) | ||
{ | ||
const auto generatedChemElement = Science::chemicalElement(); | ||
ASSERT_TRUE(std::ranges::any_of(elements, [generatedChemElement](const ChemicalElement& chemElement) | ||
{ return generatedChemElement == chemElement; })); | ||
} | ||
|
||
TEST_F(ScienceTest, shouldGenerateAnyUnit) | ||
{ | ||
const auto generatedAnyUnit = Science::unit(); | ||
std::vector<faker::Unit> units = distanceUnits; | ||
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 Unit& unit) { return generatedAnyUnit == unit; })); | ||
} | ||
|
||
TEST_F(ScienceTest, shouldGenerateDistanceUnit) | ||
{ | ||
const auto generatedDistanceUnit = Science::distanceUnit(); | ||
ASSERT_TRUE(std::ranges::any_of(distanceUnits, [generatedDistanceUnit](const Unit& distanceUnit) | ||
{ return generatedDistanceUnit == distanceUnit; })); | ||
} | ||
|
||
TEST_F(ScienceTest, shouldGenerateMassUnit) | ||
{ | ||
const auto generatedMassUnit = Science::massUnit(); | ||
ASSERT_TRUE(std::ranges::any_of(massUnits, [generatedMassUnit](const Unit& massUnit) | ||
{ return generatedMassUnit == massUnit; })); | ||
} | ||
|
||
TEST_F(ScienceTest, shouldGenerateTimeUnit) | ||
{ | ||
const auto generatedTimeUnit = Science::timeUnit(); | ||
ASSERT_TRUE(std::ranges::any_of(timeUnits, [generatedTimeUnit](const Unit& timeUnit) | ||
{ return generatedTimeUnit == timeUnit; })); | ||
} | ||
|
||
TEST_F(ScienceTest, shouldGenerateTempUnit) | ||
{ | ||
const auto generatedTempUnit = Science::tempUnit(); | ||
ASSERT_TRUE(std::ranges::any_of(temperatureUnits, [generatedTempUnit](const Unit& tempUnit) | ||
{ return generatedTempUnit == tempUnit; })); | ||
} | ||
|
||
TEST_F(ScienceTest, shouldGenerateCurrentUnit) | ||
{ | ||
const auto generatedCurrentUnit = Science::currentUnit(); | ||
ASSERT_TRUE(std::ranges::any_of(currentUnits, [generatedCurrentUnit](const Unit& currentUnit) | ||
{ return generatedCurrentUnit == currentUnit; })); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "faker-cxx/Science.h" | ||
|
||
namespace faker | ||
{ | ||
|
||
const std::vector<ChemicalElement> elements = { | ||
ChemicalElement("Hydrogen - H - 1"), ChemicalElement("Helium - He - 2"), | ||
ChemicalElement("Lithium - Li - 3"), ChemicalElement("Beryllium - Be - 4"), | ||
ChemicalElement("Boron - B - 5"), ChemicalElement("Carbon - C - 6"), | ||
ChemicalElement("Nitrogen - N - 7"), ChemicalElement("Oxygen - O - 8"), | ||
ChemicalElement("Fluorine - F - 9"), ChemicalElement("Neon - Ne - 10"), | ||
ChemicalElement("Sodium - Na - 11"), ChemicalElement("Magnesium - Mg - 12"), | ||
ChemicalElement("Aluminum - Al - 13"), ChemicalElement("Silicon - Si - 14"), | ||
ChemicalElement("Phosphorus - P - 15"), ChemicalElement("Sulfur - S - 16"), | ||
ChemicalElement("Chlorine - Cl - 17"), ChemicalElement("Argon - Ar - 18"), | ||
ChemicalElement("Potassium - K - 19"), ChemicalElement("Calcium - Ca - 20"), | ||
ChemicalElement("Scandium - Sc - 21"), ChemicalElement("Titanium - Ti - 22"), | ||
ChemicalElement("Vanadium - V - 23"), ChemicalElement("Chromium - Cr - 24"), | ||
ChemicalElement("Manganese - Mn - 25"), ChemicalElement("Iron - Fe - 26"), | ||
ChemicalElement("Cobalt - Co - 27"), ChemicalElement("Nickel - Ni - 28"), | ||
ChemicalElement("Copper - Cu - 29"), ChemicalElement("Zinc - Zn - 30"), | ||
ChemicalElement("Gallium - Ga - 31"), ChemicalElement("Germanium - Ge - 32"), | ||
ChemicalElement("Arsenic - As - 33"), ChemicalElement("Selenium - Se - 34"), | ||
ChemicalElement("Bromine - Br - 35"), ChemicalElement("Krypton - Kr - 36"), | ||
ChemicalElement("Rubidium - Rb - 37"), ChemicalElement("Strontium - Sr - 38"), | ||
ChemicalElement("Yttrium - Y - 39"), ChemicalElement("Zirconium - Zr - 40"), | ||
ChemicalElement("Niobium - Nb - 41"), ChemicalElement("Molybdenum - Mo - 42"), | ||
ChemicalElement("Technetium - Tc - 43"), ChemicalElement("Ruthenium - Ru - 44"), | ||
ChemicalElement("Rhodium - Rh - 45"), ChemicalElement("Palladium - Pd - 46"), | ||
ChemicalElement("Silver - Ag - 47"), ChemicalElement("Cadmium - Cd - 48"), | ||
ChemicalElement("Indium - In - 49"), ChemicalElement("Tin - Sn - 50"), | ||
ChemicalElement("Antimony - Sb - 51"), ChemicalElement("Tellurium - Te - 52"), | ||
ChemicalElement("Iodine - I - 53"), ChemicalElement("Xenon - Xe - 54"), | ||
ChemicalElement("Cesium - Cs - 55"), ChemicalElement("Barium - Ba - 56"), | ||
ChemicalElement("Lanthanum - La - 57"), ChemicalElement("Cerium - Ce - 58"), | ||
ChemicalElement("Praseodymium - Pr - 59"), ChemicalElement("Neodymium - Nd - 60"), | ||
ChemicalElement("Promethium - Pm - 61"), ChemicalElement("Samarium - Sm - 62"), | ||
ChemicalElement("Europium - Eu - 63"), ChemicalElement("Gadolinium - Gd - 64"), | ||
ChemicalElement("Terbium - Tb - 65"), ChemicalElement("Dysprosium - Dy - 66"), | ||
ChemicalElement("Holmium - Ho - 67"), ChemicalElement("Erbium - Er - 68"), | ||
ChemicalElement("Thulium - Tm - 69"), ChemicalElement("Ytterbium - Yb - 70"), | ||
ChemicalElement("Lutetium - Lu - 71"), ChemicalElement("Hafnium - Hf - 72"), | ||
ChemicalElement("Tantalum - Ta - 73"), ChemicalElement("Tungsten - W - 74"), | ||
ChemicalElement("Rhenium - Re - 75"), ChemicalElement("Osmium - Os - 76"), | ||
ChemicalElement("Iridium - Ir - 77"), ChemicalElement("Platinum - Pt - 78"), | ||
ChemicalElement("Gold - Au - 79"), ChemicalElement("Mercury - Hg - 80"), | ||
ChemicalElement("Thallium - Tl - 81"), ChemicalElement("Lead - Pb - 82"), | ||
ChemicalElement("Bismuth - Bi - 83"), ChemicalElement("Polonium - Po - 84"), | ||
ChemicalElement("Astatine - At - 85"), ChemicalElement("Radon - Rn - 86"), | ||
ChemicalElement("Francium - Fr - 87"), ChemicalElement("Radium - Ra - 88"), | ||
ChemicalElement("Actinium - Ac - 89"), ChemicalElement("Thorium - Th - 90"), | ||
ChemicalElement("Protactinium - Pa - 91"), ChemicalElement("Uranium - U - 92"), | ||
ChemicalElement("Neptunium - Np - 93"), ChemicalElement("Plutonium - Pu - 94"), | ||
ChemicalElement("Americium - Am - 95"), ChemicalElement("Curium - Cm - 96"), | ||
ChemicalElement("Berkelium - Bk - 97"), ChemicalElement("Californium - Cf - 98"), | ||
ChemicalElement("Einsteinium - Es - 99"), ChemicalElement("Fermium - Fm - 100"), | ||
ChemicalElement("Mendelevium - Md - 101"), ChemicalElement("Nobelium - No - 102"), | ||
ChemicalElement("Lawrencium - Lr - 103"), ChemicalElement("Rutherfordium - Rf - 104"), | ||
ChemicalElement("Dubnium - Db - 105"), ChemicalElement("Seaborgium - Sg - 106"), | ||
ChemicalElement("Bohrium - Bh - 107"), ChemicalElement("Hassium - Hs - 108"), | ||
ChemicalElement("Meitnerium - Mt - 109"), ChemicalElement("Darmstadtium - Ds - 110"), | ||
ChemicalElement("Roentgenium - Rg - 111"), ChemicalElement("Copernicium - Cn - 112"), | ||
ChemicalElement("Nihonium - Nh - 113"), ChemicalElement("Flerovium - Fl - 114"), | ||
ChemicalElement("Moscovium - Mc - 115"), ChemicalElement("Livermorium - Lv - 116"), | ||
ChemicalElement("Tennessine - Ts - 117"), ChemicalElement("Oganesson - Og - 118")}; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
#include "faker-cxx/Science.h" | ||
|
||
namespace faker | ||
{ | ||
|
||
const std::vector<Unit> distanceUnits = { | ||
/*Units to measure Length*/ | ||
Unit("Millimeter", "mm", "Length"), Unit("Centimeter", "cm", "Length"), Unit("Meter", "m", "Length"), | ||
Unit("Kilometer", "km", "Length"), Unit("Inch", "in", "Length"), Unit("Foot", "ft", "Length"), | ||
Unit("Yard", "yd", "Length"), Unit("Mile", "mi", "Length"), | ||
}; | ||
|
||
const std::vector<Unit> massUnits = { | ||
/*Units to measure Mass*/ | ||
Unit("Gram", "g", "Mass"), Unit("Kilogram", "kg", "Mass"), Unit("Milligram", "mg", "Mass"), | ||
Unit("Microgram", "μg", "Mass"), Unit("Metric ton", "t", "Mass"), Unit("Ounce", "oz", "Mass"), | ||
Unit("Pound", "lb", "Mass"), Unit("Slug", "sl", "Mass"), | ||
}; | ||
|
||
const std::vector<Unit> timeUnits = { | ||
/*Units to measure Time*/ | ||
Unit("Second", "s", "Time"), Unit("Minute", "min", "Time"), Unit("Hour", "hr", "Time"), Unit("Day", "d", "Time"), | ||
Unit("Week", "wk", "Time"), Unit("Month", "mo", "Time"), Unit("Year", "yr", "Time"), | ||
}; | ||
|
||
const std::vector<Unit> currentUnits = { | ||
/*Units to measure Electric Current*/ | ||
Unit("Ampere", "A", "Electric Current"), | ||
Unit("Milliampere", "mA", "Electric Current"), | ||
Unit("Microampere", "μA", "Electric Current"), | ||
}; | ||
|
||
const std::vector<Unit> temperatureUnits = { | ||
/*Units to measure Temperature*/ | ||
Unit("Celcius", "°C", "Temperature"), | ||
Unit("Fahrenheit", "°F", "Temperature"), | ||
Unit("Kelvin", "K", "Temperature"), | ||
}; | ||
|
||
}; |