CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
index_format_test.cc
Go to the documentation of this file.
1// -*- C++ -*-
12#include <cstdlib>
13#include <iostream>
14
15#include "gtest/gtest.h"
16
17#include "ranges/ranges.h"
18#include "array/array.h"
19
20namespace
21{
22 using namespace CNORXZ;
23
24 class Format_Test : public ::testing::Test
25 {
26 protected:
27
28 Format_Test()
29 {
30 mMeta7 = { "These", "are", "test", "strings", "foo", "bar", "baz" };
31 auto sr2 = SRangeFactory<SizeT,2>(Arr<SizeT,2>{0,1}).create();
32 auto ur3x = std::dynamic_pointer_cast<URange<Real>>
33 (URangeFactory<Real>(Vector<Real>{3.141,1.6,2.7}).create());
34 auto cr5x = std::dynamic_pointer_cast<CRange>(CRangeFactory(5).create());
35 auto ur7x = std::dynamic_pointer_cast<URange<String>>
36 (URangeFactory<String>(mMeta7).create());
37 auto mr105 = mrange(ur3x,ur7x,cr5x);
38 auto cr11 = CRangeFactory(11).create();
39 auto cr13 = CRangeFactory(13).create();
40 auto cr17 = CRangeFactory(17).create();
41 mRange = yrange({cr11,mr105,cr13,sr2});
42 mRange2 = yrange({cr11,mr105,cr13,cr17,sr2});
43 }
44
45 Vector<String> mMeta7;
46 RangePtr mRange;
47 RangePtr mRange2;
48 };
49
50 TEST_F(Format_Test, RangeCheck)
51 {
52 EXPECT_EQ(mRange->size(), 2*105*11*13);
53 EXPECT_EQ(mRange2->size(), 2*105*11*13*17);
54 auto yi = mRange->begin();
55 EXPECT_EQ(yi.lmax().val(), mRange->size());
56 EXPECT_EQ(yi.pmax().val(), mRange->size());
57 EXPECT_EQ(mRange->dim(), 4u);
58 }
59
60 TEST_F(Format_Test, CFormat)
61 {
62 CIndex ci(mRange);
63 EXPECT_EQ(ci.lmax().val(), mRange->size());
64 auto yi = mRange->begin();
65 auto yi2 = mRange2->begin();
66 ci.reformat( yi.deepFormat(), yi.deepMax() );
67 VCHECK(toString(yi.deepFormat()));
68 VCHECK(toString(yi.deepMax()));
69 VCHECK(toString(yi2.deepFormat()));
70 VCHECK(toString(yi2.deepMax()));
71 EXPECT_EQ(ci.lmax().val(), mRange->size());
72 }
73
74 TEST_F(Format_Test, XFormat)
75 {
79 EXPECT_EQ(mi.lmax().val(), mRange->size());
80 EXPECT_EQ(mi2.lmax().val(), mRange2->size());
81 auto yi = indexAs<YIndex>( mRange->begin() );
82 mi.reformat( yi.deepFormat(), yi.deepMax() );
83 EXPECT_EQ(mi.lmax().val(), mRange->size());
84 VCHECK(toString(mi.deepFormat()));
85 VCHECK(toString(mi.deepMax()));
86 VCHECK(toString(mi2.deepFormat()));
87 VCHECK(toString(mi2.deepMax()));
88
89
90 yi.setFormat( YFormat( Vector<SizeT>{ mi2.format()[CSizeT<0>{}].val(), mi2.format()[CSizeT<1>{}].val(), mi2.format()[CSizeT<2>{}].val(), mi2.format()[CSizeT<4>{}].val() } ) );
91 VCHECK(toString(yi.deepFormat()));
92 mi.reformat( yi.deepFormat(), yi.deepMax() );
93 VCHECK(toString(mi.deepFormat()));
94 VCHECK(toString(mi.deepMax()));
95
96 yi.setFormat( YFormat( Vector<SizeT>{ 13, 143, 1, 15015 } ) );
97 VCHECK(toString(yi.deepFormat()));
98 mi.reformat( yi.deepFormat(), yi.deepMax() );
99 VCHECK(toString(mi.deepFormat()));
100 VCHECK(toString(mi.deepMax()));
101
102 mi32.reformat( Vector<SizeT> { 105,1,2310,1155 }, Vector<SizeT> { 11,105,13,2 } );
103 VCHECK(toString(yi.deepFormat()));
104 mi32.reformat( yi.deepFormat(), yi.deepMax() );
105 VCHECK(toString(mi32.deepFormat()));
106 VCHECK(toString(mi32.deepMax()));
107 }
108}
Array main header.
#define VCHECK(a)
Definition macros.h:24
RangePtr yrange(const Vector< RangePtr > &rs)
Definition yrange.cc:666
Sptr< RangeBase > RangePtr
Definition types.h:157
std::vector< T, Allocator< T > > Vector
Definition types.h:310
RangePtr mrange(const Sptr< Ranges > &... rs)
Definition mrange.cc.h:800
std::integral_constant< SizeT, N > CSizeT
Definition types.h:81
Sptr< Range > rangeCast(const RangePtr r)
std::array< T, N > Arr
Definition types.h:45
String toString(const T &a)
Ranges main header.