добавлены unittest.cbp(cpp) файлы, doctest.h и histogram_internal.h

master
Platon (MiachinPY) 2 недель назад
Родитель 5615f8a811
Сommit 33c7a23266

@ -3,7 +3,7 @@
#include "histogram.h" #include "histogram.h"
using namespace std; using namespace std;
void static find_minmax(const vector<double> &numbers, double &min, double &max) void find_minmax(const vector<double> &numbers, double &min, double &max)
{ {
min = numbers[0]; min = numbers[0];
max = numbers[0]; max = numbers[0];

@ -0,0 +1,6 @@
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
#define HISTOGRAM_INTERNAL_H_INCLUDED
#include <vector>
void find_minmax(const std::vector<double> &numbers, double &min, double &max);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED

@ -0,0 +1,52 @@
#include <iostream>
#include <vector>
#include "histogram.h"
using namespace std;
void find_minmax(const vector<double> &numbers, double &min, double &max)
{
min = numbers[0];
max = numbers[0];
for(double number : numbers)
{
if(number < min)
{
min = number;
}
if(number > max)
{
max = number;
}
}
return;
}
std::vector<size_t> make_histogram(std::vector<double>& numbers, size_t bin_count)
{
double min;
double max;
find_minmax (numbers, min, max);
double bin_size = (max - min) / bin_count;
vector<size_t> bins(bin_count);
for (size_t i = 0; i < numbers.size(); i++)
{
bool found = false;
for(size_t j = 0; (j < (bin_count - 1)) && !found; j++)
{
auto lo = min + j * bin_size;
auto hi = min + (j + 1) * bin_size;
if((lo <= numbers[i]) && (numbers[i] < hi))
{
bins[j]++;
found = true;
}
}
if (!found)
{
bins[bin_count-1]++;
}
}
return bins;
}

@ -32,7 +32,18 @@
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
</Compiler> </Compiler>
<Unit filename="doctest.h" />
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h" />
<Unit filename="histogram_internal.h" />
<Unit filename="historgam.cpp" />
<Unit filename="lab01.cbp" />
<Unit filename="lab01.depend" />
<Unit filename="lab01.layout" />
<Unit filename="main.cpp" /> <Unit filename="main.cpp" />
<Unit filename="text.cpp" />
<Unit filename="text.h" />
<Unit filename="unittest.cpp" />
<Extensions /> <Extensions />
</Project> </Project>
</CodeBlocks_project_file> </CodeBlocks_project_file>

@ -0,0 +1,80 @@
# depslib dependency file v1.0
1745609797 source:c:\users\ïëàòîí\desktop\project\lab01\main.cpp
<iostream>
<vector>
"histogram.h"
"text.h"
1745611606 source:c:\users\ïëàòîí\desktop\project\lab01\historgam.cpp
<iostream>
<vector>
"histogram.h"
1745607609 c:\users\ïëàòîí\desktop\project\lab01\histogram.h
<vector>
1745609703 source:c:\users\ïëàòîí\desktop\project\lab01\text.cpp
<iostream>
<vector>
"text.h"
1745609691 c:\users\ïëàòîí\desktop\project\lab01\text.h
<vector>
1745609785 source:c:\users\ïëàòîí\desktop\project\lab01\unittest.cpp
"doctest.h"
"histogram_internal.h"
1745609083 c:\users\ïëàòîí\desktop\project\lab01\doctest.h
<signal.h>
<ciso646>
<cstddef>
<ostream>
<istream>
<type_traits>
"doctest_fwd.h"
<ctime>
<cmath>
<climits>
<math.h>
<new>
<cstdio>
<cstdlib>
<cstring>
<limits>
<utility>
<fstream>
<sstream>
<iostream>
<algorithm>
<iomanip>
<vector>
<atomic>
<mutex>
<set>
<map>
<unordered_set>
<exception>
<stdexcept>
<csignal>
<cfloat>
<cctype>
<cstdint>
<string>
<sys/types.h>
<unistd.h>
<sys/sysctl.h>
<AfxWin.h>
<windows.h>
<io.h>
<sys/time.h>
<unistd.h>
1745611606 c:\users\ïëàòîí\desktop\project\lab01\histogram_internal.h
<vector>
1746093073 source:c:\users\ïëàòîí\desktop\project\lab01\histogram.cpp
<iostream>
<vector>
"histogram.h"

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="795" topLine="2" />
</Cursor>
</File>
<File name="histogram.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -1,6 +1,7 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "histogram.h" #include "histogram.h"
#include "text.h"
using namespace std; using namespace std;
@ -26,45 +27,6 @@ input_data() {
cin >> in.bin_count; cin >> in.bin_count;
return in; return in;
} }
void show_histogram_text(vector<size_t> bins, size_t bin_count){
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
size_t max_bin = bins[0];
for(size_t i = 0; i < bin_count; i++)
{
if(bins[i] > max_bin)
{
max_bin = bins[i];
}
}
for (size_t bin: bins)
{
size_t height = bin;
if (max_bin > MAX_ASTERISK)
{
height = MAX_ASTERISK * (static_cast<double>(bin) / max_bin);
}
if (bin < 100)
{
cout << ' ';
}
if (bin < 10)
{
cout << ' ';
}
cout << bin << "|";
for(size_t i = 0; i < height; i++)
{
cout << "*";
}
cout << endl;
}
}
int main() int main()
{ {
auto in = input_data(); auto in = input_data();

@ -0,0 +1,44 @@
#include <iostream>
#include <vector>
#include "text.h"
using namespace std;
void show_histogram_text(vector<size_t> bins, size_t bin_count){
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
size_t max_bin = bins[0];
for(size_t i = 0; i < bin_count; i++)
{
if(bins[i] > max_bin)
{
max_bin = bins[i];
}
}
for (size_t bin: bins)
{
size_t height = bin;
if (max_bin > MAX_ASTERISK)
{
height = MAX_ASTERISK * (static_cast<double>(bin) / max_bin);
}
if (bin < 100)
{
cout << ' ';
}
if (bin < 10)
{
cout << ' ';
}
cout << bin << "|";
for(size_t i = 0; i < height; i++)
{
cout << "*";
}
cout << endl;
}
}

@ -0,0 +1,6 @@
#ifndef TEXT_H_INCLUDED
#define TEXT_H_INCLUDED
#include <vector>
void show_histogram_text(std::vector<size_t> bins, size_t bin_count);
#endif // TEXT_H_INCLUDED

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="unittest" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/unittest" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/unittest" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

@ -0,0 +1,26 @@
#define DOCTEST_CONFIG_NO_MULTITHREADING
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "histogram_internal.h"
TEST_CASE("distinct positive numbers") {
double min = 0;
double max = 0;
find_minmax({1, 2}, min, max);
CHECK(min == 1);
CHECK(max == 2);
}
TEST_CASE("distinct negative numbers"){
double min = 0;
double max = 0;
find_minmax({-1, -2}, min, max);
CHECK(min == -2);
CHECK(max == -1);
}
TEST_CASE("vector of the same elements"){
double min = 0;
double max = 0;
find_minmax({3,3,3}, min, max);
CHECK(min == 3);
CHECK(max == 3);
}

@ -0,0 +1,66 @@
# depslib dependency file v1.0
1745608562 source:c:\users\ïëàòîí\desktop\project\lab01\historgam.cpp
<iostream>
<vector>
"histogram.h"
1745607609 c:\users\ïëàòîí\desktop\project\lab01\histogram.h
<vector>
1746092640 source:c:\users\ïëàòîí\desktop\project\lab01\unittest.cpp
"doctest.h"
"histogram_internal.h"
1745609083 c:\users\ïëàòîí\desktop\project\lab01\doctest.h
<signal.h>
<ciso646>
<cstddef>
<ostream>
<istream>
<type_traits>
"doctest_fwd.h"
<ctime>
<cmath>
<climits>
<math.h>
<new>
<cstdio>
<cstdlib>
<cstring>
<limits>
<utility>
<fstream>
<sstream>
<iostream>
<algorithm>
<iomanip>
<vector>
<atomic>
<mutex>
<set>
<map>
<unordered_set>
<exception>
<stdexcept>
<csignal>
<cfloat>
<cctype>
<cstdint>
<string>
<sys/types.h>
<unistd.h>
<sys/sysctl.h>
<AfxWin.h>
<windows.h>
<io.h>
<sys/time.h>
<unistd.h>
1746092862 c:\users\ïëàòîí\desktop\project\lab01\histogram_internal.h
<vector>
1746092126 source:c:\users\ïëàòîí\desktop\project\lab01\histogram.cpp
<iostream>
<vector>
"histogram.h"
Загрузка…
Отмена
Сохранить