code: Добавил тест для своего варианта (забыл раньше)

master
Nikita (PodolskyNK) 11 месяцев назад
Родитель 79bcc8abbb
Сommit f4847a9a14

@ -32,6 +32,7 @@
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="doctest.h" />
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h">
<Option target="&lt;{~None~}&gt;" />
@ -44,6 +45,9 @@
<Unit filename="svg.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="svgg.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="text.cpp" />
<Unit filename="text.h">
<Option target="&lt;{~None~}&gt;" />

@ -11,11 +11,11 @@ const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10;
double ask_width(size_t numbers_count) {
double ask_width(size_t numbers_count, std::istream& input) {
while (true) {
double width;
cout << "Enter width ";
cin >> width;
cerr << "Write width ";
input >> width;
if (width < 70) {
cout << "Try again. It's too low.\n";
} else if (width > 800) {
@ -50,7 +50,7 @@ void svg_rect(double x, double y, double width, double height, string stroke = "
}
void show_histogram_svg(const vector<size_t>& bins) {
const auto IMAGE_WIDTH = ask_width(bins.size());
const auto IMAGE_WIDTH = ask_width(bins.size(), cin);
const auto MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH;
size_t max_count = 0;
for (size_t count : bins) {

@ -0,0 +1,7 @@
#ifndef SVGG_H_INCLUDED
#define SVGG_H_INCLUDED
double ask_width(size_t numbers_count);
#endif // SVGG_H_INCLUDED

@ -31,9 +31,6 @@
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="doctest.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="histogram.cpp" />
<Unit filename="histogram_internal.h" />
<Unit filename="unittest.cpp" />

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="unittest2" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/unittest2" 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/unittest2" 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>
<Unit filename="svg.cpp" />
<Unit filename="svg.h" />
<Unit filename="svgg.h" />
<Unit filename="unittest2.cpp" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

@ -0,0 +1,10 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include <iostream>
double ask_width(size_t numbers_count, std::istream& in);
TEST_CASE("ask_width returns correct width") {
std::istringstream test_input("800\n");
CHECK(ask_width(10, test_input) == 800);
}
Загрузка…
Отмена
Сохранить