ECC-1431: Cleanup

This commit is contained in:
Shahram Najm 2022-08-01 16:16:08 +01:00
parent 7ae3195552
commit fdcddc2352
2 changed files with 87 additions and 74 deletions

View File

@ -1,3 +1,13 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include <eccodes.h>
#include <string.h>
@ -11,16 +21,18 @@
typedef std::numeric_limits<double> dbl;
typedef std::numeric_limits<float> flt;
struct Range {
struct Range
{
double min;
double max;
};
/*
* Test: This test doesn't accept errors after decompression.
*/
void test_full() {
//
// Test: This test doesn't accept errors after decompression.
//
void test_full()
{
std::vector<Range> ranges;
ranges.push_back({ flt::max() / 10, flt::max() });
ranges.push_back({ flt::max() / 100, flt::max() / 10 });
@ -29,12 +41,12 @@ void test_full() {
ranges.push_back({ 1e-1, 1e-0 });
ranges.push_back({ 1e-2, 1e-1 });
ranges.push_back({ 1e-11, 1e-10 });
/* TODO */
/* The test fails for the following ranges */
/* These tests can be performed when the problem is solved with small values.*/
/* ranges.push_back({flt::min()*10 , flt::min()*100 } ); */
/* ranges.push_back({flt::min() , flt::min()*10 } ); */
/* ranges.push_back({flt::min() , flt::max() } ); */
// TODO
// The test fails for the following ranges
// These tests can be performed when the problem is solved with small values.
// ranges.push_back({flt::min()*10 , flt::min()*100 } );
// ranges.push_back({flt::min() , flt::min()*10 } );
// ranges.push_back({flt::min() , flt::max() } );
std::vector<size_t> values_lens = {
1,
@ -66,17 +78,17 @@ void test_full() {
grid_simple_values_len = in_values_len;
grid_ccsds_values_len = in_values_len;
/* Initialize with random values */
// Initialize with random values
for (size_t i = 0; i < in_values_len; ++i) {
in_values[i] = unif(re);
}
/* Convert original values to quantized values, by grid_simple */
// Convert original values to quantized values, by grid_simple
CODES_CHECK(codes_set_double_array(handle, "values", in_values, in_values_len), 0);
CODES_CHECK(codes_get_double_array(handle, "values", grid_simple_values, &grid_simple_values_len), 0);
Assert(in_values_len == grid_simple_values_len);
/* Test grid_ccsds */
// Test grid_ccsds
packing_type = "grid_ccsds";
size = packing_type.size();
CODES_CHECK(codes_set_string(handle, "packingType", packing_type.c_str(), &size), 0);
@ -88,7 +100,7 @@ void test_full() {
}
Assert(grid_ccsds_values_len == grid_simple_values_len);
/* Test buffers */
// Test buffers
for (size_t i = 0; i < grid_ccsds_values_len; ++i) {
if (grid_ccsds_values[i] != grid_simple_values[i]) {
std::cout.precision(dbl::max_digits10);
@ -107,10 +119,11 @@ void test_full() {
}
/*
* Test: This test accepts tolerates errors. Values after decompression must be within a certain user defined range.
*/
void test_simplified() {
//
// Test: This test accepts tolerates errors. Values after decompression must be within a certain user defined range.
//
void test_simplified()
{
std::vector<Range> ranges;
ranges.push_back({ flt::max() / 10, flt::max() });
ranges.push_back({ flt::max() / 100, flt::max() / 10 });
@ -119,9 +132,9 @@ void test_simplified() {
ranges.push_back({ 1e-1, 1e-0 });
ranges.push_back({ 1e-2, 1e-1 });
ranges.push_back({ 1e-11, 1e-10 });
/* TODO */
/* The test fails for the following ranges */
/* These tests can be performed when the problem is solved with small values.*/
// TODO
// The test fails for the following ranges
// These tests can be performed when the problem is solved with small values.
// ranges.push_back({flt::min()*10 , flt::min()*100 } );
// ranges.push_back({flt::min() , flt::min()*10 } );
// ranges.push_back({flt::min() , flt::max() } );
@ -153,12 +166,12 @@ void test_simplified() {
grid_ccsds_values_len = in_values_len;
/* Initialize with random values */
// Initialize with random values
for (size_t i = 0; i < in_values_len; ++i) {
in_values[i] = unif(re);
}
/* Test grid_ccsds */
// Test grid_ccsds
packing_type = "grid_ccsds";
size = packing_type.size();
CODES_CHECK(codes_set_string(handle, "packingType", packing_type.c_str(), &size), 0);
@ -170,7 +183,7 @@ void test_simplified() {
}
Assert(grid_ccsds_values_len == in_values_len);
/* Test buffers */
// Test buffers
double tolerance = 0.000001;
for (size_t i = 0; i < grid_ccsds_values_len; ++i) {
if (!((grid_ccsds_values[i] < (in_values[i] * (1 + tolerance))) &&
@ -190,7 +203,8 @@ void test_simplified() {
}
int main(int argc, char** argv) {
int main(int argc, char** argv)
{
test_simplified();
//test_full();
return 0;

View File

@ -9,9 +9,8 @@
#
. ./include.ctest.sh
set -u
REDIRECT=/dev/null
label="grib_ECC-1431_test" # Change prod to bufr or grib etc
label="grib_ecc-1431_test"
temp=temp.$label
$EXEC $test_dir/grib_ecc-1431