/*
* Unit Test Bootstrap
* Autor: Tomasz Jaworski, 2018-2019
*
* Test dla zadania Histogram
* Autor testowanej odpowiedzi: Szymon Ptak
* Test wygenerowano automatycznie o 2019-08-22 17:13:20.884104
*
* 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[] = {0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0};
int output[] = {2, 0, 1, 1, 2, -2, 0, 0, -2, 2, 0};
printf("#####START#####");
int res = create_histogram((float[]){7.467645, 3.104686, 6.894945, 2.566461}, 4, 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, 1, 1, 0, 0, 1, 1, 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 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[] = {5, 1, 3, 5, 7, 4, 2, 5, 4, 3, 3};
int output[] = {-1, 2, 2, 1, 2, -2, 1, -1, 0, 0, -1};
printf("#####START#####");
int res = create_histogram((float[]){9.561736, 9.325244, 8.788509, 2.100351, 1.301279, 8.667767, 5.572169, 4.238272, 7.981320, 7.154015, 10.001077, 3.309487, 7.103877, 5.822750, 4.994128, 4.400840, 6.310126, 8.322299, 4.774805, 0.746730, 10.214200, 2.710772, 7.253408, 5.792805, 3.467123, 0.918764, 5.646182, 4.203716, 3.325520, 10.606115, 0.477626, 6.052676, 4.708029, 0.873366, 7.513798, 8.208096, 9.202218, 4.959688, 3.204193, 3.379666, 0.035879, 2.324809}, 42, 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ć: [5, 1, 3, 5, 7, 4, 2, 5, 4, 3, 3]\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[] = {15, 14, 21, 13, 13, 7, 17, 11, 18, 12, 11};
int output[] = {0, -1, -2, 1, -1, -2, -1, 1, -2, -2, -1};
printf("#####START#####");
int res = create_histogram((float[]){8.173692, 8.090454, 10.912724, 4.529658, 9.995132, 2.344298, 2.519891, 2.474320, 2.089592, 4.534898, 5.342681, 1.335393, 8.584957, 10.422011, 6.620871, 1.815773, 3.598454, 0.643319, 8.511297, 7.674073, 9.838337, 2.729648, 0.060824, 0.604692, 10.065699, 6.202599, 0.671656, 3.335721, 1.445754, 6.858761, 9.601085, 2.163501, 3.394622, 7.496201, 3.207922, 4.350371, 8.870467, 0.713747, 3.660546, 5.792761, 1.772795, 7.356959, 1.732958, 8.385430, 0.804104, 5.376394, 6.670978, 8.168495, 1.001548, 9.274722, 2.523630, 8.545222, 1.970479, 1.753039, 2.241349, 2.380185, 4.031771, 2.085879, 8.903663, 3.048135, 3.164327, 5.119996, 4.026007, 3.777910, 8.130414, 9.591543, 7.280847, 10.745865, 6.145462, 7.935532, 0.933151, 6.152545, 8.496684, 8.381309, 0.943716, 2.424665, 6.894946, 6.109120, 2.579108, 6.175912, 10.981318, 1.947453, 2.466361, 0.139685, 9.838403, 10.590234, 6.832821, 3.484541, 8.805099, 0.642392, 0.720753, 8.071442, 7.197143, 4.908743, 6.501377, 0.734165, 7.901023, 9.800186, 6.739701, 1.416597, 10.465377, 7.353883, 5.649041, 3.925082, 8.362413, 2.236609, 9.297314, 8.006780, 6.358291, 4.140304, 2.459394, 7.553426, 3.421981, 8.848887, 4.662651, 7.067125, 0.956699, 6.971496, 6.096299, 1.772322, 2.582008, 10.788318, 3.841527, 9.371940, 5.378606, 2.586890, 6.729394, 9.153392, 4.538014, 3.465017, 4.991764, 1.390527, 9.025949, 9.910861, 8.207035, 7.122285, 2.763028, 10.934036, 4.251505, 10.500247, 2.264466, 2.976033, 10.237580, 4.756996, 5.205602, 1.597203, 4.963764, 6.575091, 0.010908, 2.132539, 0.536872, 1.526307}, 152, 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ć: [15, 14, 21, 13, 13, 7, 17, 11, 18, 12, 11]\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, 2, 0, 1, 2, 1, 0, 0, 0, 0, 0};
int output[] = {-2, 2, 0, 2, 1, 1, 2, 2, -1, 1, -1};
printf("#####START#####");
int res = create_histogram((float[]){1.231457, -6.268379, 4.108892, 5.723638, -6.606287, 3.829347, 1.365029, -2.463039, 4.040416}, 9, 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, 2, 0, 1, 2, 1, 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 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[] = {7, 4, 2, 2, 5, 5, 2, 4, 9, 5, 0};
int output[] = {-2, 1, -2, 2, -1, -2, -1, 1, -2, -1, -1};
printf("#####START#####");
int res = create_histogram((float[]){7.747161, -7.225971, 0.356632, 8.398115, -5.524842, 5.085742, -6.749687, -4.690868, -6.769981, -1.963046, -6.591207, 7.350146, -1.147830, 3.335261, -2.883743, 7.569490, -2.279014, -8.236847, 0.526599, 2.274566, -6.099789, -9.224964, 0.703662, 0.975182, -9.750845, -1.758460, -7.589300, -3.269724, 4.305434, -6.286996, 4.648744, 6.860837, 0.093459, 0.478286, 8.044264, 1.725530, -5.580437, 9.107103, 1.418151, -5.124282, 6.285003, -7.745416, 9.261965, 4.368727, 9.897671, -1.443174, -5.765890, 8.173818, 1.999783, -5.039916, 8.605543, 2.092189, 7.069623, -2.775445, -4.720051, 3.568766, 5.180836, 5.026123, -8.369343, -0.788572, -1.568379, 8.161361, 4.437803, -5.629751, -9.194369, 8.594729, 5.833741, -1.836478, 0.101654, 9.752823, 5.251085, -0.827298, 1.637072, 9.566465, -2.980605, -9.853291, -3.562150, 8.470994, 8.926503, -7.733319, 8.685047, -0.839554, 4.855199, -6.952308, -9.186050}, 85, 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ć: [7, 4, 2, 2, 5, 5, 2, 4, 9, 5, 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[] = {3, 0, 2, 1, 7, 0, 1, 2, 1, 4, 3, 2, 4, 5, 2, 2, 4, 3, 2, 5, 0};
int output[] = {2, 2, 1, 2, -1, -2, 2, 1, -1, 1, 1, 1, 2, 2, 1, 0, -1, -2, 2, -2, 2};
printf("#####START#####");
int res = create_histogram((float[]){7.294794, 9.365689, 16.628049, 12.900130, 4.587314, 9.345611, 3.380155, 19.452573, 15.752991, 14.976789, 19.082179, 0.216768, 12.477091, 4.584029, 13.306917, 16.555898, 0.982868, 7.290286, 19.495953, 2.140060, 10.411075, 12.385434, 15.021480, 16.526043, 4.245579, 19.539129, 8.679148, 13.750929, 4.123085, 11.370596, 14.684089, 2.051191, 9.975534, 17.315127, 9.246538, 16.204720, 10.150798, 13.745686, 17.761864, 12.484315, 0.468827, 6.290115, 13.463855, 4.237805, 17.023773, 18.311598, 18.373491, 4.522480, 19.015926, 10.813353, 4.615459, 13.697627, 11.688577}, 53, 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ć: [3, 0, 2, 1, 7, 0, 1, 2, 1, 4, 3, 2, 4, 5, 2, 2, 4, 3, 2, 5, 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[] = {13, 9, 14, 15, 15, 14, 10, 17, 18, 14, 13, 23, 13, 22, 16, 12, 28, 10, 13, 26, 16, 24, 16, 14, 18, 18, 12, 14, 18, 10, 18, 19, 20, 13, 24, 16, 21, 13, 20, 18, 24, 15, 16, 15, 16, 12, 13, 18, 14, 16, 0};
int output[] = {-1, 2, 0, -2, -1, 0, -2, -1, 2, -2, -2, -2, -1, -2, -2, -2, 0, -1, 2, -1, 1, 1, -1, -1, 0, 2, -2, 2, 2, -1, 1, 0, 2, 0, -2, 0, 0, 0, 1, -2, -1, 2, 0, -2, -2, 2, -2, 0, -2, -2, 1};
printf("#####START#####");
int res = create_histogram((float[]){48.049487, 30.663985, 1.454112, 19.014148, 31.872973, 24.743353, 39.274565, 22.340509, 11.910314, 36.781017, 3.294498, 10.222760, 2.626073, 40.592318, 37.811307, 38.007729, 14.370554, 7.185511, 25.703161, 40.360645, 40.518670, 38.810129, 39.917102, 37.335869, 34.018637, 17.677618, 44.258500, 24.758511, 23.204347, 7.261234, 19.832760, 21.819511, 22.848653, 37.722773, 13.315726, 13.428247, 27.772454, 47.460934, 32.956649, 20.068773, 13.629238, 38.556345, 16.511245, 46.853251, 47.709253, 2.365776, 44.561623, 21.715279, 20.745143, 18.693413, 48.849225, 3.526551, 7.022652, 24.567994, 10.196884, 25.947968, 31.937807, 40.731425, 20.791348, 11.532491, 12.041227, 10.038476, 11.346910, 37.273351, 35.027381, 4.190671, 16.197287, 35.957094, 41.056502, 45.372522, 14.216576, 44.748536, 15.397800, 8.041097, 36.854745, 34.441097, 9.015975, 36.991515, 34.692899, 26.735198, 21.053280, 13.518561, 44.819056, 37.860413, 12.783861, 44.516803, 8.584941, 19.293939, 40.545872, 26.220242, 14.389638, 29.349085, 36.367271, 16.296508, 25.579385, 5.252283, 8.270082, 18.539513, 7.085411, 40.974102, 32.930830, 25.103189, 5.374543, 35.798054, 42.709253, 22.177676, 24.964942, 17.344448, 46.608524, 9.595198, 35.735602, 21.317165, 49.856539, 25.471997, 40.206888, 10.372404, 8.467084, 5.822941, 34.439908, 18.123734, 11.508976, 31.452763, 41.104709, 15.699328, 1.987943, 19.477021, 19.635619, 6.734333, 6.786164, 8.645342, 34.521019, 42.175569, 29.257842, 12.064953, 38.362198, 27.608271, 32.396786, 16.278121, 11.744081, 28.264450, 13.534310, 48.359317, 15.968503, 0.374798, 28.218849, 23.473618, 39.307905, 49.491780, 28.872234, 29.151487, 15.258079, 4.371115, 28.077617, 22.526588, 4.875334, 14.870062, 44.478746, 14.631943, 49.239129, 34.348911, 40.015318, 27.010396, 22.618805, 31.417529, 17.302177, 14.526878, 4.775705, 49.149024, 11.432917, 40.302345, 9.585497, 47.632111, 40.117897, 2.908704, 9.874086, 18.254351, 37.437774, 7.556030, 28.646246, 21.134432, 47.861266, 11.429436, 12.008785, 20.568400, 21.259618, 42.633023, 16.249479, 5.567221, 31.473286, 42.644653, 31.034269, 30.611641, 13.603607, 9.652879, 5.480529, 21.137203, 4.487539, 40.354523, 16.451578, 3.137802, 43.154260, 31.037438, 16.596722, 0.146831, 10.369474, 32.174051, 31.951280, 17.974556, 33.237014, 49.300462, 27.113881, 6.366280, 10.785603, 28.736401, 16.072635, 11.139199, 16.261472, 42.350483, 24.873297, 4.085769, 48.840227, 13.027793, 40.811874, 13.868434, 24.418129, 31.476642, 46.679321, 47.119007, 44.386002, 12.160766, 48.751959, 32.597279, 20.678736, 20.008237, 21.556216, 18.150936, 40.195690, 41.883615, 16.182268, 17.027889, 7.960716, 45.491000, 46.175999, 45.673008, 11.563880, 23.308057, 32.015692, 38.231845, 15.234357, 43.447605, 43.892229, 41.029707, 37.490055, 14.881842, 36.591504, 20.599151, 2.808379, 1.979360, 30.690310, 3.630333, 45.313676, 28.849328, 41.172059, 35.004514, 5.279753, 25.035203, 42.448411, 46.681576, 36.256924, 31.903475, 6.797331, 25.287710, 22.923419, 26.919088, 27.898832, 35.585232, 3.070711, 13.033225, 2.292143, 47.860090, 47.424272, 21.401417, 8.166921, 38.283540, 10.993991, 35.059598, 20.745315, 38.304675, 42.554101, 24.188122, 38.832388, 24.067769, 41.433031, 26.325357, 35.031278, 13.135680, 7.645495, 27.559660, 25.942526, 23.875847, 22.147495, 4.633898, 9.735197, 44.762658, 36.618526, 29.960756, 0.831279, 10.944394, 19.509660, 41.776251, 36.157187, 24.923070, 22.907479, 5.716383, 43.733240, 22.673388, 11.901122, 5.932226, 26.426987, 30.866548, 21.817570, 42.381606, 18.087643, 0.065777, 28.862910, 21.069604, 46.854986, 21.940109, 39.847049, 20.096052, 47.988199, 12.438318, 43.852589, 42.133868, 3.481733, 39.735985, 38.847944, 3.268677, 49.888682, 37.197917, 19.741842, 41.102631, 40.664422, 34.509190, 38.371821, 38.278558, 38.279452, 26.144883, 21.916455, 8.189325, 39.080990, 44.929796, 19.742653, 28.108642, 34.715451, 5.853261, 31.263816, 11.060206, 47.017978, 2.162312, 25.589409, 34.781268, 35.668651, 31.133572, 6.783608, 0.146499, 13.275904, 13.079419, 21.202612, 39.760053, 34.716782, 16.157927, 42.741282, 6.025575, 32.304336, 9.049736, 16.608728, 2.933726, 25.348978, 12.815115, 47.362118, 33.355756, 16.061774, 48.328716, 31.627072, 20.119198, 15.384105, 49.266891, 12.021682, 31.702513, 48.836311, 16.070868, 43.966393, 32.623660, 11.965700, 24.437067, 49.520035, 16.590102, 33.720134, 14.136387, 41.386947, 13.929807, 7.709394, 19.164110, 2.374110, 19.598132, 41.505475, 9.874944, 6.211501, 10.825833, 8.820842, 37.239695, 21.093631, 37.053590, 20.161469, 16.365694, 5.885687, 11.638811, 19.482456, 0.601182, 32.615065, 41.978688, 16.973561, 15.188452, 11.570700, 3.183493, 28.038067, 22.969795, 18.316571, 43.471579, 10.879170, 16.099768, 45.884147, 39.507591, 13.528271, 7.496254, 12.062850, 13.665556, 4.842212, 20.817859, 0.700443, 42.807567, 3.238750, 47.656523, 14.339255, 2.476455, 29.281893, 21.661858, 3.297728, 21.291722, 45.608785, 46.952325, 36.318014, 36.163938, 17.374035, 41.452303, 45.880381, 13.078477, 4.772099, 9.274454, 44.024733, 22.837877, 19.049619, 42.072916, 36.034743, 3.860880, 22.018832, 1.808453, 31.807204, 21.900726, 30.731765, 26.147195, 46.626424, 40.877043, 8.436944, 34.307893, 38.801929, 9.693125, 16.808029, 38.261098, 21.388589, 15.667882, 0.882683, 19.568254, 27.112960, 39.637454, 43.826950, 30.428015, 39.778027, 36.089877, 19.468406, 29.942443, 25.618097, 39.697159, 16.226152, 42.449046, 35.875291, 30.187438, 20.628230, 5.550995, 2.793730, 11.459040, 48.372769, 26.780402, 36.238787, 1.650333, 8.504542, 28.356233, 32.178812, 47.930983, 43.191959, 34.201489, 33.921046, 47.480048, 28.416421, 23.718816, 34.727786, 48.808082, 4.799920, 8.122833, 27.506312, 48.914993, 0.912521, 36.427231, 22.193060, 11.418085, 12.572496, 32.561304, 24.465783, 7.322178, 23.428937, 20.856738, 43.750943, 49.696172, 11.958599, 23.083083, 33.529226, 48.847275, 21.235505, 23.912192, 33.095556, 38.701800, 2.461781, 19.946019, 13.980571, 3.957668, 7.010659, 30.297667, 4.154354, 11.447834, 21.336935, 36.245118, 31.853853, 26.034415, 19.387070, 8.069760, 45.323904, 46.240399, 17.968796, 24.964664, 48.650664, 19.919863, 7.956885, 24.584916, 3.001916, 49.253097, 18.721173, 8.070409, 25.185224, 20.501548, 30.953270, 40.245935, 38.058588, 34.481711, 39.110577, 34.532140, 10.805432, 7.397974, 46.213111, 21.874001, 30.672153, 40.811977, 19.922627, 7.027204, 43.751303, 42.809612, 44.244837, 4.283685, 25.092272, 9.362389, 7.212548, 26.849275, 13.896801, 0.980727, 32.518630, 41.241076, 28.888666, 15.609022, 33.846845, 34.449396, 16.601270, 1.173609, 43.917857, 34.528876, 38.258681, 27.295958, 11.616402, 19.296655, 23.545770, 28.681518, 30.069124, 25.859139, 45.832817, 15.776564, 38.193079, 19.912344, 11.870270, 42.775898, 0.682997, 15.220102, 13.534101, 39.971812, 16.464446, 26.276568, 33.303816, 24.495305, 35.239323, 28.237748, 35.985248, 48.313353, 33.827578, 33.976357, 16.577561, 34.364966, 10.441214, 32.151941, 49.901073, 49.058809, 35.150763, 36.003499, 46.129522, 27.958005, 47.585003, 32.121950, 44.634503, 5.289551, 21.375178, 36.564677, 1.490912, 30.186362, 4.207295, 39.805065, 28.943514, 16.125424, 8.929046, 41.857776, 42.911248, 16.209491, 37.729901, 16.399386, 36.296122, 22.309624, 6.663902, 39.554381, 10.491635, 30.822429, 33.304637, 27.848362, 40.000618, 14.042962, 9.588080, 34.147891, 43.886856, 8.791963, 20.256392, 7.992769, 23.803332, 32.835049, 49.072004, 31.640085, 17.287433, 30.477624, 23.896298, 19.685067, 14.042335, 6.673827, 11.304894, 13.734235, 14.046241, 12.073810, 44.530409, 35.580082, 45.738880, 18.920082, 49.386820, 47.354939, 40.315738, 40.916390, 27.582394, 26.934787, 18.967089, 2.591601, 21.319882, 47.791175, 40.033020, 3.798185, 16.021873, 33.278676, 1.398839, 25.674710, 31.191310, 6.326497, 38.382945, 7.017020, 17.541096, 30.240095, 0.533868, 43.449269, 32.914264, 40.712807, 30.848149, 30.537926, 28.940512, 32.704162, 2.030861, 18.427069, 44.292927, 12.263846, 29.420726, 24.446940, 32.595239, 40.806415, 40.313248, 5.920453, 18.795250, 14.971875, 17.911735, 36.939530, 18.444384, 23.421578, 29.384048, 19.367253, 0.392271, 24.203556, 45.053345, 36.050044, 41.603838, 13.845112, 47.894764, 33.723505, 22.879700, 32.274178, 27.376922, 32.547518, 19.407196, 34.903747, 46.211833, 11.233380, 9.460630, 44.699023, 11.762937, 19.797566, 3.520850, 19.741990, 35.946456, 25.985335, 8.188994, 31.896433, 23.240716, 4.707992, 34.842296, 34.415749, 39.417100, 34.819335, 25.740114, 8.592074, 25.234290, 38.704941, 29.425155, 23.324988, 8.926151, 30.958368, 35.145859, 9.565731, 24.440222, 44.168334, 14.214201, 39.452098, 16.817273, 4.781953, 28.537660, 49.588476, 22.214839, 46.804751, 1.137182, 47.938988, 5.266239, 19.136581, 37.458359, 45.478801, 14.855806, 13.404457, 27.306746, 34.766122, 37.015290, 24.145560, 12.812610, 48.375928, 36.678679, 29.449798, 15.361573, 43.164136, 49.644002, 2.701718, 39.833895, 14.510872}, 816, output, 51);
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 < 51; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [13, 9, 14, 15, 15, 14, 10, 17, 18, 14, 13, 23, 13, 22, 16, 12, 28, 10, 13, 26, 16, 24, 16, 14, 18, 18, 12, 14, 18, 10, 18, 19, 20, 13, 24, 16, 21, 13, 20, 18, 24, 15, 16, 15, 16, 12, 13, 18, 14, 16, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 51; ++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[] = {6, 3, 6, 4, 9, 2, 5, 6, 5, 2};
int output[] = {-1, 2, 1, 0, -2, 2, -2, 0, 0, 0};
printf("#####START#####");
int res = create_histogram((float[]){7.795144, 6.227743, 3.479573, 10.875119, 3.078031, 0.413672, 2.764350, 3.702348, 0.550957, 8.962879, 3.749640, 2.847171, 2.110760, 4.764102, 8.661196, 6.332090, 9.770846, 8.258708, 4.725931, 0.322078, 7.088743, 10.197463, 2.617354, 4.210734, 4.910803, 2.984975, 4.734002, 5.068746, 7.577156, 6.646863, 8.816245, 2.611262, 7.589817, 8.242003, 7.797063, 10.324775, 10.953271, 5.354424, 1.710878, 1.456850, 9.277592, 4.941843, 0.986695, 1.459510, 4.013790, 6.857330, 0.183880, 0.224162, 6.297384, 4.189783, 4.619659, 7.521206, 10.415347}, 53, output, 10);
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 < 10; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [6, 3, 6, 4, 9, 2, 5, 6, 5, 2]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 10; ++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, 0, 1, 0, 0, 0, 0, 0};
int output[] = {1, -1, 2, -2, 0, -1, 1, -1, 1, -1, 1};
printf("#####START#####");
int res = create_histogram((float[]){5.389922}, 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, 0, 1, 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[] = {3};
int output[] = {1};
printf("#####START#####");
int res = create_histogram((float[]){9.466188, 10.603259, 6.320724, 7.383983, 4.983959, 8.489685, 0.867769, 2.061836, 4.613589, 6.186311, 0.226646, 9.868875, 2.807720, 5.262775, 2.232708, 6.701434, 8.698873, 9.590420, 1.365865, 3.239688, 3.254837, 9.863652, 4.594498, 1.937026, 1.790866, 4.041782, 3.873007, 4.662874, 7.488042, 8.860250, 5.202922, 10.203264, 2.293287, 3.803486, 3.846969, 3.954768, 5.250217, 9.742381, 2.289589, 0.349720, 8.762198, 6.495437}, 42, 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ć: [3]\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[]){7.467645, 3.104686, 6.894945, 2.566461}, 14, NULL, 19);
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, 0, -1, 2, 1, 0, -1, -1, -1, 0, 1};
printf("#####START#####");
int res = create_histogram(NULL, 20, 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, 0, -1, 2, 1, 0, -1, -1, -1, 0, 1};
printf("#####START#####");
int res = create_histogram((float[]){7.467645, 3.104686, 6.894945, 2.566461}, 0, output, 15);
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, 0, -1, 2, 1, 0, -1, -1, -1, 0, 1};
printf("#####START#####");
int res = create_histogram((float[]){7.467645, 3.104686, 6.894945, 2.566461}, 20, 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, 0, -1, 2, 1, 0, -1, -1, -1, 0, 1};
printf("#####START#####");
int res = create_histogram((float[]){7.467645, 3.104686, 6.894945, 2.566461}, -13, output, 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 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, 0, -1, 2, 1, 0, -1, -1, -1, 0, 1};
printf("#####START#####");
int res = create_histogram((float[]){7.467645, 3.104686, 6.894945, 2.566461}, 11, 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 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[] = {2, 0, 2, -3, -6, -3, 8, 5, 1};
//-------------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, -9);
printf("***END***\n");
//-------------3-----------------------
printf("\n***TEST 3***\n\n");
printf("***START***\n");
display_vector(tab, 9);
printf("***END***\n");
//-------------4-----------------------
printf("\n***TEST 4***\n\n");
printf("***START***\n");
display_vector(tab, 9 - 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[] = {2.000000, -9.000000, -1.000000, -4.000000, -3.000000, -7.000000, 2.000000, -7.000000, -6.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ć: [2.000000, -9.000000, -1.000000, -4.000000, -3.000000, -7.000000, 2.000000, -7.000000, -6.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 = 6;
const float expected_array[] = {5.000000, 0.000000, -10.000000, 3.000000, -3.000000, 8.000000, -8.000000};
float dest[7];
int result = read_vector_float(dest, 7, -8);
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ć: [5.000000, 0.000000, -10.000000, 3.000000, -3.000000, 8.000000, -8.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 = 5;
const float expected_array[] = {0.000000, 6.000000, -3.000000, -4.000000, 8.000000};
float dest[5];
int result = read_vector_float(dest, 5, -1);
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, 6.000000, -3.000000, -4.000000, 8.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[6];
printf("#####START#####");
int result = read_vector_float(dest, 0, -6);
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[10];
printf("#####START#####");
int result = read_vector_float(dest, -10, -8);
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, -4, -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();
}