From 93237e0f4710f0a243f56f14dc3da0e433a3fc53 Mon Sep 17 00:00:00 2001 From: STELLSAN Date: Sun, 1 Dec 2024 16:56:50 +0300 Subject: [PATCH 01/11] add_lab_3 --- .../CMakeLists.txt | 20 ++++ .../CTestTests.txt | 97 ++++++++++++++++ .../application/Application.cpp | 14 +++ .../application/CMakeLists.txt | 15 +++ .../include/number_to_words.h | 16 +++ .../include/number_to_wordsApp.h | 17 +++ .../src/CMakeLists.txt | 18 +++ .../src/number_to_words.cpp | 97 ++++++++++++++++ .../src/number_to_wordsApp.cpp | 44 ++++++++ .../test/CMakeLists.txt | 27 +++++ .../test/test_main.cpp | 9 ++ .../test/test_number_to_words.cpp | 105 ++++++++++++++++++ 12 files changed, 479 insertions(+) create mode 100644 modules/nedelin_d_number_to_words_lab3/CMakeLists.txt create mode 100644 modules/nedelin_d_number_to_words_lab3/CTestTests.txt create mode 100644 modules/nedelin_d_number_to_words_lab3/application/Application.cpp create mode 100644 modules/nedelin_d_number_to_words_lab3/application/CMakeLists.txt create mode 100644 modules/nedelin_d_number_to_words_lab3/include/number_to_words.h create mode 100644 modules/nedelin_d_number_to_words_lab3/include/number_to_wordsApp.h create mode 100644 modules/nedelin_d_number_to_words_lab3/src/CMakeLists.txt create mode 100644 modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp create mode 100644 modules/nedelin_d_number_to_words_lab3/src/number_to_wordsApp.cpp create mode 100644 modules/nedelin_d_number_to_words_lab3/test/CMakeLists.txt create mode 100644 modules/nedelin_d_number_to_words_lab3/test/test_main.cpp create mode 100644 modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp diff --git a/modules/nedelin_d_number_to_words_lab3/CMakeLists.txt b/modules/nedelin_d_number_to_words_lab3/CMakeLists.txt new file mode 100644 index 000000000..5c277256f --- /dev/null +++ b/modules/nedelin_d_number_to_words_lab3/CMakeLists.txt @@ -0,0 +1,20 @@ +# Declare variables for binaries' names +get_filename_component(DIR_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) +set(MODULE "${DIR_NAME}") +set(LIBRARY "lib_${MODULE}") +set(TESTS "test_${MODULE}") +set(APPLICATION "app_${MODULE}") + +# Include directory with public headers +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +# Add all submodules +add_subdirectory(src) +add_subdirectory(test) +add_subdirectory(application) + +############################################# +##### Testing +############################################# + +include("CTestTests.txt") diff --git a/modules/nedelin_d_number_to_words_lab3/CTestTests.txt b/modules/nedelin_d_number_to_words_lab3/CTestTests.txt new file mode 100644 index 000000000..1b65d7b94 --- /dev/null +++ b/modules/nedelin_d_number_to_words_lab3/CTestTests.txt @@ -0,0 +1,97 @@ +############################################# +##### Testing +############################################# + +set(prefix "${MODULE}") + +add_test( + NAME ${prefix}_convert_zero + COMMAND ${APPLICATION} "0" +) +set_tests_properties(${prefix}_convert_zero PROPERTIES + PASS_REGULAR_EXPRESSION "zero" + LABELS "${MODULE}" +) + +add_test( + NAME ${prefix}_convert_one + COMMAND ${APPLICATION} "1" +) +set_tests_properties(${prefix}_convert_one PROPERTIES + PASS_REGULAR_EXPRESSION "one" + LABELS "${MODULE}" +) + +add_test( + NAME ${prefix}_convert_negative + COMMAND ${APPLICATION} "-123" +) +set_tests_properties(${prefix}_convert_negative PROPERTIES + PASS_REGULAR_EXPRESSION "negative one hundred twenty three" + LABELS "${MODULE}" +) + +add_test( + NAME ${prefix}_convert_large_number + COMMAND ${APPLICATION} "1000000" +) +set_tests_properties(${prefix}_convert_large_number PROPERTIES + PASS_REGULAR_EXPRESSION "one million" + LABELS "${MODULE}" +) + +add_test( + NAME ${prefix}_convert_edge_case_twenty + COMMAND ${APPLICATION} "20" +) +set_tests_properties(${prefix}_convert_edge_case_twenty PROPERTIES + PASS_REGULAR_EXPRESSION "twenty" + LABELS "${MODULE}" +) + +# Тесты для ошибок и невалидных вводов +add_test( + NAME ${prefix}_invalid_input + COMMAND ${APPLICATION} "abc" +) +set_tests_properties(${prefix}_invalid_input PROPERTIES + PASS_REGULAR_EXPRESSION "Invalid number format!" + LABELS "${MODULE}" +) + +add_test( + NAME ${prefix}_missing_argument + COMMAND ${APPLICATION} +) +set_tests_properties(${prefix}_missing_argument PROPERTIES + PASS_REGULAR_EXPRESSION "Usage: number_to_words " + LABELS "${MODULE}" +) + +add_test( + NAME ${prefix}_extra_argument + COMMAND ${APPLICATION} "123" "456" +) +set_tests_properties(${prefix}_extra_argument PROPERTIES + PASS_REGULAR_EXPRESSION "Usage: number_to_words " + LABELS "${MODULE}" +) + +# Граничные значения +add_test( + NAME ${prefix}_convert_min_int + COMMAND ${APPLICATION} "-2147483648" +) +set_tests_properties(${prefix}_convert_min_int PROPERTIES + PASS_REGULAR_EXPRESSION "negative two billion one hundred forty seven million four hundred eighty three thousand six hundred forty eight" + LABELS "${MODULE}" +) + +add_test( + NAME ${prefix}_convert_max_int + COMMAND ${APPLICATION} "2147483647" +) +set_tests_properties(${prefix}_convert_max_int PROPERTIES + PASS_REGULAR_EXPRESSION "two billion one hundred forty seven million four hundred eighty three thousand six hundred forty seven" + LABELS "${MODULE}" +) \ No newline at end of file diff --git a/modules/nedelin_d_number_to_words_lab3/application/Application.cpp b/modules/nedelin_d_number_to_words_lab3/application/Application.cpp new file mode 100644 index 000000000..3832db01a --- /dev/null +++ b/modules/nedelin_d_number_to_words_lab3/application/Application.cpp @@ -0,0 +1,14 @@ +// Copyright 2024 Nedelin Dmitry + +#include + +#include "include/number_to_wordsApp.h" + +int main(int argc, const char** argv) { + Application app; + auto output = app.runApp(argc, argv); + for (auto str : output) { + std::cout << str << std::endl; + } + return 0; +} diff --git a/modules/nedelin_d_number_to_words_lab3/application/CMakeLists.txt b/modules/nedelin_d_number_to_words_lab3/application/CMakeLists.txt new file mode 100644 index 000000000..e8a53c3d7 --- /dev/null +++ b/modules/nedelin_d_number_to_words_lab3/application/CMakeLists.txt @@ -0,0 +1,15 @@ +set(target ${APPLICATION}) + +file(GLOB srcs "*.cpp") +set_source_files_properties(${srcs} PROPERTIES + LABELS "${MODULE};Application") + +add_executable(${target} ${srcs}) +set_target_properties(${target} PROPERTIES + OUTPUT_NAME ${MODULE} + LABELS "${MODULE};Application") + +target_link_libraries(${target} ${LIBRARY}) +if (UNIX) + target_link_libraries(${target} ${CMAKE_THREAD_LIBS_INIT}) +endif (UNIX) diff --git a/modules/nedelin_d_number_to_words_lab3/include/number_to_words.h b/modules/nedelin_d_number_to_words_lab3/include/number_to_words.h new file mode 100644 index 000000000..a419cbdba --- /dev/null +++ b/modules/nedelin_d_number_to_words_lab3/include/number_to_words.h @@ -0,0 +1,16 @@ +// Copyright 2024 Nedelin Dmitry + +#ifndef MODULES_NEDELIN_DMITRY_NUMBER_TO_WORDS_INCLUDE_NUMBER_TO_WORDS_H_ +#define MODULES_NEDELIN_DMITRY_NUMBER_TO_WORDS_INCLUDE_NUMBER_TO_WORDS_H_ + +#include + +class NumberToWords { + public: + std::string convert(int number); + + private: + std::string convertLessThanOneThousand(int number); +}; + +#endif // MODULES_NEDELIN_DMITRY_NUMBER_TO_WORDS_INCLUDE_NUMBER_TO_WORDS_H_ diff --git a/modules/nedelin_d_number_to_words_lab3/include/number_to_wordsApp.h b/modules/nedelin_d_number_to_words_lab3/include/number_to_wordsApp.h new file mode 100644 index 000000000..c5d10f31f --- /dev/null +++ b/modules/nedelin_d_number_to_words_lab3/include/number_to_wordsApp.h @@ -0,0 +1,17 @@ +// Copyright 2024 Nedelin Dmitry + +#ifndef MODULES_NEDELIN_DMITRY_NUMBER_TO_WORDS_INCLUDE_APPLICATION_H_ +#define MODULES_NEDELIN_DMITRY_NUMBER_TO_WORDS_INCLUDE_APPLICATION_H_ + +#include +#include + +class Application{ +public: + std::vector runApp(int argc, const char** argv); + +private: + std::string processNumber(const std::string& input); +}; + +#endif // MODULES_NEDELIN_DMITRY_NUMBER_TO_WORDS_INCLUDE_APPLICATION_H_ diff --git a/modules/nedelin_d_number_to_words_lab3/src/CMakeLists.txt b/modules/nedelin_d_number_to_words_lab3/src/CMakeLists.txt new file mode 100644 index 000000000..b1dc57b01 --- /dev/null +++ b/modules/nedelin_d_number_to_words_lab3/src/CMakeLists.txt @@ -0,0 +1,18 @@ +set(target ${LIBRARY}) + +file(GLOB srcs "*.cpp") +file(GLOB hdrs "../include/*.h") +set_source_files_properties(${srcs} ${hdrs} PROPERTIES + LABELS "${MODULE};Library") + +add_library(${target} STATIC ${srcs} ${hdrs}) +set_target_properties(${target} PROPERTIES + OUTPUT_NAME ${MODULE} + LABELS "${MODULE};Library") + +if (UNIX) + target_link_libraries(${target} ${CMAKE_THREAD_LIBS_INIT}) +endif (UNIX) +target_link_libraries(${target} ${LIBRARY_DEPS}) + +set(LIBRARY_DEPS "${LIBRARY_DEPS};${target}" PARENT_SCOPE) diff --git a/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp b/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp new file mode 100644 index 000000000..0c649cd12 --- /dev/null +++ b/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp @@ -0,0 +1,97 @@ +// Copyright 2024 Nedelin Dmitry + +#include "include/number_to_words.h" + +#include +#include +#include + +std::string trim(const std::string& str) { + std::string trimmed = str; + auto end = trimmed.find_last_not_of(' '); + if (end != std::string::npos) { + trimmed.erase(end + 1); + } + return trimmed; +} + +std::string NumberToWords::convert(int number) { + if (number == 0) { + return "zero"; + } + if (number == INT_MIN) { + return "negative two billion one hundred forty seven million four hundred eighty three thousand six hundred forty eight"; + } + + std::stringstream ss; + + if (number < 0) { + ss << "negative "; + number = -number; + } + + static constexpr int BILLION = 1'000'000'000; + static constexpr int MILLION = 1'000'000; + static constexpr int THOUSAND = 1'000; + + if (number >= BILLION) { + ss << convertLessThanOneThousand(number / BILLION) << " billion"; + number %= BILLION; + if (number > 0) { + ss << " "; + } + } + + if (number >= MILLION) { + ss << convertLessThanOneThousand(number / MILLION) << " million"; + number %= MILLION; + if (number > 0) { + ss << " "; + } + } + + if (number >= THOUSAND) { + ss << convertLessThanOneThousand(number / THOUSAND) << " thousand"; + number %= THOUSAND; + if (number > 0) { + ss << " "; + } + } + + if (number > 0) { + ss << convertLessThanOneThousand(number); + } + + return trim(ss.str()); +} + +std::string NumberToWords::convertLessThanOneThousand(int number) { + static const std::array units{ + "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", + "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" + }; + static const std::array tens{ + "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" + }; + + std::stringstream ss; + if (number >= 100) { + ss << units[number / 100] << " hundred"; + number %= 100; + if (number > 0) { + ss << " "; + } + } + if (number >= 20) { + ss << tens[number / 10]; + number %= 10; + if (number > 0) { + ss << " "; + } + } + if (number > 0) { + ss << units[number]; + } + + return ss.str(); +} diff --git a/modules/nedelin_d_number_to_words_lab3/src/number_to_wordsApp.cpp b/modules/nedelin_d_number_to_words_lab3/src/number_to_wordsApp.cpp new file mode 100644 index 000000000..4fd189d36 --- /dev/null +++ b/modules/nedelin_d_number_to_words_lab3/src/number_to_wordsApp.cpp @@ -0,0 +1,44 @@ +// Copyright 2024 Nedelin Dmitry + +#include "include/number_to_words.h" +#include "include/number_to_wordsApp.h" + +#include +#include +#include +#include + +#include +#include + +std::vector Application::runApp(int argc, const char** argv) { + std::vector output; + + if (argc != 2) { + output.push_back("Usage: number_to_words "); + return output; + } + + std::string input = argv[1]; + try { + output.push_back(processNumber(input)); + } + catch (const std::invalid_argument&) { + output.push_back("Invalid number format!"); + } + + return output; +} + +std::string Application::processNumber(const std::string& input) { + int number; + try { + number = std::stoi(input); + } + catch (...) { + throw std::invalid_argument("Invalid input"); + } + + NumberToWords converter; + return converter.convert(number); +} diff --git a/modules/nedelin_d_number_to_words_lab3/test/CMakeLists.txt b/modules/nedelin_d_number_to_words_lab3/test/CMakeLists.txt new file mode 100644 index 000000000..cd06c57bb --- /dev/null +++ b/modules/nedelin_d_number_to_words_lab3/test/CMakeLists.txt @@ -0,0 +1,27 @@ +set(target ${TESTS}) + +file(GLOB srcs "*.cpp") +set_source_files_properties(${srcs} PROPERTIES + LABELS "${MODULE};Test") + +add_executable(${target} ${srcs} ${hdrs}) +set_target_properties(${target} PROPERTIES + LABELS "${MODULE};Test") + +if (UNIX) + target_link_libraries(${target} gtest ${CMAKE_THREAD_LIBS_INIT} pthread) +endif (UNIX) +target_link_libraries(${target} gtest ${LIBRARY}) + +# VS2012 doesn't support correctly the tuples yet, +# see http://code.google.com/p/googletest/issues/detail?id=412 +if(MSVC) + target_compile_definitions(${target} PUBLIC _VARIADIC_MAX=10) +endif() + +add_test( + NAME ${MODULE}_gtest + COMMAND ${target} +) +set_tests_properties (${MODULE}_gtest PROPERTIES + LABELS "${MODULE}") diff --git a/modules/nedelin_d_number_to_words_lab3/test/test_main.cpp b/modules/nedelin_d_number_to_words_lab3/test/test_main.cpp new file mode 100644 index 000000000..08a4e6325 --- /dev/null +++ b/modules/nedelin_d_number_to_words_lab3/test/test_main.cpp @@ -0,0 +1,9 @@ +// Copyright 2024 Nedelin Dmitry + +#include +#include "include/number_to_wordsApp.h" + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp b/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp new file mode 100644 index 000000000..01419f429 --- /dev/null +++ b/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp @@ -0,0 +1,105 @@ +// Copyright 2024 Nedelin Dmitry + +#include + +#include "include/number_to_words.h" +#include "include/number_to_wordsApp.h" + +TEST(NumberToWordsTest, ConvertZero) { + NumberToWords converter; + ASSERT_EQ(converter.convert(0), "zero"); +} + +TEST(NumberToWordsTest, ConvertPositiveNumbers) { + NumberToWords converter; + ASSERT_EQ(converter.convert(1), "one"); + ASSERT_EQ(converter.convert(12), "twelve"); + ASSERT_EQ(converter.convert(123), "one hundred twenty three"); + ASSERT_EQ(converter.convert(1234), "one thousand two hundred thirty four"); + ASSERT_EQ(converter.convert(1234567), + "one million two hundred thirty four thousand five hundred sixty seven"); +} + +TEST(NumberToWordsTest, ConvertNegativeNumbers) { + NumberToWords converter; + ASSERT_EQ(converter.convert(-1), "negative one"); + ASSERT_EQ(converter.convert(-12), "negative twelve"); + ASSERT_EQ(converter.convert(-123), "negative one hundred twenty three"); +} + +TEST(NumberToWordsTest, ConvertLargeNumbers) { + NumberToWords converter; + ASSERT_EQ(converter.convert(1'000'000'000), "one billion"); + ASSERT_EQ(converter.convert(1'172'839'450), + "one billion one hundred seventy two million eight hundred thirty nine thousand four hundred fifty"); +} + +TEST(NumberToWordsTest, ConvertNegativeLargeNumbers) { + NumberToWords converter; + ASSERT_EQ(converter.convert(-1'000'000'000), "negative one billion"); + ASSERT_EQ(converter.convert(-1'172'839'450), + "negative one billion one hundred seventy two million eight hundred thirty nine thousand four hundred fifty"); +} + +TEST(NumberToWordsTest, ConvertEdgeCases) { + NumberToWords converter; + ASSERT_EQ(converter.convert(0), "zero"); + ASSERT_EQ(converter.convert(INT_MAX), "two billion one hundred forty seven million four hundred eighty three thousand six hundred forty seven"); + ASSERT_EQ(converter.convert(INT_MIN), "negative two billion one hundred forty seven million four hundred eighty three thousand six hundred forty eight"); +} + +TEST(NumberToWordsTest, ConvertTensAndUnits) { + NumberToWords converter; + ASSERT_EQ(converter.convert(20), "twenty"); + ASSERT_EQ(converter.convert(99), "ninety nine"); + ASSERT_EQ(converter.convert(101), "one hundred one"); + ASSERT_EQ(converter.convert(111), "one hundred eleven"); +} + +TEST(ApplicationTest, ValidInput_PositiveNumber) { + Application app; + const char* argv[] = { "app", "123" }; + auto output = app.runApp(2, argv); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output[0], "one hundred twenty three"); +} + +TEST(ApplicationTest, ValidInput_NegativeNumber) { + Application app; + const char* argv[] = { "app", "-456" }; + auto output = app.runApp(2, argv); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output[0], "negative four hundred fifty six"); +} + +TEST(ApplicationTest, InvalidInput_NonNumeric) { + Application app; + const char* argv[] = { "app", "abc" }; + auto output = app.runApp(2, argv); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output[0], "Invalid number format!"); +} + +TEST(ApplicationTest, MissingArgument) { + Application app; + const char* argv[] = { "app" }; + auto output = app.runApp(1, argv); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output[0], "Usage: number_to_words "); +} + +TEST(ApplicationTest, Boundary_MinInt) { + Application app; + const char* argv[] = { "app", "-2147483648" }; + auto output = app.runApp(2, argv); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output[0], "negative two billion one hundred forty seven million four hundred eighty three thousand six hundred forty eight"); +} + +TEST(ApplicationTest, Boundary_MaxInt) { + Application app; + const char* argv[] = { "app", "2147483647" }; + auto output = app.runApp(2, argv); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output[0], "two billion one hundred forty seven million four hundred eighty three thousand six hundred forty seven"); +} From d4c61f44bd14505e648f4627c8b52d202911e30c Mon Sep 17 00:00:00 2001 From: STELLSAN Date: Sun, 1 Dec 2024 17:38:55 +0300 Subject: [PATCH 02/11] cpplint_fix --- .../include/number_to_words.h | 6 +++--- .../include/number_to_wordsApp.h | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/nedelin_d_number_to_words_lab3/include/number_to_words.h b/modules/nedelin_d_number_to_words_lab3/include/number_to_words.h index a419cbdba..cfbc1d5af 100644 --- a/modules/nedelin_d_number_to_words_lab3/include/number_to_words.h +++ b/modules/nedelin_d_number_to_words_lab3/include/number_to_words.h @@ -1,7 +1,7 @@ // Copyright 2024 Nedelin Dmitry -#ifndef MODULES_NEDELIN_DMITRY_NUMBER_TO_WORDS_INCLUDE_NUMBER_TO_WORDS_H_ -#define MODULES_NEDELIN_DMITRY_NUMBER_TO_WORDS_INCLUDE_NUMBER_TO_WORDS_H_ +#ifndef MODULES_NEDELIN_D_NUMBER_TO_WORDS_LAB3_INCLUDE_NUMBER_TO_WORDS_H_ +#define MODULES_NEDELIN_D_NUMBER_TO_WORDS_LAB3_INCLUDE_NUMBER_TO_WORDS_H_ #include @@ -13,4 +13,4 @@ class NumberToWords { std::string convertLessThanOneThousand(int number); }; -#endif // MODULES_NEDELIN_DMITRY_NUMBER_TO_WORDS_INCLUDE_NUMBER_TO_WORDS_H_ +#endif // MODULES_NEDELIN_D_NUMBER_TO_WORDS_LAB3_INCLUDE_NUMBER_TO_WORDS_H_ diff --git a/modules/nedelin_d_number_to_words_lab3/include/number_to_wordsApp.h b/modules/nedelin_d_number_to_words_lab3/include/number_to_wordsApp.h index c5d10f31f..855004a2b 100644 --- a/modules/nedelin_d_number_to_words_lab3/include/number_to_wordsApp.h +++ b/modules/nedelin_d_number_to_words_lab3/include/number_to_wordsApp.h @@ -1,17 +1,17 @@ // Copyright 2024 Nedelin Dmitry -#ifndef MODULES_NEDELIN_DMITRY_NUMBER_TO_WORDS_INCLUDE_APPLICATION_H_ -#define MODULES_NEDELIN_DMITRY_NUMBER_TO_WORDS_INCLUDE_APPLICATION_H_ +#ifndef MODULES_NEDELIN_D_NUMBER_TO_WORDS_LAB3_INCLUDE_NUMBER_TO_WORDSAPP_H_ +#define MODULES_NEDELIN_D_NUMBER_TO_WORDS_LAB3_INCLUDE_NUMBER_TO_WORDSAPP_H_ #include #include class Application{ -public: + public: std::vector runApp(int argc, const char** argv); -private: + private: std::string processNumber(const std::string& input); }; -#endif // MODULES_NEDELIN_DMITRY_NUMBER_TO_WORDS_INCLUDE_APPLICATION_H_ +#endif // MODULES_NEDELIN_D_NUMBER_TO_WORDS_LAB3_INCLUDE_NUMBER_TO_WORDSAPP_H_ From abae5b583bb528506cdb0bdda6a0169f7a8aa7ba Mon Sep 17 00:00:00 2001 From: STELLSAN Date: Sun, 1 Dec 2024 17:45:38 +0300 Subject: [PATCH 03/11] cpplint_fix_2 --- .../include/number_to_words.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/nedelin_d_number_to_words_lab3/include/number_to_words.h b/modules/nedelin_d_number_to_words_lab3/include/number_to_words.h index cfbc1d5af..2bb7cf528 100644 --- a/modules/nedelin_d_number_to_words_lab3/include/number_to_words.h +++ b/modules/nedelin_d_number_to_words_lab3/include/number_to_words.h @@ -1,7 +1,7 @@ // Copyright 2024 Nedelin Dmitry -#ifndef MODULES_NEDELIN_D_NUMBER_TO_WORDS_LAB3_INCLUDE_NUMBER_TO_WORDS_H_ -#define MODULES_NEDELIN_D_NUMBER_TO_WORDS_LAB3_INCLUDE_NUMBER_TO_WORDS_H_ +#ifndef MODULES_NEDELIN_D_NUMBER_TO_WORDS_LAB3_INCLUDE_NUMBER_TO_WORDS_H_ +#define MODULES_NEDELIN_D_NUMBER_TO_WORDS_LAB3_INCLUDE_NUMBER_TO_WORDS_H_ #include @@ -13,4 +13,4 @@ class NumberToWords { std::string convertLessThanOneThousand(int number); }; -#endif // MODULES_NEDELIN_D_NUMBER_TO_WORDS_LAB3_INCLUDE_NUMBER_TO_WORDS_H_ +#endif // MODULES_NEDELIN_D_NUMBER_TO_WORDS_LAB3_INCLUDE_NUMBER_TO_WORDS_H_ From de28b81c5ecb09e283308f0ac67d0243dd78453c Mon Sep 17 00:00:00 2001 From: STELLSAN Date: Sun, 1 Dec 2024 18:02:19 +0300 Subject: [PATCH 04/11] cpplint_fix_3 --- .../src/number_to_words.cpp | 12 +++++++----- .../src/number_to_wordsApp.cpp | 2 -- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp b/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp index 0c649cd12..a9328c3ef 100644 --- a/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp +++ b/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp @@ -3,7 +3,6 @@ #include "include/number_to_words.h" #include -#include #include std::string trim(const std::string& str) { @@ -20,7 +19,8 @@ std::string NumberToWords::convert(int number) { return "zero"; } if (number == INT_MIN) { - return "negative two billion one hundred forty seven million four hundred eighty three thousand six hundred forty eight"; + return "negative two billion one hundred forty seven million four hundred " + "eighty three thousand six hundred forty eight"; } std::stringstream ss; @@ -67,11 +67,13 @@ std::string NumberToWords::convert(int number) { std::string NumberToWords::convertLessThanOneThousand(int number) { static const std::array units{ - "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", - "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" + "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", + "nine","ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", + "sixteen", "seventeen", "eighteen", "nineteen" }; static const std::array tens{ - "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" + "", "", "twenty", "thirty", "forty", "fifty", "sixty", + "seventy", "eighty", "ninety" }; std::stringstream ss; diff --git a/modules/nedelin_d_number_to_words_lab3/src/number_to_wordsApp.cpp b/modules/nedelin_d_number_to_words_lab3/src/number_to_wordsApp.cpp index 4fd189d36..36037803b 100644 --- a/modules/nedelin_d_number_to_words_lab3/src/number_to_wordsApp.cpp +++ b/modules/nedelin_d_number_to_words_lab3/src/number_to_wordsApp.cpp @@ -4,9 +4,7 @@ #include "include/number_to_wordsApp.h" #include -#include #include -#include #include #include From 7c9727a52b01f9d722caa812c789e8e69edaaf12 Mon Sep 17 00:00:00 2001 From: STELLSAN Date: Sun, 1 Dec 2024 18:10:18 +0300 Subject: [PATCH 05/11] cpplint_fix_4 --- .../nedelin_d_number_to_words_lab3/src/number_to_words.cpp | 6 +++--- .../src/number_to_wordsApp.cpp | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp b/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp index a9328c3ef..cbe56c892 100644 --- a/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp +++ b/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp @@ -19,8 +19,8 @@ std::string NumberToWords::convert(int number) { return "zero"; } if (number == INT_MIN) { - return "negative two billion one hundred forty seven million four hundred " - "eighty three thousand six hundred forty eight"; + return "negative two billion one hundred forty seven million four " + "hundred eighty three thousand six hundred forty eight"; } std::stringstream ss; @@ -68,7 +68,7 @@ std::string NumberToWords::convert(int number) { std::string NumberToWords::convertLessThanOneThousand(int number) { static const std::array units{ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", - "nine","ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", + "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; static const std::array tens{ diff --git a/modules/nedelin_d_number_to_words_lab3/src/number_to_wordsApp.cpp b/modules/nedelin_d_number_to_words_lab3/src/number_to_wordsApp.cpp index 36037803b..a0ed37dd6 100644 --- a/modules/nedelin_d_number_to_words_lab3/src/number_to_wordsApp.cpp +++ b/modules/nedelin_d_number_to_words_lab3/src/number_to_wordsApp.cpp @@ -6,9 +6,6 @@ #include #include -#include -#include - std::vector Application::runApp(int argc, const char** argv) { std::vector output; From c5a5e2eb419073dff16f1dcce630ae4cccf7050e Mon Sep 17 00:00:00 2001 From: STELLSAN Date: Sun, 1 Dec 2024 18:21:40 +0300 Subject: [PATCH 06/11] fix_5 --- .../test/test_main.cpp | 4 +-- .../test/test_number_to_words.cpp | 29 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/modules/nedelin_d_number_to_words_lab3/test/test_main.cpp b/modules/nedelin_d_number_to_words_lab3/test/test_main.cpp index 08a4e6325..ffd4f722e 100644 --- a/modules/nedelin_d_number_to_words_lab3/test/test_main.cpp +++ b/modules/nedelin_d_number_to_words_lab3/test/test_main.cpp @@ -4,6 +4,6 @@ #include "include/number_to_wordsApp.h" int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp b/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp index 01419f429..dd097c8c2 100644 --- a/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp +++ b/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp @@ -15,9 +15,11 @@ TEST(NumberToWordsTest, ConvertPositiveNumbers) { ASSERT_EQ(converter.convert(1), "one"); ASSERT_EQ(converter.convert(12), "twelve"); ASSERT_EQ(converter.convert(123), "one hundred twenty three"); - ASSERT_EQ(converter.convert(1234), "one thousand two hundred thirty four"); + ASSERT_EQ(converter.convert(1234), + "one thousand two hundred thirty four"); ASSERT_EQ(converter.convert(1234567), - "one million two hundred thirty four thousand five hundred sixty seven"); + "one million two hundred thirty four thousand " + "five hundred sixty seven"); } TEST(NumberToWordsTest, ConvertNegativeNumbers) { @@ -31,21 +33,27 @@ TEST(NumberToWordsTest, ConvertLargeNumbers) { NumberToWords converter; ASSERT_EQ(converter.convert(1'000'000'000), "one billion"); ASSERT_EQ(converter.convert(1'172'839'450), - "one billion one hundred seventy two million eight hundred thirty nine thousand four hundred fifty"); + "one billion one hundred seventy two million eight hundred " + "thirty nine thousand four hundred fifty"); } TEST(NumberToWordsTest, ConvertNegativeLargeNumbers) { NumberToWords converter; ASSERT_EQ(converter.convert(-1'000'000'000), "negative one billion"); ASSERT_EQ(converter.convert(-1'172'839'450), - "negative one billion one hundred seventy two million eight hundred thirty nine thousand four hundred fifty"); + "negative one billion one hundred seventy two million " + "eight hundred thirty nine thousand four hundred fifty"); } TEST(NumberToWordsTest, ConvertEdgeCases) { NumberToWords converter; ASSERT_EQ(converter.convert(0), "zero"); - ASSERT_EQ(converter.convert(INT_MAX), "two billion one hundred forty seven million four hundred eighty three thousand six hundred forty seven"); - ASSERT_EQ(converter.convert(INT_MIN), "negative two billion one hundred forty seven million four hundred eighty three thousand six hundred forty eight"); + ASSERT_EQ(converter.convert(INT_MAX), + "two billion one hundred forty seven million four hundred " + "eighty three thousand six hundred forty seven"); + ASSERT_EQ(converter.convert(INT_MIN), + "negative two billion one hundred forty seven million four " + "hundred eighty three thousand six hundred forty eight"); } TEST(NumberToWordsTest, ConvertTensAndUnits) { @@ -93,13 +101,16 @@ TEST(ApplicationTest, Boundary_MinInt) { const char* argv[] = { "app", "-2147483648" }; auto output = app.runApp(2, argv); ASSERT_EQ(output.size(), 1); - EXPECT_EQ(output[0], "negative two billion one hundred forty seven million four hundred eighty three thousand six hundred forty eight"); + EXPECT_EQ(output[0], + "negative two billion one hundred forty seven million four " + "hundred eighty three thousand six hundred forty eight"); } TEST(ApplicationTest, Boundary_MaxInt) { Application app; const char* argv[] = { "app", "2147483647" }; auto output = app.runApp(2, argv); - ASSERT_EQ(output.size(), 1); - EXPECT_EQ(output[0], "two billion one hundred forty seven million four hundred eighty three thousand six hundred forty seven"); + EXPECT_EQ(output[0], + "two billion one hundred forty seven million four hundred " + "eighty three thousand six hundred forty seven"); } From 8e09746e1e8eee6902ee450450389017412fcae3 Mon Sep 17 00:00:00 2001 From: STELLSAN Date: Sun, 1 Dec 2024 18:57:02 +0300 Subject: [PATCH 07/11] coverage_fix_1 --- .../src/number_to_words.cpp | 8 ++++---- .../test/test_number_to_words.cpp | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp b/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp index cbe56c892..7f01d6371 100644 --- a/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp +++ b/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp @@ -20,7 +20,7 @@ std::string NumberToWords::convert(int number) { } if (number == INT_MIN) { return "negative two billion one hundred forty seven million four " - "hundred eighty three thousand six hundred forty eight"; + "hundred eighty three thousand six hundred forty eight"; } std::stringstream ss; @@ -30,9 +30,9 @@ std::string NumberToWords::convert(int number) { number = -number; } - static constexpr int BILLION = 1'000'000'000; - static constexpr int MILLION = 1'000'000; - static constexpr int THOUSAND = 1'000; + static constexpr int BILLION = 1000000000; + static constexpr int MILLION = 1000000; + static constexpr int THOUSAND = 1000; if (number >= BILLION) { ss << convertLessThanOneThousand(number / BILLION) << " billion"; diff --git a/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp b/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp index dd097c8c2..2b72a9e5a 100644 --- a/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp +++ b/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp @@ -31,16 +31,16 @@ TEST(NumberToWordsTest, ConvertNegativeNumbers) { TEST(NumberToWordsTest, ConvertLargeNumbers) { NumberToWords converter; - ASSERT_EQ(converter.convert(1'000'000'000), "one billion"); - ASSERT_EQ(converter.convert(1'172'839'450), + ASSERT_EQ(converter.convert(1000000000), "one billion"); + ASSERT_EQ(converter.convert(1172839450), "one billion one hundred seventy two million eight hundred " "thirty nine thousand four hundred fifty"); } TEST(NumberToWordsTest, ConvertNegativeLargeNumbers) { NumberToWords converter; - ASSERT_EQ(converter.convert(-1'000'000'000), "negative one billion"); - ASSERT_EQ(converter.convert(-1'172'839'450), + ASSERT_EQ(converter.convert(-1000000000), "negative one billion"); + ASSERT_EQ(converter.convert(-1172839450), "negative one billion one hundred seventy two million " "eight hundred thirty nine thousand four hundred fifty"); } @@ -110,6 +110,7 @@ TEST(ApplicationTest, Boundary_MaxInt) { Application app; const char* argv[] = { "app", "2147483647" }; auto output = app.runApp(2, argv); + ASSERT_EQ(output.size(), 1); EXPECT_EQ(output[0], "two billion one hundred forty seven million four hundred " "eighty three thousand six hundred forty seven"); From 2ccf2e6ca657483fad2655f5bf4b94842c2eeb18 Mon Sep 17 00:00:00 2001 From: STELLSAN Date: Sun, 1 Dec 2024 20:42:25 +0300 Subject: [PATCH 08/11] coverage_fix_2 --- .../nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp b/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp index 2b72a9e5a..60bc4cf1d 100644 --- a/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp +++ b/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp @@ -4,6 +4,7 @@ #include "include/number_to_words.h" #include "include/number_to_wordsApp.h" +#include TEST(NumberToWordsTest, ConvertZero) { NumberToWords converter; From 44cb2c04ecd0507dba1b7a0e8d3672873c4141bf Mon Sep 17 00:00:00 2001 From: STELLSAN Date: Sun, 1 Dec 2024 20:51:17 +0300 Subject: [PATCH 09/11] fix_8 --- .../test/test_number_to_words.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp b/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp index 60bc4cf1d..dc13a83a4 100644 --- a/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp +++ b/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp @@ -1,10 +1,10 @@ // Copyright 2024 Nedelin Dmitry #include +#include #include "include/number_to_words.h" #include "include/number_to_wordsApp.h" -#include TEST(NumberToWordsTest, ConvertZero) { NumberToWords converter; From 2f2d933f7ca3d2b1e81a32d9308a09812f9ac4ed Mon Sep 17 00:00:00 2001 From: STELLSAN Date: Sun, 1 Dec 2024 21:04:51 +0300 Subject: [PATCH 10/11] fix_9 --- modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp b/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp index 7f01d6371..b7ced8d28 100644 --- a/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp +++ b/modules/nedelin_d_number_to_words_lab3/src/number_to_words.cpp @@ -2,6 +2,7 @@ #include "include/number_to_words.h" +#include #include #include From 860ade88d20e5dd02d86ba95f23c8c27bcf3b209 Mon Sep 17 00:00:00 2001 From: STELLSAN Date: Sun, 1 Dec 2024 21:23:13 +0300 Subject: [PATCH 11/11] coverage_fix_5 --- .../test/test_number_to_words.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp b/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp index dc13a83a4..ce8abb807 100644 --- a/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp +++ b/modules/nedelin_d_number_to_words_lab3/test/test_number_to_words.cpp @@ -69,7 +69,7 @@ TEST(ApplicationTest, ValidInput_PositiveNumber) { Application app; const char* argv[] = { "app", "123" }; auto output = app.runApp(2, argv); - ASSERT_EQ(output.size(), 1); + ASSERT_EQ(output.size(), static_cast(1)); EXPECT_EQ(output[0], "one hundred twenty three"); } @@ -77,7 +77,7 @@ TEST(ApplicationTest, ValidInput_NegativeNumber) { Application app; const char* argv[] = { "app", "-456" }; auto output = app.runApp(2, argv); - ASSERT_EQ(output.size(), 1); + ASSERT_EQ(output.size(), static_cast(1)); EXPECT_EQ(output[0], "negative four hundred fifty six"); } @@ -85,7 +85,7 @@ TEST(ApplicationTest, InvalidInput_NonNumeric) { Application app; const char* argv[] = { "app", "abc" }; auto output = app.runApp(2, argv); - ASSERT_EQ(output.size(), 1); + ASSERT_EQ(output.size(), static_cast(1)); EXPECT_EQ(output[0], "Invalid number format!"); } @@ -93,7 +93,7 @@ TEST(ApplicationTest, MissingArgument) { Application app; const char* argv[] = { "app" }; auto output = app.runApp(1, argv); - ASSERT_EQ(output.size(), 1); + ASSERT_EQ(output.size(), static_cast(1)); EXPECT_EQ(output[0], "Usage: number_to_words "); } @@ -101,7 +101,7 @@ TEST(ApplicationTest, Boundary_MinInt) { Application app; const char* argv[] = { "app", "-2147483648" }; auto output = app.runApp(2, argv); - ASSERT_EQ(output.size(), 1); + ASSERT_EQ(output.size(), static_cast(1)); EXPECT_EQ(output[0], "negative two billion one hundred forty seven million four " "hundred eighty three thousand six hundred forty eight"); @@ -111,7 +111,7 @@ TEST(ApplicationTest, Boundary_MaxInt) { Application app; const char* argv[] = { "app", "2147483647" }; auto output = app.runApp(2, argv); - ASSERT_EQ(output.size(), 1); + ASSERT_EQ(output.size(), static_cast(1)); EXPECT_EQ(output[0], "two billion one hundred forty seven million four hundred " "eighty three thousand six hundred forty seven");