добавлены тесты
Этот коммит содержится в:
@@ -1,6 +1,6 @@
|
|||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
|
|
||||||
void find_minmax(std::vector<double>& vec, double& min, double& max) {
|
void find_minmax(std::vector<double> vec, double& min, double& max) {
|
||||||
|
|
||||||
|
|
||||||
min = vec[0];
|
min = vec[0];
|
||||||
@@ -11,8 +11,8 @@ void find_minmax(std::vector<double>& vec, double& min, double& max) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<size_t> make_histogram(size_t number, std::vector<double>& vec) {
|
vector<size_t> make_histogram(size_t number, vector<double> vec) {
|
||||||
std::vector<size_t> bins(number);
|
vector<size_t> bins(number);
|
||||||
if (vec.empty()) return bins;
|
if (vec.empty()) return bins;
|
||||||
|
|
||||||
double mn, mx;
|
double mn, mx;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
std::vector<size_t> make_histogram(size_t number, std::vector<double>& vec);
|
using namespace std;
|
||||||
|
vector<size_t> make_histogram(size_t number, vector<double> vec);
|
||||||
|
|
||||||
#endif // HISTOGRAM_H_INCLUDED
|
#endif // HISTOGRAM_H_INCLUDED
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
|
||||||
void find_minmax(std::vector<double>& vec, double& min, double& max);
|
void find_minmax(std::vector<double> vec, double& min, double& max);
|
||||||
|
|
||||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
|||||||
2
text.cpp
2
text.cpp
@@ -1,7 +1,7 @@
|
|||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void show_histogram(const std::vector<size_t>& bins) {
|
void show_histogram(const vector<size_t>& bins) {
|
||||||
|
|
||||||
|
|
||||||
bool gigant = false;
|
bool gigant = false;
|
||||||
|
|||||||
2
text.h
2
text.h
@@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
void show_histogram(const std::vector<size_t>& bins);
|
void show_histogram(const vector<size_t>& bins);
|
||||||
|
|
||||||
#endif // TEXT_H_INCLUDED
|
#endif // TEXT_H_INCLUDED
|
||||||
|
|||||||
55
unittest.cpp
55
unittest.cpp
@@ -0,0 +1,55 @@
|
|||||||
|
#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);
|
||||||
|
}
|
||||||
|
TEST_CASE("vector of one elements"){
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({3}, min, max);
|
||||||
|
CHECK(min == max);
|
||||||
|
}
|
||||||
|
TEST_CASE("mixed positive and negative numbers") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({-1, 2, 0, -3, 5}, min, max);
|
||||||
|
CHECK(min == -3);
|
||||||
|
CHECK(max == 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("vector with all negative numbers") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({-5, -10, -2}, min, max);
|
||||||
|
CHECK(min == -10);
|
||||||
|
CHECK(max == -2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("vector with zero") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({0, -1, 1}, min, max);
|
||||||
|
CHECK(min == -1);
|
||||||
|
CHECK(max == 1);
|
||||||
|
}
|
||||||
|
|||||||
Двоичные данные
unittest/bin/Debug/unittest.exe
Обычный файл
Двоичные данные
unittest/bin/Debug/unittest.exe
Обычный файл
Двоичный файл не отображается.
Двоичные данные
unittest/obj/Debug/histogram.o
Двоичные данные
unittest/obj/Debug/histogram.o
Двоичный файл не отображается.
Двоичные данные
unittest/obj/Debug/unittest.o
Двоичные данные
unittest/obj/Debug/unittest.o
Двоичный файл не отображается.
59
unittest/unittest.depend
Обычный файл
59
unittest/unittest.depend
Обычный файл
@@ -0,0 +1,59 @@
|
|||||||
|
# depslib dependency file v1.0
|
||||||
|
1748213255 source:c:\users\home\desktop\lab34\laba01\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
|
||||||
|
1748213210 c:\users\home\desktop\lab34\laba01\histogram.h
|
||||||
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
1748213127 source:c:\users\home\desktop\lab34\laba01\unittest.cpp
|
||||||
|
"doctest.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
|
||||||
|
1748211324 c:\users\home\desktop\lab34\laba01\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>
|
||||||
|
|
||||||
|
1748213259 c:\users\home\desktop\lab34\laba01\histogram_internal.h
|
||||||
|
|
||||||
Ссылка в новой задаче
Block a user