| 1 |
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 2 |
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception |
| 3 |
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 4 |
// vi: set et ts=4 sw=2 sts=2: |
| 5 |
|
| 6 |
/** \file |
| 7 |
* \brief Test the FieldVector class from dune-common with the unit tests for the dune-istl vector interface |
| 8 |
* |
| 9 |
* This test is exceptional: it is testing a class from dune-common! This is because FieldVector is supposed |
| 10 |
* to implement the dune-istl vector interface, but it resides in dune-common because most other modules |
| 11 |
* also want to use it. However, the tests for the dune-istl vector interface reside in dune-istl, and therefore |
| 12 |
* the compliance test for FieldVector needs to be done in dune-istl, too. |
| 13 |
*/ |
| 14 |
#include <complex> |
| 15 |
|
| 16 |
#include <dune/common/fvector.hh> |
| 17 |
|
| 18 |
#include <dune/istl/test/vectortest.hh> |
| 19 |
|
| 20 |
using namespace Dune; |
| 21 |
|
| 22 |
int main() try |
| 23 |
{ |
| 24 |
// Test a double vector |
| 25 |
FieldVector<double,3> vDouble = {1.0, 2.0, 3.0}; |
| 26 |
testHomogeneousRandomAccessContainer(vDouble); |
| 27 |
testConstructibility<decltype(vDouble)>(); |
| 28 |
testNorms(vDouble); |
| 29 |
testVectorSpaceOperations(vDouble); |
| 30 |
|
| 31 |
// Test a double vector of length 1 |
| 32 |
FieldVector<double,1> vDouble1 = {1.0}; |
| 33 |
testHomogeneousRandomAccessContainer(vDouble1); |
| 34 |
testConstructibility<decltype(vDouble1)>(); |
| 35 |
testNorms(vDouble1); |
| 36 |
testVectorSpaceOperations(vDouble1); |
| 37 |
|
| 38 |
// Test a complex vector |
| 39 |
FieldVector<std::complex<double>,3> vComplex = {{1.0, 1.0}, {2.0,2.0}, {3.0,3.0}}; |
| 40 |
testHomogeneousRandomAccessContainer(vComplex); |
| 41 |
testConstructibility<decltype(vComplex)>(); |
| 42 |
testNorms(vComplex); |
| 43 |
testVectorSpaceOperations(vComplex); |
| 44 |
|
| 45 |
// Test a complex vector of length 1 |
| 46 |
FieldVector<std::complex<double>,1> vComplex1 = {{1.0,3.14}}; |
| 47 |
testHomogeneousRandomAccessContainer(vComplex1); |
| 48 |
testConstructibility<decltype(vComplex1)>(); |
| 49 |
testNorms(vComplex1); |
| 50 |
testVectorSpaceOperations(vComplex1); |
| 51 |
|
| 52 |
return 0; |
| 53 |
} |
| 54 |
catch (std::exception& e) { |
| 55 |
std::cerr << e.what() << std::endl; |
| 56 |
return 1; |
| 57 |
} |