/*
* Unit Test Bootstrap
* Autor: Tomasz Jaworski, 2018-2019
*
* Test dla zadania Histogram
* Autor testowanej odpowiedzi: Szymon Ptak
* Test wygenerowano automatycznie o 2019-08-22 14:37:49.671300
*
* Debug:
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <signal.h>
#include <setjmp.h>
#include <assert.h>
#define _RLDEBUG_API_
#include "unit_helper_v2.h"
#include "rdebug.h"
#include "tested_declarations.h"
#include "rdebug.h"
//
// Elementy globalne dla całego testu
//
//
// Test 1: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST1(void)
{
// informacje o teście
test_start(1, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {1, 1, 0, 3, 0, 0, 1, 1, 1, 2, 0};
int output[] = {-1, 2, 2, 0, 0, 2, -1, -2, 2, -2, -1};
printf("#####START#####");
int res = create_histogram((float[]){9.518692, 3.443866, 7.055154, 8.458204, 9.907916, 3.000328, 0.594705, 3.191147, 6.547804, 1.098704}, 10, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [1, 1, 0, 3, 0, 0, 1, 1, 1, 2, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 2: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST2(void)
{
// informacje o teście
test_start(2, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {6, 9, 5, 5, 3, 7, 9, 12, 6, 9, 10};
int output[] = {2, -1, 1, 0, -2, -1, 0, 0, 0, 0, 1};
printf("#####START#####");
int res = create_histogram((float[]){5.413925, 1.781544, 4.391522, 8.531974, 3.513799, 7.091066, 2.580160, 0.483282, 5.937148, 9.745676, 7.438524, 9.127770, 9.412598, 2.713236, 6.573285, 7.652658, 6.319721, 1.790424, 9.166389, 2.310211, 3.518089, 6.569487, 10.834342, 6.514268, 7.109804, 3.078378, 5.026966, 0.110734, 10.863506, 10.911295, 8.755959, 6.515508, 7.223319, 7.336721, 9.623288, 3.722459, 0.941431, 10.376163, 4.905137, 5.821361, 7.022242, 10.608939, 8.842693, 1.985088, 0.552247, 5.734786, 7.454968, 2.127497, 1.983933, 9.325905, 9.508216, 6.056632, 4.693447, 6.773652, 3.257261, 9.701057, 0.746508, 1.595327, 8.796712, 8.173345, 0.142486, 10.077515, 5.033130, 7.989790, 9.333579, 6.105485, 10.556338, 7.572498, 1.496999, 10.216882, 2.504094, 1.908084, 6.329690, 7.868914, 10.696092, 1.582104, 1.148494, 5.450443, 7.849730, 10.025431, 8.069710}, 81, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [6, 9, 5, 5, 3, 7, 9, 12, 6, 9, 10]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 3: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST3(void)
{
// informacje o teście
test_start(3, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {11, 4, 12, 7, 5, 10, 11, 11, 7, 10, 17};
int output[] = {0, -2, 1, -1, 1, -1, 1, 1, 0, -1, 1};
printf("#####START#####");
int res = create_histogram((float[]){2.993562, 9.653282, 5.305054, 5.774185, 0.965892, 10.931455, 10.558178, 6.258653, 2.486685, 8.546137, 8.071327, 0.322811, 10.715595, 10.695556, 2.591549, 0.335486, 9.115608, 10.553500, 10.630196, 9.856680, 0.110971, 7.753857, 5.389701, 9.325155, 0.822377, 10.372576, 5.083610, 3.881286, 3.508405, 10.903254, 1.367710, 4.790432, 7.868460, 3.412780, 6.898885, 9.900079, 8.133178, 6.714273, 2.728648, 4.995104, 7.553316, 7.197624, 5.228690, 4.853426, 2.294693, 3.437410, 7.457044, 6.766042, 5.215847, 6.134510, 4.926558, 9.027551, 2.761660, 1.164692, 5.427750, 7.358987, 0.491766, 6.026190, 0.649519, 8.204221, 10.556852, 7.651743, 4.653247, 7.339836, 8.414270, 6.737497, 2.950492, 6.365283, 3.206814, 0.325479, 9.853050, 3.711715, 2.772476, 0.041999, 2.938364, 10.961920, 7.056081, 10.788795, 5.658772, 1.923286, 5.554826, 2.369291, 7.259197, 0.401352, 0.374847, 10.077305, 8.217501, 7.268485, 10.672332, 9.265966, 10.429056, 2.651902, 6.316908, 1.138707, 8.369756, 6.538496, 5.883746, 9.294028, 10.157844, 9.207683, 6.856499, 10.981996, 2.434623, 10.104568, 3.750732}, 105, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [11, 4, 12, 7, 5, 10, 11, 11, 7, 10, 17]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 4: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST4(void)
{
// informacje o teście
test_start(4, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0};
int output[] = {-2, -1, -1, 0, 2, 1, 2, -1, 2, -1, -2};
printf("#####START#####");
int res = create_histogram((float[]){9.600186, -1.216536, -2.912441, 7.118444, 6.258671, -4.779145}, 6, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 5: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST5(void)
{
// informacje o teście
test_start(5, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {4, 3, 5, 3, 3, 7, 5, 3, 6, 6, 0};
int output[] = {1, -1, 0, 2, -1, -1, 0, 1, 1, -2, -2};
printf("#####START#####");
int res = create_histogram((float[]){7.816867, 8.537161, -3.757584, -5.095287, 5.173758, -3.325508, -6.167335, -2.263289, 4.683312, 8.510949, -6.575628, -4.454925, -7.625356, 9.612091, -7.476779, 9.558728, -7.153574, -4.099735, -9.257369, -3.026189, 4.614883, -8.323259, 5.244349, -1.967544, 1.404351, 9.357274, -6.522116, -4.174161, -8.161105, -3.215861, -9.592720, -7.795013, 3.642323, 9.394539, -9.779225, -7.941569, 1.139510, 8.768603, 7.444392, -5.681962, 5.642943, 6.413727, 2.540143, -1.223242, -3.695068, -2.264731, 5.015518, 4.947787, 0.784136, 5.436879, 9.433930, 2.885807, -4.903352, -1.963367, 0.725673, 1.913030, 3.076752, -7.610032, 0.212862, -7.206737, -8.575655, 6.996612, -0.341640, -0.423295, 6.221285, -0.114614, 0.261348, 2.116228, 3.269305, -0.915676, -2.917884, -9.120155, -4.692460, -1.691823, 2.916951, -6.378957, -4.267648, -0.044909, 8.078735, -5.137032, -8.378810, -7.602026, 8.043313, -4.384670, 8.645689, 5.217950, -8.925460, -6.725657, 7.153709, 5.962187, 2.970383, -5.353988, -3.178021, -4.530008, -5.857679, 6.708484, -1.471926, 9.097917, 6.521947}, 99, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [4, 3, 5, 3, 3, 7, 5, 3, 6, 6, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 6: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST6(void)
{
// informacje o teście
test_start(6, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {5, 2, 5, 1, 1, 2, 3, 6, 0, 3, 4, 1, 1, 2, 5, 2, 3, 3, 3, 4, 0};
int output[] = {-2, -2, 1, -2, -2, 0, -1, -2, 0, 2, 1, 1, 0, 0, -2, 1, 1, 1, -1, 2, 2};
printf("#####START#####");
int res = create_histogram((float[]){12.953351, 14.593756, 13.136056, 10.290746, 1.091832, 2.555782, 18.506028, 7.933087, 14.587491, 10.312102, 6.187005, 17.829693, 13.488232, 9.697138, 5.401331, 17.467803, 7.537393, 16.784471, 0.722876, 6.646494, 19.545846, 14.014964, 2.137772, 14.412180, 0.885743, 1.141210, 2.828552, 16.569525, 15.819818, 0.349420, 6.312299, 7.452586, 19.486855, 19.241848, 15.469959, 0.945685, 7.872474, 0.817731, 18.010917, 2.596932, 11.658194, 7.795313, 10.110835, 4.381613, 10.775501, 5.527607, 14.662035, 19.143623, 2.317519, 9.730194, 16.519338, 9.051565, 3.730093, 18.673607, 7.534751, 17.530099}, 56, output, 21);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 21; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [5, 2, 5, 1, 1, 2, 3, 6, 0, 3, 4, 1, 1, 2, 5, 2, 3, 3, 3, 4, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 21; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 7: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST7(void)
{
// informacje o teście
test_start(7, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {7, 11, 11, 7, 11, 5, 10, 8, 10, 7, 11, 9, 10, 11, 11, 12, 15, 15, 10, 13, 11, 10, 7, 7, 12, 8, 15, 14, 8, 5, 11, 8, 18, 9, 6, 13, 11, 13, 9, 9, 15, 9, 10, 9, 12, 12, 10, 6, 14, 9, 5, 12, 8, 14, 4, 13, 13, 13, 11, 8, 7, 5, 10, 11, 9, 12, 8, 9, 9, 12, 17, 4, 13, 5, 8, 5, 8, 5, 13, 12, 11, 16, 11, 11, 10, 13, 8, 9, 9, 11, 12, 10, 6, 0};
int output[] = {-2, 2, 0, 1, 2, 0, 1, 0, -1, -2, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, 2, 1, -1, -2, 2, 0, -2, 0, 1, -2, 0, 0, 1, -1, -2, -2, -2, -1, -1, 2, 2, -2, 0, -1, -1, 1, 2, -2, 1, 2, -2, -1, -1, 2, 2, 1, 1, -1, -1, -2, 0, 2, 1, -2, -2, 2, -2, -2, 0, -1, 0, 0, 0, 2, -1, 2, 2, 0, 2, -2, 1, 0, 0, 0, 1, -2, -1, -2, -1, -2, 0, -2, -1, 0};
printf("#####START#####");
int res = create_histogram((float[]){30.730261, 53.510879, 23.467289, 68.522825, 41.453266, 73.236129, 90.873426, 26.348848, 6.210839, 18.760695, 74.014118, 3.300236, 29.644638, 87.657026, 47.157159, 69.587732, 3.281883, 88.028523, 43.778650, 88.785317, 7.730265, 33.305187, 58.337027, 11.640077, 81.348529, 35.225054, 42.791314, 9.589624, 20.530604, 31.297119, 55.345630, 26.172414, 15.841953, 72.198457, 2.706073, 9.815888, 14.416926, 69.457628, 21.666922, 56.650415, 0.725065, 85.703783, 8.971210, 21.943983, 23.272338, 35.463545, 18.431863, 13.333212, 78.924880, 45.476144, 89.652698, 17.256449, 13.001754, 32.010660, 90.935202, 90.354782, 19.621422, 35.946550, 14.319411, 64.690679, 59.841325, 27.712909, 8.063809, 9.749180, 28.457867, 17.157468, 31.702702, 30.968129, 15.199494, 57.985257, 9.968748, 27.249947, 37.413108, 67.272218, 69.113351, 27.962420, 42.198010, 45.556998, 35.155714, 30.608820, 90.081899, 56.359641, 34.355740, 30.346288, 8.561679, 53.870907, 56.557063, 86.617157, 24.093626, 46.995555, 18.804967, 53.440537, 91.042574, 39.757542, 27.377101, 34.284020, 46.652135, 61.256213, 78.834747, 53.012401, 27.071231, 48.249169, 3.672243, 82.023159, 13.967941, 23.143185, 1.183351, 19.049732, 17.710057, 16.024187, 40.156647, 77.645667, 7.510039, 65.716711, 47.649445, 2.340235, 34.596054, 83.363803, 68.796919, 42.244124, 18.845295, 42.476233, 64.357123, 66.437939, 62.722834, 25.120593, 70.922308, 15.717121, 59.285556, 16.319175, 44.664364, 19.122544, 49.842440, 53.125454, 75.319549, 21.804228, 12.449549, 67.672688, 40.922828, 58.371021, 78.806352, 81.194661, 86.905964, 35.113293, 78.995362, 13.066346, 36.066784, 18.191434, 74.721443, 88.557055, 12.243195, 61.683476, 82.189234, 14.925293, 57.073658, 79.267669, 36.515140, 81.096147, 28.930266, 39.004275, 85.711070, 19.424351, 67.260786, 26.514204, 44.085012, 42.223480, 52.312820, 28.030881, 26.707364, 44.723365, 30.575179, 56.015628, 32.549252, 39.084798, 12.812057, 84.004154, 61.347403, 30.060493, 1.980578, 40.820241, 89.482833, 91.714427, 65.548974, 18.761639, 73.090310, 44.609856, 11.759164, 13.729900, 60.777608, 47.181990, 25.957368, 84.887623, 83.706727, 74.951290, 11.514876, 49.370461, 37.144085, 7.364302, 63.711464, 5.921881, 66.189710, 31.230673, 39.047063, 10.664221, 57.363367, 70.909461, 85.364825, 48.748909, 83.688268, 48.837835, 72.988283, 56.396245, 39.139407, 48.244703, 79.711648, 82.146588, 27.407854, 90.216194, 47.384103, 32.433415, 47.665937, 39.349567, 51.192896, 21.180419, 21.785983, 73.322027, 6.756280, 62.117395, 13.325442, 32.845078, 69.530142, 27.687360, 21.995685, 3.803807, 55.935302, 2.788640, 16.543265, 18.907686, 69.444014, 84.062942, 19.961264, 78.290204, 11.308150, 81.887164, 14.868346, 72.506036, 1.650213, 15.244563, 29.762344, 44.575656, 37.950779, 0.374323, 53.360031, 89.310827, 82.976691, 48.630419, 75.244499, 83.689663, 87.882592, 7.217208, 20.567154, 65.224102, 26.056617, 58.047245, 67.837142, 22.925148, 92.118906, 62.266997, 20.540265, 14.633456, 0.453642, 4.517010, 75.510815, 78.177623, 40.137939, 88.362134, 30.037654, 16.279177, 48.185152, 20.639661, 14.251411, 45.836341, 17.513079, 28.708466, 72.535698, 48.633959, 92.287506, 9.228626, 73.717565, 1.149136, 23.531274, 18.630832, 6.526377, 15.689397, 44.506161, 79.111555, 80.284090, 84.356156, 2.193598, 16.343609, 7.694204, 86.423769, 27.273711, 32.435937, 37.763363, 41.263036, 70.898602, 22.868397, 55.289947, 20.496004, 79.330241, 81.583624, 81.927378, 40.612436, 62.330738, 5.053083, 62.389068, 13.824408, 59.559323, 70.534527, 70.124958, 22.542992, 50.594419, 51.736767, 35.622931, 24.602079, 89.099869, 59.428376, 17.619468, 89.288869, 55.055045, 16.669634, 38.454298, 15.080057, 19.828863, 72.363261, 57.927958, 53.965067, 34.494932, 24.534330, 45.666713, 55.507181, 63.284165, 65.995850, 45.991772, 17.490232, 22.896697, 91.835611, 79.377448, 10.141150, 74.342379, 32.564539, 31.264987, 37.688947, 74.685429, 85.805221, 38.525924, 75.570993, 35.856023, 70.777855, 12.243232, 76.231673, 45.973443, 72.408951, 4.649346, 67.628964, 32.707001, 26.277495, 76.696704, 78.076075, 53.432777, 28.255767, 32.184650, 25.345692, 58.507413, 57.013693, 40.490256, 26.844300, 61.746691, 30.394586, 24.633025, 42.106301, 26.477660, 49.317214, 72.634988, 44.038111, 82.748472, 35.789517, 79.278078, 66.440512, 59.314266, 32.836643, 35.021641, 74.084443, 14.169436, 17.725117, 70.960947, 70.835989, 20.929343, 40.851994, 63.380647, 90.836114, 70.332807, 17.043365, 90.656209, 39.346354, 87.532923, 32.695295, 86.564160, 68.055571, 92.180908, 16.197487, 86.181282, 6.003675, 32.518469, 49.556822, 41.497725, 92.699527, 27.448130, 19.770525, 63.992876, 51.662465, 44.683223, 62.420438, 53.644374, 1.662689, 91.993124, 38.235993, 77.663252, 18.961108, 21.893404, 17.799535, 87.551130, 46.437975, 28.635176, 31.885704, 21.108695, 17.216158, 80.746336, 24.095920, 8.735537, 57.923361, 6.113880, 51.100637, 51.553234, 6.686066, 2.963587, 85.643997, 38.124145, 65.960183, 86.650621, 17.181997, 49.535753, 8.820786, 84.089449, 80.467694, 91.857986, 26.898745, 43.833079, 50.104643, 14.895579, 85.069359, 2.198685, 80.484878, 64.939202, 81.927828, 16.257606, 68.835755, 90.941852, 20.782961, 12.082054, 86.295792, 32.734659, 35.813722, 65.685922, 46.706796, 30.874753, 35.331913, 4.034145, 8.828925, 55.702769, 75.522949, 88.293466, 36.284786, 64.112824, 76.970506, 31.475815, 50.356394, 37.817970, 33.238710, 22.901848, 76.278700, 26.094222, 53.048405, 83.396419, 15.894857, 19.930656, 69.587203, 66.258680, 32.387594, 65.654219, 81.698953, 51.639795, 53.291136, 68.027809, 19.288504, 35.935237, 25.421487, 23.619997, 46.171126, 36.857857, 36.730152, 56.224696, 48.111095, 10.543792, 92.646770, 91.099789, 22.314667, 76.122656, 7.553475, 1.241453, 68.086025, 33.954663, 67.003218, 33.359870, 80.970376, 71.295018, 40.489269, 77.670764, 70.376850, 54.387094, 48.003990, 36.896917, 51.631319, 48.298005, 2.586604, 81.168341, 10.933855, 90.887690, 46.761564, 70.889142, 60.695963, 43.783786, 85.785757, 76.269704, 42.960231, 70.453157, 55.525087, 58.726168, 68.997925, 34.780205, 11.511547, 64.025777, 2.720972, 40.773166, 81.220281, 36.082944, 60.708360, 33.470660, 48.457182, 39.809535, 53.659310, 38.039998, 36.777732, 38.079850, 10.357876, 66.696896, 40.805248, 4.975515, 4.265365, 32.222634, 0.625719, 58.970254, 88.278362, 66.496364, 13.198762, 55.783311, 90.163160, 24.584637, 70.317423, 57.054342, 16.120272, 34.163914, 62.855684, 85.048057, 33.486521, 45.622343, 85.315802, 79.471463, 67.605789, 89.863099, 33.485562, 65.228841, 65.325737, 37.959239, 41.368021, 89.702202, 64.825139, 79.191807, 14.473177, 72.401217, 72.360873, 46.901604, 23.813708, 0.739015, 24.877972, 30.714302, 69.676266, 87.165388, 83.077860, 63.119107, 57.230185, 25.144861, 39.558693, 2.366155, 65.778692, 25.035336, 58.889285, 60.722748, 1.478533, 83.027627, 42.305534, 27.444357, 63.771602, 13.424967, 16.519203, 27.769210, 38.117307, 85.337056, 89.203279, 40.909790, 15.320038, 4.246162, 52.925949, 90.394810, 52.749142, 43.132053, 72.305195, 64.960927, 81.088787, 31.589972, 41.144680, 20.432838, 81.017428, 18.053176, 76.841992, 41.573547, 4.169797, 11.660403, 56.495522, 80.774862, 91.781016, 13.704764, 82.972343, 12.105630, 69.448777, 40.115896, 69.867828, 32.428548, 3.543918, 47.213871, 12.984878, 12.134457, 43.293157, 15.982970, 35.633061, 36.927882, 83.363621, 83.806263, 55.387089, 77.673243, 26.479601, 6.892400, 40.666480, 84.461198, 55.235202, 85.656514, 24.526724, 53.543845, 17.094459, 16.965539, 52.648703, 88.198296, 8.856221, 26.664068, 17.979087, 57.637180, 13.885649, 63.285774, 82.978062, 84.757109, 33.525060, 25.982575, 81.864695, 10.706441, 12.208816, 69.681223, 87.823108, 63.687340, 90.084233, 59.857212, 16.468637, 37.631149, 56.112563, 72.834619, 67.156928, 83.776281, 19.620311, 58.046173, 40.214069, 62.912349, 1.114156, 45.544765, 17.255971, 3.673311, 57.183414, 0.026044, 8.118003, 52.472655, 57.420756, 85.211987, 70.058740, 88.529237, 71.782763, 45.832441, 2.106454, 74.865987, 21.605628, 37.412750, 54.574605, 78.071014, 46.549858, 78.200675, 80.026055, 58.304374, 9.562694, 88.633528, 20.066691, 56.274376, 27.851003, 32.563176, 51.024874, 11.560536, 10.883713, 5.215616, 20.020110, 56.173640, 16.261876, 54.345847, 10.803340, 43.355178, 83.275302, 55.010824, 79.573958, 32.572323, 91.622013, 28.345402, 55.311819, 26.754334, 81.887917, 89.949628, 72.694078, 71.258629, 87.534439, 60.866597, 82.113705, 48.920546, 43.460730, 82.471282, 29.702197, 49.538853, 14.780880, 8.768895, 37.268396, 82.187666, 12.465421, 5.827211, 38.264673, 25.846095, 32.857341, 1.345977, 66.432246, 19.479402, 58.680534, 85.594150, 74.143757, 44.576152, 57.601986, 29.175996, 87.042260, 24.828425, 48.009262, 44.907951, 71.877054, 44.774942, 80.818090, 46.462605, 65.925138, 16.929631, 21.288118, 37.237836, 6.457052, 80.265002, 41.605624, 70.550553, 37.184531, 24.228718, 51.918544, 11.263548, 91.992361, 4.892342, 70.552570, 36.552987, 50.936874, 56.997601, 64.351611, 78.689361, 24.471606, 65.750677, 51.831816, 19.566874, 31.916048, 10.779330, 16.959461, 30.725320, 66.733151, 44.746228, 9.353776, 77.208711, 54.740131, 51.034250, 17.184366, 51.228073, 84.152139, 26.137525, 43.450504, 11.991973, 79.912554, 43.339276, 57.130391, 89.327027, 22.285294, 28.218665, 63.653764, 41.068477, 80.176668, 19.036442, 49.641830, 58.883910, 5.889121, 46.478230, 4.715838, 41.600364, 62.174735, 80.242051, 87.239796, 4.577940, 33.701093, 78.420106, 76.323418, 38.941524, 86.479622, 73.109127, 6.586144, 92.668417, 72.514057, 23.695634, 27.104893, 56.468371, 59.781776, 2.452284, 79.751571, 0.903151, 50.930791, 45.271856, 68.535052, 69.639147, 10.947566, 27.157496, 42.587925, 89.631437, 20.929190, 81.491135, 4.382433, 64.139312, 63.088710, 1.861165, 62.464164, 1.594774, 15.325242, 60.248629, 56.271195, 67.187908, 45.086298, 63.443066, 78.759621, 7.600123, 68.948734, 52.812867, 82.130012, 8.724080, 69.604899, 59.191684, 60.358335, 84.170595, 24.694776, 15.864386, 26.731560, 36.203203, 78.520849, 6.310243, 3.689783, 49.639875, 52.089281, 40.596305, 42.015080, 70.518063, 52.319808, 37.723167, 84.243184, 81.979442, 53.096799, 45.759153, 15.138805, 79.774749, 14.900225, 91.476408, 61.822979, 48.302258, 10.772839, 55.995338, 7.494611, 29.916436, 49.170269}, 934, output, 94);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 94; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [7, 11, 11, 7, 11, 5, 10, 8, 10, 7, 11, 9, 10, 11, 11, 12, 15, 15, 10, 13, 11, 10, 7, 7, 12, 8, 15, 14, 8, 5, 11, 8, 18, 9, 6, 13, 11, 13, 9, 9, 15, 9, 10, 9, 12, 12, 10, 6, 14, 9, 5, 12, 8, 14, 4, 13, 13, 13, 11, 8, 7, 5, 10, 11, 9, 12, 8, 9, 9, 12, 17, 4, 13, 5, 8, 5, 8, 5, 13, 12, 11, 16, 11, 11, 10, 13, 8, 9, 9, 11, 12, 10, 6, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 94; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 8: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST8(void)
{
// informacje o teście
test_start(8, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {5, 2, 1, 5, 2, 2, 3, 3, 2};
int output[] = {-1, 2, -2, 1, 1, 2, 1, -2, -1};
printf("#####START#####");
int res = create_histogram((float[]){6.267626, 0.920600, 7.890004, 3.468204, 6.523170, 3.942619, 8.543707, 9.945534, 9.973365, 3.362877, 8.957166, 5.152096, 5.963124, 2.810810, 0.308426, 6.528250, 0.607573, 3.652873, 0.239573, 10.853127, 4.585116, 7.577382, 9.989480, 7.113094, 0.261081, 3.327232, 1.467148, 4.980877, 1.090338}, 29, output, 9);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 9; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [5, 2, 1, 5, 2, 2, 3, 3, 2]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 9; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 9: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST9(void)
{
// informacje o teście
test_start(9, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0};
int output[] = {1, 0, 2, 2, 1, 1, 0, 2, 2, 1, -2};
printf("#####START#####");
int res = create_histogram((float[]){4.065648}, 1, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 10: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST10(void)
{
// informacje o teście
test_start(10, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {10};
int output[] = {-2};
printf("#####START#####");
int res = create_histogram((float[]){9.840667, 1.762895, 7.241409, 6.065265, 0.685269, 8.946456, 1.988750, 1.327738, 3.337296, 8.260178, 4.984220, 8.763312, 9.603732, 8.473311, 3.589084, 3.394032, 4.830384, 7.631678, 0.055899, 3.067883, 0.895901, 10.866677, 4.531092, 2.714100, 7.336863, 9.916604, 3.566498, 2.370017, 5.802211, 5.124355, 4.850031, 7.521245, 8.497306, 10.889861, 7.766846, 3.126986, 8.542199, 1.903103, 8.620445, 8.413615, 7.552398, 2.625610, 5.517776, 9.166106, 8.048858, 7.226476, 7.625273, 5.260171, 10.856382, 7.870323, 8.114873, 2.936199, 1.114882, 6.421509, 3.791269, 10.265241, 0.941640, 0.704292, 1.692216, 3.741130, 0.931978, 9.015668, 9.609450, 2.875016, 5.082252, 0.357869, 0.552557, 1.780653, 4.292532, 6.989825, 2.689366, 9.340729, 10.551343, 5.355138, 3.965824, 3.597987, 5.148740, 7.407245, 3.052289, 5.489183, 0.268132, 8.733403, 8.029769, 6.793260, 0.884565, 7.395179, 10.294673, 1.199204, 2.787339, 8.101105, 8.466817, 8.254397, 7.411833, 3.891045, 1.280279, 6.661815, 4.682573, 4.141517, 7.202771}, 99, output, 1);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 1; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [10]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 1; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 11: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST11(void)
{
// informacje o teście
test_start(11, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
printf("#####START#####");
int res = create_histogram((float[]){9.518692, 3.443866, 7.055154, 8.458204, 9.907916, 3.000328, 0.594705, 3.191147, 6.547804, 1.098704}, 15, NULL, 12);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 12: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST12(void)
{
// informacje o teście
test_start(12, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {2, 2, 2, 2, 0, -1, 1, 0, 2, 0, 0};
printf("#####START#####");
int res = create_histogram(NULL, 11, output, 20);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 13: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST13(void)
{
// informacje o teście
test_start(13, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {2, 2, 2, 2, 0, -1, 1, 0, 2, 0, 0};
printf("#####START#####");
int res = create_histogram((float[]){9.518692, 3.443866, 7.055154, 8.458204, 9.907916, 3.000328, 0.594705, 3.191147, 6.547804, 1.098704}, 0, output, 17);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 14: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST14(void)
{
// informacje o teście
test_start(14, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {2, 2, 2, 2, 0, -1, 1, 0, 2, 0, 0};
printf("#####START#####");
int res = create_histogram((float[]){9.518692, 3.443866, 7.055154, 8.458204, 9.907916, 3.000328, 0.594705, 3.191147, 6.547804, 1.098704}, 16, output, 0);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 15: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST15(void)
{
// informacje o teście
test_start(15, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {2, 2, 2, 2, 0, -1, 1, 0, 2, 0, 0};
printf("#####START#####");
int res = create_histogram((float[]){9.518692, 3.443866, 7.055154, 8.458204, 9.907916, 3.000328, 0.594705, 3.191147, 6.547804, 1.098704}, -15, output, 17);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 16: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST16(void)
{
// informacje o teście
test_start(16, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {2, 2, 2, 2, 0, -1, 1, 0, 2, 0, 0};
printf("#####START#####");
int res = create_histogram((float[]){9.518692, 3.443866, 7.055154, 8.458204, 9.907916, 3.000328, 0.594705, 3.191147, 6.547804, 1.098704}, 19, output, -13);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 17: Sprawdzanie poprawności działania funkcji display
//
void UTEST17(void)
{
// informacje o teście
test_start(17, "Sprawdzanie poprawności działania funkcji display", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int tab[] = {0, 1, -1, 3, -7, 0, -4};
//-------------1-----------------------
printf("\n***TEST 1***\n\n");
printf("***START***\n");
display_vector(tab, 0);
printf("***END***\n");
//-------------2-----------------------
printf("\n***TEST 2***\n\n");
printf("***START***\n");
display_vector(tab, -7);
printf("***END***\n");
//-------------3-----------------------
printf("\n***TEST 3***\n\n");
printf("***START***\n");
display_vector(tab, 7);
printf("***END***\n");
//-------------4-----------------------
printf("\n***TEST 4***\n\n");
printf("***START***\n");
display_vector(tab, 7 - 1);
printf("***END***\n");
onerror_terminate(); // przerwanie wszystkich testów jednostkowych (np. coś jest mocno nie tak z kodem)
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 18: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST18(void)
{
// informacje o teście
test_start(18, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 9;
const float expected_array[] = {-9.000000, 7.000000, 9.000000, 10.000000, -9.000000, 1.000000, -3.000000, 8.000000, 8.000000, 0.000000};
float dest[10];
int result = read_vector_float(dest, 10, 0);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [-9.000000, 7.000000, 9.000000, 10.000000, -9.000000, 1.000000, -3.000000, 8.000000, 8.000000, 0.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 19: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST19(void)
{
// informacje o teście
test_start(19, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 10;
const float expected_array[] = {-9.000000, -5.000000, -3.000000, 0.000000, 8.000000, -1.000000, 6.000000, 2.000000, 7.000000, 6.000000, -10.000000};
float dest[11];
int result = read_vector_float(dest, 11, -10);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [-9.000000, -5.000000, -3.000000, 0.000000, 8.000000, -1.000000, 6.000000, 2.000000, 7.000000, 6.000000, -10.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 20: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST20(void)
{
// informacje o teście
test_start(20, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 0;
const float expected_array[] = {0.000000};
float dest[5];
int result = read_vector_float(dest, 5, 0);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [0.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 21: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST21(void)
{
// informacje o teście
test_start(21, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 4;
const float expected_array[] = {-7.000000, 0.000000, -3.000000, -5.000000};
float dest[4];
int result = read_vector_float(dest, 4, -10);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [-7.000000, 0.000000, -3.000000, -5.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 22: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST22(void)
{
// informacje o teście
test_start(22, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int expected_result = -1;
float dest[5];
printf("#####START#####");
int result = read_vector_float(dest, 0, 5);
printf("#####END#####");
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 23: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST23(void)
{
// informacje o teście
test_start(23, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int expected_result = -1;
float dest[6];
printf("#####START#####");
int result = read_vector_float(dest, -8, -9);
printf("#####END#####");
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 24: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST24(void)
{
// informacje o teście
test_start(24, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int expected_result = -1;
printf("#####START#####");
int result = read_vector_float(NULL, -3, 2);
printf("#####END#####");
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
enum run_mode_t { rm_normal_with_rld = 0, rm_unit_test = 1, rm_main_test = 2 };
int __wrap_main(volatile int _argc, char** _argv, char** _envp)
{
int volatile vargc = _argc;
char ** volatile vargv = _argv, ** volatile venvp = _envp;
volatile enum run_mode_t run_mode = rm_unit_test; // -1
volatile int selected_test = -1;
if (vargc > 1)
{
char* smode = strtok(vargv[1], ",");
char* stest = strtok(NULL, "");
char *errptr = NULL;
run_mode = (enum run_mode_t)strtol(smode, &errptr, 10);
if (*errptr == '\x0')
{
memmove(vargv + 1, vargv + 2, sizeof(char*) * (vargc - 1));
vargc--;
if (stest != NULL)
{
int val = (int)strtol(stest, &errptr, 10);
if (*errptr == '\x0')
selected_test = val;
}
}
}
// printf("runmode=%d; selected_test=%d\n", run_mode, selected_test);
// inicjuj testy jednostkowe
unit_test_init(run_mode, "unit_test_v2.c");
test_limit_init();
rldebug_set_reported_severity_level(MSL_FAILURE);
if (run_mode == rm_normal_with_rld)
{
// konfiguracja ograniczników
rldebug_reset_limits();
// uruchom funkcję main Studenta a potem wyświetl podsumowanie sterty i zasobów
volatile int ret_code = rdebug_call_main(tested_main, vargc, vargv, venvp);
rldebug_reset_limits();
int leaks_detected = rldebug_show_leaked_resources(0);
if (leaks_detected)
raise(SIGHEAP);
return ret_code;
}
if (run_mode == rm_unit_test)
{
test_title("Testy jednostkowe");
void (*pfcn[])(void) =
{
UTEST1, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST2, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST3, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST4, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST5, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST6, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST7, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST8, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST9, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST10, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST11, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST12, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST13, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST14, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST15, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST16, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST17, // Sprawdzanie poprawności działania funkcji display
UTEST18, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST19, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST20, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST21, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST22, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST23, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST24, // Sprawdzanie poprawności działania funkcji read_vector_float
NULL
};
for (int idx = 0; pfcn[idx] != NULL && !test_get_session_termination_flag(); idx++)
{
if (selected_test == -1 || selected_test == idx + 1)
pfcn[idx]();
// limit niezaliczonych testów, po jakim testy jednostkowe zostaną przerwane
if (test_session_get_fail_count() >= 1000)
test_terminate_session();
}
test_title("RLDebug :: Analiza wycieku zasobów");
// sprawdź wycieki pamięci
int leaks_detected = rldebug_show_leaked_resources(1);
test_set_session_leaks(leaks_detected);
// poinformuj serwer Mrówka o wyniku testu - podsumowanie
test_title("Podsumowanie");
if (selected_test == -1)
test_summary(24); // wszystkie testy muszą zakończyć się sukcesem
else
test_summary(1); // tylko jeden (selected_test) test musi zakończyć się sukcesem
return EXIT_SUCCESS;
}
if (run_mode == rm_main_test)
{
test_title("Testy funkcji main()");
void (*pfcn[])(int, char**, char**) =
{
NULL
};
for (volatile int idx = 0; pfcn[idx] != NULL && !test_get_session_termination_flag(); idx++)
{
if (selected_test == -1 || selected_test == idx + 1)
pfcn[idx](vargc, vargv, venvp);
// limit niezaliczonych testów, po jakim testy jednostkowe zostaną przerwane
if (test_session_get_fail_count() >= 1000)
test_terminate_session();
}
test_title("RLDebug :: Analiza wycieku zasobów");
// sprawdź wycieki pamięci
int leaks_detected = rldebug_show_leaked_resources(1);
test_set_session_leaks(leaks_detected);
// poinformuj serwer Mrówka o wyniku testu - podsumowanie
test_title("Podsumowanie");
if (selected_test == -1)
test_summary(0); // wszystkie testy muszą zakończyć się sukcesem
else
test_summary(1); // tylko jeden (selected_test) test musi zakończyć się sukcesem
return EXIT_SUCCESS;
}
printf("*** Nieznana wartość RunMode: %d", (int)run_mode);
abort();
}