Compare commits
No commits in common. "a4624b477fb4e164391131088bbcbec116a85efd" and "992103fd7b26f250a1d7302509b0f9518b22867a" have entirely different histories.
a4624b477f
...
992103fd7b
|
@ -6,4 +6,3 @@ set(CMAKE_CXX_STANDARD 11)
|
||||||
add_subdirectory(third-party/googletest-1.17.0)
|
add_subdirectory(third-party/googletest-1.17.0)
|
||||||
|
|
||||||
add_subdirectory(mixplus)
|
add_subdirectory(mixplus)
|
||||||
add_subdirectory(counter)
|
|
|
@ -1,11 +0,0 @@
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
||||||
|
|
||||||
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src SRC)
|
|
||||||
|
|
||||||
add_library(libcount STATIC ${SRC})
|
|
||||||
|
|
||||||
add_executable(counter main.cpp)
|
|
||||||
|
|
||||||
target_link_libraries(counter libcount)
|
|
||||||
|
|
||||||
add_subdirectory(tests)
|
|
|
@ -1,15 +0,0 @@
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
namespace counter
|
|
||||||
{
|
|
||||||
struct Counter
|
|
||||||
{
|
|
||||||
static std::unordered_map<std::string, long> count(const std::string& input);
|
|
||||||
|
|
||||||
static void countPair(std::unordered_map<std::string, long>& map, const std::string& input);
|
|
||||||
|
|
||||||
|
|
||||||
static void countTriple(std::unordered_map<std::string, long>& map, const std::string& input);
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
#include <counter.h>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main(const int argc, char** argv)
|
|
||||||
{
|
|
||||||
if (argc != 2)
|
|
||||||
{
|
|
||||||
std::cout << "ERROR: Need a string." << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string input(argv[1]);
|
|
||||||
|
|
||||||
const auto map = counter::Counter::count(input);
|
|
||||||
|
|
||||||
for (const auto& pair : map)
|
|
||||||
{
|
|
||||||
std::cout << pair.first << ' ' << pair.second << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
#include "counter.h"
|
|
||||||
|
|
||||||
|
|
||||||
void counter::Counter::countPair(std::unordered_map<std::string, long>& map, const std::string& input)
|
|
||||||
{
|
|
||||||
for (int i = 1; i < input.size(); i++)
|
|
||||||
{
|
|
||||||
const auto pair = input.substr(i - 1, 2);
|
|
||||||
|
|
||||||
map[pair] += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void counter::Counter::countTriple(std::unordered_map<std::string, long>& map, const std::string& input)
|
|
||||||
{
|
|
||||||
for (int i = 2; i < input.size(); i++)
|
|
||||||
{
|
|
||||||
const auto pair = input.substr(i - 2, 3);
|
|
||||||
|
|
||||||
map[pair] += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unordered_map<std::string, long> counter::Counter::count(const std::string& input)
|
|
||||||
{
|
|
||||||
std::unordered_map<std::string, long> map;
|
|
||||||
|
|
||||||
countPair(map, input);
|
|
||||||
countTriple(map, input);
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
enable_testing()
|
|
||||||
|
|
||||||
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} TEST_SRC)
|
|
||||||
|
|
||||||
add_executable(
|
|
||||||
counter_tests
|
|
||||||
${TEST_SRC}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(counter_tests GTest::gtest_main libcount)
|
|
|
@ -61,7 +61,7 @@ void loop() { RUN_ALL_TESTS(); }
|
||||||
|
|
||||||
GTEST_API_ int _tmain(int argc, TCHAR** argv) {
|
GTEST_API_ int _tmain(int argc, TCHAR** argv) {
|
||||||
#else
|
#else
|
||||||
GTEST_API_ int main(int argc, char** argv) {
|
GTEST_API_ int main(const int argc, const char** argv) {
|
||||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||||
std::cout << "Running main() from gmock_main.cc\n";
|
std::cout << "Running main() from gmock_main.cc\n";
|
||||||
// Since Google Mock depends on Google Test, InitGoogleMock() is
|
// Since Google Mock depends on Google Test, InitGoogleMock() is
|
||||||
|
|
Loading…
Reference in New Issue
Block a user