Skip to content

Commit

Permalink
Update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
AnderOne committed Apr 5, 2019
1 parent 3f43773 commit 589908d
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 1 deletion.
3 changes: 2 additions & 1 deletion testsuite/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ derrick-bass-1 derrick-bass-3 exprctor expression-slicing extract free \
gary-huber-1 indexexpr-base initialize int-math-func interlace iter \
Josef-Wagenhuber levicivita loop1 matthias-troyer-1 matthias-troyer-2 \
mattias-lindstroem-1 member_function minmax minsumpow module \
multicomponent multicomponent-2 newet Olaf-Ronneberger-1 \
multicomponent multicomponent-1 multicomponent-2 newet Olaf-Ronneberger-1 \
patrik-jonsson-1 peter-bienstman-1 peter-bienstman-2 peter-bienstman-3 \
peter-bienstman-4 peter-bienstman-5 peter-nordlund-1 peter-nordlund-2 \
peter-nordlund-3 preexisting promote pthread qcd reduce reindex \
Expand Down Expand Up @@ -73,6 +73,7 @@ minmax_SOURCES = minmax.cpp
minsumpow_SOURCES = minsumpow.cpp
module_SOURCES = module1.cpp module2.cpp
multicomponent_SOURCES = multicomponent.cpp
multicomponent_1_SOURCES = multicomponent-1.cpp
multicomponent_2_SOURCES = multicomponent-2.cpp
newet_SOURCES = newet.cpp
Olaf_Ronneberger_1_SOURCES = Olaf-Ronneberger-1.cpp
Expand Down
128 changes: 128 additions & 0 deletions testsuite/multicomponent-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#include "testsuite.h"
#include <blitz/array.h>
#include <blitz/array.cc>
#include <blitz/tinyvec2.h>
#include <blitz/tinyvec2.cc>
#include <blitz/tinymat2.h>
#include <blitz/tinymat2.cc>

BZ_USING_NAMESPACE(blitz)

static const double eps = 0.0001;

#define ISCLOSE(a, b) BZTEST(fabs((a)-(b))<eps)

#define __TEST_FOR_VECTOR_EXPR

typedef TinyMatrix<double, 2, 3> T_matrix;
typedef TinyVector<double, 3> T_vector;
typedef Array<double, 2> T_array_2;
typedef Array<double, 1> T_array_1;
typedef Array<T_vector, 1> T_array_1_of_vector;
typedef Array<T_vector, 2> T_array_2_of_vector;
typedef Array<T_matrix, 1> T_array_1_of_matrix;
typedef Array<T_matrix, 2> T_array_2_of_matrix;

#ifndef __TEST_FOR_VECTOR_EXPR
#define EXPR2(a) (T_vector(a * 2 + 1))
#define EXPR3(a) (T_vector(a * 3 - 4))
#else
#define EXPR2(a) (a * 2 + 1)
#define EXPR3(a) (a * 3 - 4)
#endif

#define EXPR4(a, b) (a - b * 5 + 6)

int main() {

T_vector V1(1, 2, 3);
T_vector V2 = EXPR2(V1);
T_vector V3 = EXPR3(V1);
T_vector V4 = EXPR4(V2, V1);
cout << "V1 = " << V1 << endl;
cout << "V2 = " << V2 << endl;
cout << "V3 = " << V3 << endl;
cout << "V4 = " << V4 << endl;

cout << "Testing for 1d-Array:" << endl;

//Here TinyVector is composite object like as Array in the left side
T_array_1 A1(3);
A1 = EXPR2(V1);
cout << A1 << endl;
for (int k = 0; k < 3; ++ k) { ISCLOSE(A1(k), V2(k)); }
//Here we construct TinyVector as scalar value and fill Array
T_array_1_of_vector A1V(5);
A1V = EXPR2(V1);
cout << A1V << endl;
for (int i = 0; i < 5; ++ i)
for (int k = 0; k < 3; ++ k) { ISCLOSE(A1V(i)(k), V2(k)); }
//Partial assignment of a vector expression
A1V(Range(1, 3)) = EXPR3(V1);
cout << A1V << endl;
for (int i = 0; i < 5; ++ i)
for (int k = 0; k < 3; ++ k) {
if ((i >= 1) && (i <= 3)) {
ISCLOSE(A1V(i)(k), V3(k));
}
else {
ISCLOSE(A1V(i)(k), V2(k));
}
}
//Check for component wise assignment
for (int k = 0; k < 3; ++ k) {
A1V[k] = V4(k);
}
cout << A1V << endl;
for (int i = 0; i < 5; ++ i)
for (int k = 0; k < 3; ++ k) { ISCLOSE(A1V(i)(k), V4(k)); }

cout << "Testing for 2d-Array:" << endl;

//Here we construct TinyVector as scalar value and fill Array
T_array_2_of_vector A2V(5, 4);
A2V = EXPR2(V1);
cout << A2V << endl;
for (int i = 0; i < 5; ++ i)
for (int j = 0; j < 4; ++ j)
for (int k = 0; k < 3; ++ k) { ISCLOSE(A2V(i, j)(k), V2(k)); }
//Partial assignment of a vector expression
A2V(Range(2, 3), Range(1, 2)) = EXPR3(V1);
cout << A2V << endl;
for (int i = 0; i < 5; ++ i)
for (int j = 0; j < 4; ++ j)
for (int k = 0; k < 3; ++ k) {
if ((i >= 2) && (i <= 3) &&
(j >= 1) && (j <= 2)) {
ISCLOSE(A2V(i, j)(k), V3(k));
}
else {
ISCLOSE(A2V(i, j)(k), V2(k));
}
}
//Check for component wise assignment
for (int k = 0; k < 3; ++ k) {
A2V[k] = V4(k);
}
cout << A2V << endl;
for (int i = 0; i < 5; ++ i)
for (int j = 0; j < 4; ++ j)
for (int k = 0; k < 3; ++ k) { ISCLOSE(A2V(i, j)(k), V4(k)); }
//Check for array expression
T_array_2_of_vector A(5, 4);
T_array_2_of_vector B(5, 4);
T_array_2_of_vector C(5, 4);
A = V1;
B = V2;
B(0, 3) = EXPR3(V1);
B(4, 0) = V3;
C = EXPR4(B, A);
cout << C << endl;
for (int i = 0; i < 5; ++ i)
for (int j = 0; j < 4; ++ j)
for (int k = 0; k < 3; ++ k) {
ISCLOSE(C(i, j)(k), EXPR4(B(i, j)(k), A(i, j)(k)));
}

return 0;
}

0 comments on commit 589908d

Please sign in to comment.