Skip to content
Snippets Groups Projects
Unverified Commit c5264763 authored by Stauder, Lucas's avatar Stauder, Lucas
Browse files

Initial Upload

parents
No related branches found
No related tags found
No related merge requests found
# CLion
/.idea
/*-build-*
# Visual Studio
/.vs
/out
# vscode
/.vscode
/build
cmake_minimum_required(VERSION 3.26)
project(Uebung6)
set(CMAKE_CXX_STANDARD 14)
add_executable(Uebung6 src/main.cpp
src/outliers.h
src/outliers.cpp
src/statistics.cpp
src/statistics.h)
# Fetch Catch2
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
)
FetchContent_MakeAvailable(Catch2)
enable_testing()
add_executable(test_outliers
src/outliers.h
src/outliers.cpp
src/outliers.test.cpp
)
add_executable(test_statistics
src/statistics.cpp
src/statistics.h
src/statistics.test.cpp
)
add_executable(test_histogram
src/histogram.cpp
src/histogram.h
src/histogram.test.cpp
)
target_link_libraries(test_outliers PRIVATE Catch2::Catch2WithMain)
target_link_libraries(test_statistics PRIVATE Catch2::Catch2WithMain)
target_link_libraries(test_histogram PRIVATE Catch2::Catch2WithMain)
target_include_directories(test_outliers PRIVATE src/)
target_include_directories(test_statistics PRIVATE src/)
target_include_directories(test_histogram PRIVATE src/)
add_test(test_outliers ./test_outliers)
add_test(test_statistics ./test_statistics)
add_test(test_histogram ./test_histogram)
set_property(TEST test_outliers PROPERTY ENVIRONMENT "CTEST_OUTPUT_ON_FAILURE=1")
set_property(TEST test_statistics PROPERTY ENVIRONMENT "CTEST_OUTPUT_ON_FAILURE=1")
set_property(TEST test_histogram PROPERTY ENVIRONMENT "CTEST_OUTPUT_ON_FAILURE=1")
#include "histogram.h"
#include <algorithm>
#include <unordered_map>
int getMostFrequentValue(const std::vector<int>& data) {
return 0;
}
#ifndef HISTOGRAM_H
#define HISTOGRAM_H
#include <vector>
int getMostFrequentValue(const std::vector<int>& data);
#endif // HISTOGRAM_H
#include "histogram.h"
#include <catch2/catch_test_macros.hpp>
TEST_CASE("getMostFrequentValue") {
REQUIRE(getMostFrequentValue({1, 2, 2, 3}) == 2);
REQUIRE(getMostFrequentValue({10}) == 10);
REQUIRE(getMostFrequentValue(
{1, 2, 2, 2, 3, 3, 1, 3, 2, 8, 32, 1, 3, 1, 2, 4, 3, 2, 3, 3, 3}) == 3);
const int mfv = getMostFrequentValue({1, 2, 2, 3, 3});
const bool correct = (mfv == 2) || (mfv == 3);
REQUIRE(correct);
}
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
#include "outliers.h"
double findNMin(const std::vector<double>& data, size_t n) {
return 0;
}
double findNMax(const std::vector<double>& data, size_t n) {
return 0.0;
}
std::vector<double> removeOutliers(std::vector<double> data, size_t n) {
return {};
}
#ifndef UEBUNG5_OUTLIERS_H
#define UEBUNG5_OUTLIERS_H
#include <cstddef>
#include <vector>
double findNMin(const std::vector<double>& data, size_t n);
double findNMax(const std::vector<double>& data, size_t n);
std::vector<double> removeOutliers(std::vector<double> data, size_t n);
#endif // UEBUNG5_OUTLIERS_H
#include "outliers.h"
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_vector.hpp>
void allElementsInVector(std::vector<double> test, std::vector<double> correct) {
REQUIRE(test.size() == correct.size());
std::sort(test.begin(), test.end());
for (int i = 0; i < correct.size(); ++i) {
CHECK(test[i] == correct[i]);
}
}
TEST_CASE("findNMin") {
const std::vector<double> data = {
1, 2, 3, 4, 5,
};
REQUIRE(findNMin(data, 1) == 1);
REQUIRE(findNMin(data, 2) == 2);
REQUIRE(findNMin(data, 5) == 5);
const std::vector<double> data2 = {
4, 2, 1, 2, 3,
};
REQUIRE(findNMin(data2, 1) == 1);
REQUIRE(findNMin(data2, 2) == 2);
REQUIRE(findNMin(data2, 5) == 4);
}
TEST_CASE("findNMax") {
const std::vector<double> data = {
1, 2, 3, 4, 5,
};
REQUIRE(findNMax(data, 1) == 5);
REQUIRE(findNMax(data, 2) == 4);
REQUIRE(findNMax(data, 5) == 1);
const std::vector<double> data2 = {
4, 2, 1, 2, 3,
};
REQUIRE(findNMax(data2, 1) == 4);
REQUIRE(findNMax(data2, 2) == 3);
REQUIRE(findNMax(data2, 5) == 1);
}
TEST_CASE("removeOutliers") {
std::vector<double> data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
std::vector<double> data2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 30,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
std::vector<double> correct = {0, 0, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 18, 18};
std::vector<double> correct2 = {0, 0, 3, 4, 5, 6, 7, 8, 9, 9,
11, 12, 13, 14, 15, 16, 17, 18, 19, 19};
allElementsInVector(removeOutliers(data, 2), correct);
allElementsInVector(removeOutliers(data2, 2), correct2);
}
#include "statistics.h"
#include <algorithm>
#include <numeric>
size_t countValuesNearMean(const std::vector<double>& data) { return 0; }
#ifndef STATISTICS_H
#define STATISTICS_H
#include <cstddef>
#include <vector>
size_t countValuesNearMean(const std::vector<double>& data);
#endif // STATISTICS_H
#include "statistics.h"
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_vector.hpp>
TEST_CASE("countValuesNearMean") {
REQUIRE(countValuesNearMean({1, 2, 3}) == 1);
REQUIRE(countValuesNearMean({2, 3, 2, 1}) == 2);
REQUIRE(countValuesNearMean({1, 4, 2, 3}) == 0);
REQUIRE(countValuesNearMean({2.5, 2.5, 1, 4, 2, 3, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5}) == 9);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment