Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homework/transform-containers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ FetchContent_MakeAvailable(googletest)
project(transformContainers)
enable_testing()

add_executable(${PROJECT_NAME}-ut test.cpp) # add your cpp file here after test.cpp
add_executable(${PROJECT_NAME}-ut unique_map.cpp test.cpp) # add your cpp file here after test.cpp
# if this is problematic take a look into CMakeLists.txt files in other exercises

add_compile_options(${PROJECT_NAME}-ut -Wall -Wextra -Wconversion -pedantic -Werror)
Expand Down
9 changes: 9 additions & 0 deletions homework/transform-containers/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
RMDIR build /S /Q
mkdir build
cd build
cmake -G "MinGW Makefiles" ..
MinGW32-make

transformContainers-ut.exe

cd ..
3 changes: 1 addition & 2 deletions homework/transform-containers/test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "gtest/gtest.h"

// TODO: add proper includes
#include "unique_map.hpp"

TEST(transformContainerTests, ShouldReturnUniqueMap) {
std::map<int, std::string> expected_result{
Expand Down
22 changes: 22 additions & 0 deletions homework/transform-containers/unique_map.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "unique_map.hpp"
#include <algorithm>
#include <iostream>

std::map<int, std::string> removeDuplicateAndTranformToMap(std::list<std::string> in_list, std::deque<int> in_deque) {
std::map<int, std::string> result;

in_list.sort();
std::sort(in_deque.begin(), in_deque.end());

in_list.erase(std::unique(in_list.begin(), in_list.end()), in_list.end());
in_deque.erase(std::unique(in_deque.begin(), in_deque.end()), in_deque.end());

std::transform(in_list.begin(), in_list.end(),
in_deque.begin(),
std::inserter(result, result.end()),
[](auto& str, auto& num) {
return std::make_pair(num, str);
});

return result;
}
8 changes: 8 additions & 0 deletions homework/transform-containers/unique_map.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <deque>
#include <list>
#include <map>
#include <string>

std::map<int, std::string> removeDuplicateAndTranformToMap(std::list<std::string>, std::deque<int>);