1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include <forstio/test/suite.h>
#include <forstio/codec/netcdf/netcdf.h>
namespace {
namespace schema {
using namespace saw::schema;
using TestStruct = Struct<
Member<Int32, "data">,
Member<Float64, "other">
>;
using TestArrayStruct = Struct<
Member<Array<Int32,2>, "data">
>;
}
SAW_TEST("NetCDF Struct Primitive read"){
using namespace saw;
data<schema::TestStruct, encode::Netcdf> netcdf{"./data/primitive.nc"};
data<schema::TestStruct, encode::Native> native;
codec<schema::TestStruct, encode::Netcdf> codec;
auto eov = codec.decode(netcdf, native);
SAW_EXPECT(eov.is_value(), "Decoding failed");
SAW_EXPECT(native.get<"data">().get() == 5, "Int Value incorrect");
SAW_EXPECT(native.get<"other">().get() == 32.0, "Double Value incorrect");
}
SAW_TEST("NetCDF Struct Array read"){
using namespace saw;
data<schema::TestArrayStruct, encode::Netcdf> netcdf{"./data/array.nc"};
data<schema::TestArrayStruct, encode::Native> native;
codec<schema::TestArrayStruct, encode::Netcdf> codec;
auto eov = codec.decode(netcdf, native);
SAW_EXPECT(eov.is_value(), "Decoding failed");
auto& arr = native.get<"data">();
SAW_EXPECT(arr.get_dim_size(0) == 5, "Incorrect dimension 0");
SAW_EXPECT(arr.get_dim_size(1) == 3, "Incorrect dimension 1");
for(std::size_t i = 0; i < 5; ++i){
for(std::size_t j = 0; j < 3; ++j){
int64_t exp_val = i * 3 + j;
SAW_EXPECT(arr.at(i,j).get() == exp_val, "Incorrect value");
}
}
}
}
|