diff --git a/histogram.cpp b/histogram.cpp index f6d543d..aaece74 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -1,8 +1,9 @@ #include "histogram.hpp" #include -void find_minmax(std::vector &numbers, double& min, double& max) +bool find_minmax(std::vector &numbers, double& min, double& max) { + if (numbers.empty()) return false; min = numbers[0]; max = numbers[0]; for (double x : numbers) { @@ -11,6 +12,7 @@ void find_minmax(std::vector &numbers, double& min, double& max) if (min > x) min = x; } + return true; } std::vector make_histogram(std::vector numbers, size_t bin_count) diff --git a/lab_3.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/lab_3.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..0c67376 --- /dev/null +++ b/lab_3.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,5 @@ + + + + + diff --git a/lab_3.xcodeproj/project.xcworkspace/xcuserdata/lesaminov.xcuserdatad/UserInterfaceState.xcuserstate b/lab_3.xcodeproj/project.xcworkspace/xcuserdata/lesaminov.xcuserdatad/UserInterfaceState.xcuserstate index b346b5e..13ae96d 100644 Binary files a/lab_3.xcodeproj/project.xcworkspace/xcuserdata/lesaminov.xcuserdatad/UserInterfaceState.xcuserstate and b/lab_3.xcodeproj/project.xcworkspace/xcuserdata/lesaminov.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/lab_3.xcodeproj/project.xcworkspace/xcuserdata/lesaminov.xcuserdatad/WorkspaceSettings.xcsettings b/lab_3.xcodeproj/project.xcworkspace/xcuserdata/lesaminov.xcuserdatad/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..bbfef02 --- /dev/null +++ b/lab_3.xcodeproj/project.xcworkspace/xcuserdata/lesaminov.xcuserdatad/WorkspaceSettings.xcsettings @@ -0,0 +1,14 @@ + + + + + BuildLocationStyle + UseAppPreferences + CustomBuildLocationType + RelativeToDerivedData + DerivedDataLocationStyle + Default + ShowSharedSchemesAutomaticallyEnabled + + + diff --git a/lab_3.xcodeproj/xcshareddata/xcschemes/lab_3.xcscheme b/lab_3.xcodeproj/xcshareddata/xcschemes/lab_3.xcscheme new file mode 100644 index 0000000..7f5653a --- /dev/null +++ b/lab_3.xcodeproj/xcshareddata/xcschemes/lab_3.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lab_3.xcodeproj/xcuserdata/lesaminov.xcuserdatad/xcschemes/xcschememanagement.plist b/lab_3.xcodeproj/xcuserdata/lesaminov.xcuserdatad/xcschemes/xcschememanagement.plist index dcf43d8..55c19b6 100644 --- a/lab_3.xcodeproj/xcuserdata/lesaminov.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/lab_3.xcodeproj/xcuserdata/lesaminov.xcuserdatad/xcschemes/xcschememanagement.plist @@ -10,5 +10,13 @@ 0 + SuppressBuildableAutocreation + + 35EA3A932A2D54F400ED69F1 + + primary + + + diff --git a/main.cpp b/main.cpp index 15e45ed..485e4e4 100644 --- a/main.cpp +++ b/main.cpp @@ -16,15 +16,16 @@ struct Input Input input_data() { size_t number_count; - cout << "Enter number count: "; + cerr << "Enter number count: "; cin >> number_count; // Кол-во чисел Input in; in.numbers.resize(number_count); for (size_t i = 0; i < number_count; i++) { + cerr << "Enter number №" << i+1 << ": "; cin >> in.numbers[i]; } - cout << "Enter bin count: "; + cerr << "Enter bin count: "; cin >> in.bin_count; return in; } diff --git a/svg.cpp b/svg.cpp index 9761ad3..7bdd543 100644 --- a/svg.cpp +++ b/svg.cpp @@ -29,9 +29,9 @@ svg_text(double left, double baseline, string text) } void -svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black") +svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black", string fill_opacity = "1.0") { - cout << " "; } @@ -65,10 +65,8 @@ show_histogram_svg(const vector& bins) { double bin_width = (MAX_WIDTH)*(bins[i]/max_count); double opacity = (bins[i]/max_count); - string fill_opacity = to_string(opacity); svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i])); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, BOARD_COLOR, FILL_COLOR); - cout << " fill-opacity ='" << fill_opacity << "'" << " /> "; + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, BOARD_COLOR, FILL_COLOR, to_string(opacity)); top += BIN_HEIGHT; } diff --git a/unittest/histogram_internal.hpp b/unittest/histogram_internal.hpp index caf2ee2..82b1024 100644 --- a/unittest/histogram_internal.hpp +++ b/unittest/histogram_internal.hpp @@ -1,8 +1,9 @@ #include #include -void find_minmax(std::vector &numbers, double& min, double& max) +bool find_minmax(std::vector &numbers, double& min, double& max) { + if (numbers.empty()) return false; min = numbers[0]; max = numbers[0]; for (double x : numbers) { @@ -11,4 +12,5 @@ void find_minmax(std::vector &numbers, double& min, double& max) if (min > x) min = x; } + return true; } diff --git a/unittest/unittest.cpp b/unittest/unittest.cpp index f5fdc74..6c577ed 100644 --- a/unittest/unittest.cpp +++ b/unittest/unittest.cpp @@ -3,7 +3,7 @@ #include "histogram_internal.hpp" #include -TEST_CASE("distinct positive numbers") { +TEST_CASE("test_negative_numbers") { double min = 0; double max = 0; std::vector numbers3 = {-5, -3, -4, -1, -2}; @@ -11,8 +11,15 @@ TEST_CASE("distinct positive numbers") { CHECK(min == -5); CHECK(max == -1); } - -TEST_CASE("vector with same elements") { +TEST_CASE("test_ positive_numbers") { //тест не должен быть удачным + double min = 0; + double max = 0; + std::vector numbers3 = {1,2,3,4,0}; + find_minmax(numbers3, min, max); + CHECK(min == 1); //min должен быть равен 0 + CHECK(max == 4); +} +TEST_CASE("test_same_elements") { double min = 0; double max = 0; std::vector numbers3 = {2,2,2}; @@ -20,7 +27,7 @@ TEST_CASE("vector with same elements") { CHECK(min == 2); CHECK(max == 2); } -TEST_CASE("distinct positive numbers 2") { +TEST_CASE("test_one_element") { double min = 0; double max = 0; std::vector numbers3 = {-4}; @@ -28,3 +35,9 @@ TEST_CASE("distinct positive numbers 2") { CHECK(min == -4); CHECK(max == -4); } +TEST_CASE("test_no_element") { + double min = 0; + double max = 0; + std::vector numbers3 = {}; + CHECK(find_minmax(numbers3, min, max) == false); +} diff --git a/unittest/unittest.xcodeproj/project.xcworkspace/xcuserdata/lesaminov.xcuserdatad/UserInterfaceState.xcuserstate b/unittest/unittest.xcodeproj/project.xcworkspace/xcuserdata/lesaminov.xcuserdatad/UserInterfaceState.xcuserstate index 3298840..6936264 100644 Binary files a/unittest/unittest.xcodeproj/project.xcworkspace/xcuserdata/lesaminov.xcuserdatad/UserInterfaceState.xcuserstate and b/unittest/unittest.xcodeproj/project.xcworkspace/xcuserdata/lesaminov.xcuserdatad/UserInterfaceState.xcuserstate differ