| 1 |
// Copyright (C) 2017 |
| 2 |
// |
| 3 |
// This file is part of DOLFIN. |
| 4 |
// |
| 5 |
// DOLFIN is free software: you can redistribute it and/or modify |
| 6 |
// it under the terms of the GNU Lesser General Public License as published by |
| 7 |
// the Free Software Foundation, either version 3 of the License, or |
| 8 |
// (at your option) any later version. |
| 9 |
// |
| 10 |
// DOLFIN is distributed in the hope that it will be useful, |
| 11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
// GNU Lesser General Public License for more details. |
| 14 |
// |
| 15 |
// You should have received a copy of the GNU Lesser General Public License |
| 16 |
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
// |
| 18 |
// First added: 2017-03-08 |
| 19 |
// Last changed: 2017-03-08 |
| 20 |
// |
| 21 |
// Unit tests Selected methods for SUNDIALSNVector |
| 22 |
|
| 23 |
#include <dolfin.h> |
| 24 |
#include <gtest/gtest.h> |
| 25 |
|
| 26 |
using namespace dolfin; |
| 27 |
|
| 28 |
//---------------------------------------------------- |
| 29 |
void _test(MPI_Comm comm) |
| 30 |
{ |
| 31 |
SUNDIALSNVector v(comm, 10), u(comm, 10); |
| 32 |
v.N_VConst(0,v.nvector()); |
| 33 |
u.N_VConst(0.0,u.nvector()); |
| 34 |
ASSERT_EQ(v.vec()->sum(), 0.0); |
| 35 |
|
| 36 |
// N_VConst(double a, N_Vector x) |
| 37 |
v.N_VConst(1.0,v.nvector()); |
| 38 |
ASSERT_EQ(v.vec()->sum(), v.vec()->size()); |
| 39 |
|
| 40 |
// operator=(const N_Vector x) |
| 41 |
u = v; |
| 42 |
ASSERT_EQ(u.vec()->sum(), u.vec()->size()); |
| 43 |
|
| 44 |
} |
| 45 |
//---------------------------------------------------- |
| 46 |
TEST(TestSUNDIALSNVector, test_backend) |
| 47 |
{ |
| 48 |
// SUNDIALS |
| 49 |
#ifdef HAS_SUNDIALS |
| 50 |
_test(MPI_COMM_WORLD); |
| 51 |
#endif |
| 52 |
} |
| 53 |
//---------------------------------------------------- |
| 54 |
|
| 55 |
// Test all |
| 56 |
int SUNDIALSNVector_main(int argc, char **argv) { |
| 57 |
testing::InitGoogleTest(&argc, argv); |
| 58 |
return RUN_ALL_TESTS(); |
| 59 |
} |