-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refined Hacker::Phrases and created better Tests + formatting
- Loading branch information
1 parent
2e9078c
commit f3f2902
Showing
10 changed files
with
220 additions
and
157 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 |
---|---|---|
@@ -1,71 +1,109 @@ | ||
#include "gtest/gtest.h" | ||
#include "faker-cxx/Hacker.h" | ||
|
||
#include <algorithm> | ||
#include <string> | ||
#include <iostream> | ||
|
||
#include "gtest/gtest.h" | ||
|
||
#include "data/Abbreviations.h" | ||
#include "data/Adjectives.h" | ||
#include "data/Ingverbs.h" | ||
#include "data/Nouns.h" | ||
#include "data/Verbs.h" | ||
#include "data/Phrases.h" | ||
|
||
// testing Hacker module, test like Person module tests | ||
// testing phrases will be different, test that each phrase will have a random word from each word list | ||
#include "data/Verbs.h" | ||
#include "faker-cxx/Helper.h" | ||
|
||
using namespace ::testing; | ||
using namespace faker; | ||
|
||
class HackerTest : public Test { | ||
class HackerTest : public Test | ||
{ | ||
public: | ||
}; | ||
|
||
TEST_F(HackerTest, shouldGenerateAbbreviation) { | ||
TEST_F(HackerTest, shouldGenerateAbbreviation) | ||
{ | ||
std::string generatedAbbreviation = Hacker::abbreviation(); | ||
|
||
ASSERT_TRUE(std::ranges::any_of(abbreviations, [generatedAbbreviation](const std::string& abbreviation) { return abbreviation == generatedAbbreviation; })); | ||
ASSERT_TRUE(std::ranges::any_of(abbreviations, [generatedAbbreviation](const std::string& abbreviation) | ||
{ return abbreviation == generatedAbbreviation; })); | ||
} | ||
|
||
TEST_F(HackerTest, shouldGenerateAdjective) { | ||
TEST_F(HackerTest, shouldGenerateAdjective) | ||
{ | ||
std::string generatedAdjective = Hacker::adjective(); | ||
|
||
ASSERT_TRUE(std::ranges::any_of(adjectives, [generatedAdjective](const std::string& adjective) { return adjective == generatedAdjective; })); | ||
ASSERT_TRUE(std::ranges::any_of(adjectives, [generatedAdjective](const std::string& adjective) | ||
{ return adjective == generatedAdjective; })); | ||
} | ||
|
||
TEST_F(HackerTest, shouldGenerateNoun) { | ||
TEST_F(HackerTest, shouldGenerateNoun) | ||
{ | ||
std::string generatedNoun = Hacker::noun(); | ||
|
||
ASSERT_TRUE(std::ranges::any_of(nouns, [generatedNoun](const std::string& noun) { return noun == generatedNoun; })); | ||
} | ||
|
||
TEST_F(HackerTest, shouldGenerateVerb) { | ||
TEST_F(HackerTest, shouldGenerateVerb) | ||
{ | ||
std::string generatedVerb = Hacker::verb(); | ||
|
||
ASSERT_TRUE(std::ranges::any_of(verbs, [generatedVerb](const std::string& verb) { return verb == generatedVerb; })); | ||
} | ||
|
||
TEST_F(HackerTest, shouldGenerateIngverb) { | ||
TEST_F(HackerTest, shouldGenerateIngverb) | ||
{ | ||
std::string generatedIngverb = Hacker::ingverb(); | ||
|
||
ASSERT_TRUE(std::ranges::any_of(ingverbs, [generatedIngverb](const std::string& ingverb) { return ingverb == generatedIngverb; })); | ||
ASSERT_TRUE(std::ranges::any_of(ingverbs, [generatedIngverb](const std::string& ingverb) | ||
{ return ingverb == generatedIngverb; })); | ||
} | ||
|
||
TEST_F(HackerTest, shouldGeneratePhrase) { | ||
TEST_F(HackerTest, shouldGeneratePhrase) | ||
{ | ||
std::string generatedPhrase = Hacker::phrase(); | ||
size_t limit = 1000000; | ||
size_t attempt = 0; | ||
|
||
while (attempt <= limit) { | ||
std::string newGeneratedPhrase = Hacker::phrase(); | ||
if (newGeneratedPhrase == generatedPhrase) { | ||
std::cout << generatedPhrase << "\n"; | ||
std::cout << newGeneratedPhrase << "\n"; | ||
ASSERT_TRUE(true); | ||
bool hasAdjective, hasNoun, hasVerb, hasAbbreviation; | ||
hasAdjective = hasNoun = hasVerb = hasAbbreviation = false; | ||
|
||
// Check for adjectives | ||
for (const std::string& adj : adjectives) | ||
{ | ||
if (generatedPhrase.find(adj) != std::string::npos) | ||
{ | ||
hasAdjective = true; | ||
break; | ||
} | ||
} | ||
|
||
attempt++; | ||
// Check for nouns | ||
for (const std::string& noun : nouns) | ||
{ | ||
if (generatedPhrase.find(noun) != std::string::npos) | ||
{ | ||
hasNoun = true; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// Check for verbs | ||
for (const std::string& verb : verbs) | ||
{ | ||
if (generatedPhrase.find(verb) != std::string::npos) | ||
{ | ||
hasVerb = true; | ||
break; | ||
} | ||
} | ||
|
||
// Check for abbreviations | ||
for (const std::string& abbreviation : abbreviations) | ||
{ | ||
if (generatedPhrase.find(abbreviation) != std::string::npos) | ||
{ | ||
hasAbbreviation = true; | ||
break; | ||
} | ||
} | ||
|
||
ASSERT_TRUE((hasAdjective && hasNoun && hasVerb && hasAbbreviation)); | ||
} |
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
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
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 |
---|---|---|
@@ -1,32 +1,28 @@ | ||
#pragma once | ||
|
||
#include "faker-cxx/Helper.h" | ||
#include "fmt/format.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "Abbreviations.h" | ||
#include "Adjectives.h" | ||
#include "faker-cxx/Helper.h" | ||
#include "fmt/format.h" | ||
#include "Ingverbs.h" | ||
#include "Nouns.h" | ||
#include "Verbs.h" | ||
#include "Adjectives.h" | ||
|
||
|
||
namespace faker { | ||
// use fmt::format() to format each phrase w/ random word | ||
|
||
const std::vector<std::string> phrases = { | ||
fmt::format("If we {} the {}, we can get to the {} {} through the {} {} {}!", Helper::arrayElement<std::string>(verbs), Helper::arrayElement<std::string>(nouns), Helper::arrayElement<std::string>(abbreviations), Helper::arrayElement<std::string>(nouns), Helper::arrayElement<std::string>(adjectives), Helper::arrayElement<std::string>(abbreviations), Helper::arrayElement<std::string>(nouns)), | ||
fmt::format("We need to {} the {} {} {}!", Helper::arrayElement<std::string>(verbs), Helper::arrayElement<std::string>(adjectives), Helper::arrayElement<std::string>(abbreviations), Helper::arrayElement<std::string>(nouns)), | ||
fmt::format("Try to {} the {} {}, maybe it will {} the {} {}!", Helper::arrayElement<std::string>(verbs), Helper::arrayElement<std::string>(abbreviations), Helper::arrayElement<std::string>(nouns), Helper::arrayElement<std::string>(verbs), Helper::arrayElement<std::string>(adjectives), Helper::arrayElement<std::string>(nouns)), | ||
fmt::format("You can't {} the {} without {} the {} {} {}!", Helper::arrayElement<std::string>(verbs), Helper::arrayElement<std::string>(nouns), Helper::arrayElement<std::string>(ingverbs), Helper::arrayElement<std::string>(adjectives), Helper::arrayElement<std::string>(abbreviations), Helper::arrayElement<std::string>(nouns)), | ||
fmt::format("Use the {} {} {}, then you can {} the {} {}!", Helper::arrayElement<std::string>(adjectives), Helper::arrayElement<std::string>(abbreviations), Helper::arrayElement<std::string>(nouns), Helper::arrayElement<std::string>(verbs), Helper::arrayElement<std::string>(adjectives), Helper::arrayElement<std::string>(nouns)), | ||
fmt::format("The {} {} is down, {} the {} {} so we can {} the {} {}!", Helper::arrayElement<std::string>(abbreviations), Helper::arrayElement<std::string>(nouns), Helper::arrayElement<std::string>(verbs), Helper::arrayElement<std::string>(adjectives), Helper::arrayElement<std::string>(nouns), Helper::arrayElement<std::string>(verbs), Helper::arrayElement<std::string>(abbreviations), Helper::arrayElement<std::string>(nouns)), | ||
fmt::format("{} the {} won't do anything, we need to {} the {} {} {}!", Helper::arrayElement<std::string>(ingverbs), Helper::arrayElement<std::string>(nouns), Helper::arrayElement<std::string>(verbs), Helper::arrayElement<std::string>(adjectives), Helper::arrayElement<std::string>(abbreviations), Helper::arrayElement<std::string>(nouns)), | ||
fmt::format("I'll {} the {} {} {}, that should {} the {} {}!", Helper::arrayElement<std::string>(verbs), Helper::arrayElement<std::string>(adjectives), Helper::arrayElement<std::string>(abbreviations), Helper::arrayElement<std::string>(nouns), Helper::arrayElement<std::string>(nouns), Helper::arrayElement<std::string>(abbreviations), Helper::arrayElement<std::string>(nouns)), | ||
}; | ||
|
||
|
||
//const std::vector<std::string> phrases = {fmt::format("{0}", Helper::arrayElement<std::string>(faker::abbreviations))}; | ||
} | ||
namespace faker | ||
{ | ||
// use fmt::format() to format each phrase w/ random word | ||
|
||
const std::vector<std::string> phrases = { | ||
"If we {verb} the {noun}, we can get to the {abbreviation} {noun} through the {adjective} {abbreviation} {noun}!", | ||
"We need to {verb} the {adjective} {abbreviation} {noun}!", | ||
"Try to {verb} the {abbreviation} {noun}, maybe it will {verb} the {adjective} {noun}!", | ||
"You can't {verb} the {noun} without {ingverb} the {adjective} {abbreviation} {noun}!", | ||
"Use the {adjective} {abbreviation} {noun}, then you can {verb} the {adjective} {noun}!", | ||
"The {abbreviation} {noun} is down, {verb} the {adjective} {noun} so we can {verb} the {abbreviation} {noun}!", | ||
"{ingverb} the {noun} won't do anything, we need to {verb} the {adjective} {abbreviation} {noun}!", | ||
"I'll {verb} the {adjective} {abbreviation} {noun}, that should {noun} the {abbreviation} {noun}!", | ||
}; | ||
} |
Oops, something went wrong.