Сравнить коммиты
12 Коммитов
7b584264f5
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 51270d3cea | |||
| ced73de2f7 | |||
| bdc44e502d | |||
| fa47ef4649 | |||
| 1fe50f24cc | |||
| ca0634537d | |||
| 0b9e56cf89 | |||
| 21e87301db | |||
| 26886daedc | |||
| 76950f6e99 | |||
| 44949175d5 | |||
| bf2f0d2977 |
@@ -2,14 +2,20 @@
|
|||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
using namespace std;
|
|
||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
|
|
||||||
void
|
using namespace std;
|
||||||
|
|
||||||
|
bool
|
||||||
find_minmax(const vector<double>& numbers, double& min, double& max){
|
find_minmax(const vector<double>& numbers, double& min, double& max){
|
||||||
|
if (numbers.empty()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
min = numbers[0];
|
min = numbers[0];
|
||||||
min = numbers[0];
|
max = numbers[0];
|
||||||
for(size_t i=0; i < numbers.size(); i++){
|
for(size_t i=0; i < numbers.size(); i++)
|
||||||
|
{
|
||||||
if (numbers[i] < min)
|
if (numbers[i] < min)
|
||||||
{
|
{
|
||||||
min = numbers[i];
|
min = numbers[i];
|
||||||
@@ -19,6 +25,8 @@ find_minmax(const vector<double>& numbers, double& min, double& max){
|
|||||||
max = numbers[i];
|
max = numbers[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
8
histogram_internal.h
Обычный файл
8
histogram_internal.h
Обычный файл
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
bool
|
||||||
|
find_minmax(const std::vector<double>& numbers, double& min, double& max);
|
||||||
|
|
||||||
|
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
8
input_colors_internal.h
Обычный файл
8
input_colors_internal.h
Обычный файл
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef INPUT_COLORS_INTERNAL_H_INCLUDED
|
||||||
|
#define INPUT_COLORS_INTERNAL_H_INCLUDED
|
||||||
|
|
||||||
|
void
|
||||||
|
input_colors(std::string &colors_stroke, std::string &colors_fill);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // INPUT_COLORS_INTERNAL_H_INCLUDED
|
||||||
93
main.cpp
93
main.cpp
@@ -1,51 +1,92 @@
|
|||||||
#include <iostream>
|
#include <curl/curl.h>
|
||||||
#include <conio.h>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdlib.h>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "svg01.h"
|
#include "svg.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
struct Input {
|
struct Input {
|
||||||
vector<double> numbers;
|
vector<double> numbers;
|
||||||
size_t bin_count {};
|
size_t bin_count {};
|
||||||
string colors_stroke;
|
|
||||||
string colors_fill;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Input
|
Input
|
||||||
input_data(){
|
input_data(istream& in, bool prompt){
|
||||||
|
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
|
if (prompt){
|
||||||
cerr << "Enter number count: ";
|
cerr << "Enter number count: ";
|
||||||
cin >> number_count;
|
}
|
||||||
|
in >> number_count;
|
||||||
|
|
||||||
Input in;
|
Input iinn;
|
||||||
|
iinn.numbers.resize(number_count);
|
||||||
in.numbers.resize(number_count);
|
if (prompt){
|
||||||
cerr << "Enter numbers: " << endl;
|
cerr << "Enter numbers: ";}
|
||||||
for (size_t i = 0; i < number_count; i++)
|
for (size_t i = 0; i < number_count; i++)
|
||||||
{
|
{
|
||||||
cin >> in.numbers[i];
|
in >> iinn.numbers[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
cerr << "Enter bin count: ";
|
if (prompt){
|
||||||
cin >> in.bin_count;
|
cerr << "Enter bin count: ";}
|
||||||
in.colors_stroke = "midnightblue";
|
in >> iinn.bin_count;
|
||||||
in.colors_fill = "deeppink";
|
|
||||||
|
|
||||||
input_colors(in.colors_stroke, in.colors_fill);
|
return iinn;
|
||||||
|
|
||||||
return in;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
static size_t
|
||||||
|
write_data(void* items, size_t item_size, size_t item_count, void* ctx){
|
||||||
|
size_t data_size = item_size * item_count;
|
||||||
|
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
|
||||||
|
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
||||||
|
return data_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Input
|
||||||
|
download(const string& address){
|
||||||
|
stringstream buffer;
|
||||||
|
CURL *curl = curl_easy_init();
|
||||||
|
if(curl) {
|
||||||
|
CURLcode res;
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if(!res) {
|
||||||
|
curl_off_t dl;
|
||||||
|
res = curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD_T, &dl);
|
||||||
|
if(!res) {
|
||||||
|
cerr<<"Downloaded "<<dl<< " bytes\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
}
|
||||||
|
return input_data(buffer, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
#include <curl/curl.h>
|
||||||
auto in = input_data();
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
std::vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
Input input;
|
||||||
show_histogram_svg(bins, in.colors_stroke, in.colors_fill);
|
if (argc > 1) {
|
||||||
return 0;
|
input = download(argv[1]);
|
||||||
|
} else {
|
||||||
|
input = input_data(cin, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto bins = make_histogram(input.numbers, input.bin_count);
|
||||||
|
show_histogram_svg(bins);
|
||||||
}
|
}
|
||||||
|
|||||||
6
marks.06.txt
Обычный файл
6
marks.06.txt
Обычный файл
@@ -0,0 +1,6 @@
|
|||||||
|
10
|
||||||
|
3 3 4 4 4 4 4 5 5 5
|
||||||
|
3
|
||||||
|
Yes
|
||||||
|
darkgreen
|
||||||
|
lightcoral
|
||||||
@@ -33,19 +33,19 @@ svg_rect(double x, double y, double width, double height, string colors_stroke,
|
|||||||
void
|
void
|
||||||
input_colors(string &colors_stroke, string &colors_fill){
|
input_colors(string &colors_stroke, string &colors_fill){
|
||||||
string color_personal;
|
string color_personal;
|
||||||
cout << "Do you want to change colors? Yes/No" << endl;
|
cerr << "Do you want to change colors? Yes/No" << endl;
|
||||||
cin >> color_personal;
|
cin >> color_personal;
|
||||||
while ((color_personal != "No") && (color_personal != "Yes")){
|
while ((color_personal != "No") && (color_personal != "Yes")){
|
||||||
cout << "WRONG ANSWER! Try again!" << endl;
|
cerr << "WRONG ANSWER! Try again!" << endl;
|
||||||
cin >> color_personal;
|
cin >> color_personal;
|
||||||
}
|
}
|
||||||
if (color_personal == "No"){
|
if (color_personal == "No"){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cout << "What color for a stroke do you want?" << endl;
|
cerr << "What color for a stroke do you want?" << endl;
|
||||||
cin >> colors_stroke;
|
cin >> colors_stroke;
|
||||||
cout << "What color to fill do you want?" << endl;
|
cerr << "What color to fill do you want?" << endl;
|
||||||
cin >> colors_fill;
|
cin >> colors_fill;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ TEST_CASE("distinct positive numbers") {
|
|||||||
TEST_CASE("empty vector"){
|
TEST_CASE("empty vector"){
|
||||||
double min = 0;
|
double min = 0;
|
||||||
double max = 0;
|
double max = 0;
|
||||||
find_minmax({ 0, 0 }, min, max);
|
CHECK(!find_minmax({}, min, max));
|
||||||
CHECK(min == 0);
|
|
||||||
CHECK(max == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("same elements"){
|
TEST_CASE("same elements"){
|
||||||
@@ -24,7 +22,6 @@ TEST_CASE("same elements"){
|
|||||||
double max = 0;
|
double max = 0;
|
||||||
find_minmax({ 1, 1 }, min, max);
|
find_minmax({ 1, 1 }, min, max);
|
||||||
CHECK(min == max);
|
CHECK(min == max);
|
||||||
CHECK(max == min);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("only one number"){
|
TEST_CASE("only one number"){
|
||||||
@@ -38,7 +35,7 @@ TEST_CASE("only one number"){
|
|||||||
TEST_CASE("distinct negative numbers") {
|
TEST_CASE("distinct negative numbers") {
|
||||||
double min = 0;
|
double min = 0;
|
||||||
double max = 0;
|
double max = 0;
|
||||||
find_minmax({0, -2}, min, max);
|
find_minmax({-1, -2}, min, max);
|
||||||
CHECK(min == -2);
|
CHECK(min == -2);
|
||||||
CHECK(max == 0);
|
CHECK(max == -1);
|
||||||
}
|
}
|
||||||
|
|||||||
20
unittest_personal.cpp
Обычный файл
20
unittest_personal.cpp
Обычный файл
@@ -0,0 +1,20 @@
|
|||||||
|
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||||
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
|
#include "doctest.h"
|
||||||
|
#include "input_colors_internal.h"
|
||||||
|
|
||||||
|
TEST_CASE("Mistakes in spelling") {
|
||||||
|
std::string colors_stroke = "black";
|
||||||
|
std::string colors_fill = "green";
|
||||||
|
input_colors(colors_stroke, colors_fill);
|
||||||
|
CHECK(colors_stroke == "yellow");
|
||||||
|
CHECK(colors_fill == "pink");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("The answer is No") {
|
||||||
|
std::string colors_stroke = "black";
|
||||||
|
std::string colors_fill = "green";
|
||||||
|
input_colors(colors_stroke, colors_fill);
|
||||||
|
CHECK(colors_stroke == "black");
|
||||||
|
CHECK(colors_fill == "green");
|
||||||
|
}
|
||||||
Ссылка в новой задаче
Block a user