Skip to content

Commit

Permalink
Add better error handling of test
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Nov 24, 2023
1 parent a949810 commit a44244b
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions lib/resdata/tests/rd_grid_dx_dy_dz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,33 @@
#include <math.h>

#include <string>
#include <filesystem>
#include <iostream>

#include <ert/util/test_util.hpp>
#include <ert/util/util.h>

#include <resdata/rd_grid.hpp>
#include <resdata/rd_file.hpp>

namespace fs = std::filesystem;

double err(double a, double b) { return (a - b) / a; }

void test_dxdydz(const std::string &grid_fname, const std::string &init_fname) {
double eps_x = 1e-4;
double eps_y = 1e-4;
double eps_z = 1e-3;
rd_grid_type *grid = rd_grid_alloc(grid_fname.c_str());
if (grid == NULL) {
std::cerr << "Could not open " << grid_fname << std::endl;
exit(-1);
}
rd_file_type *init_file = rd_file_open(init_fname.c_str(), 0);
if (init_file == NULL) {
std::cerr << "Could not open " << init_fname << std::endl;
exit(-1);
}
rd_kw_type *dx = rd_file_iget_named_kw(init_file, "DX", 0);
rd_kw_type *dy = rd_file_iget_named_kw(init_file, "DY", 0);
rd_kw_type *dz = rd_file_iget_named_kw(init_file, "DZ", 0);
Expand Down Expand Up @@ -46,9 +58,19 @@ void test_dxdydz(const std::string &grid_fname, const std::string &init_fname) {
}

int main(int argc, char **argv) {
if (argc < 2) {
std::cerr << "Must give case as input" << std::endl;
exit(-1);
}
const std::string rd_case = argv[1];
std::string grid_file = rd_case + ".EGRID";
std::string init_file = rd_case + ".INIT";
fs::path grid_file = rd_case + ".EGRID";
fs::path init_file = rd_case + ".INIT";

if (!fs::exists(grid_file) || !fs::exists(init_file)) {
std::cerr << "Given case " << rd_case << " without grid or init"
<< std::endl;
exit(-1);
}

test_dxdydz(grid_file, init_file);

Expand Down

0 comments on commit a44244b

Please sign in to comment.