| 1 |
// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering |
| 2 |
// Solutions of Sandia, LLC (NTESS). Under the terms of Contract |
| 3 |
// DE-NA0003525 with NTESS, the U.S. Government retains certain rights |
| 4 |
// in this software. |
| 5 |
// |
| 6 |
// Redistribution and use in source and binary forms, with or without |
| 7 |
// modification, are permitted provided that the following conditions are |
| 8 |
// met: |
| 9 |
// |
| 10 |
// * Redistributions of source code must retain the above copyright |
| 11 |
// notice, this list of conditions and the following disclaimer. |
| 12 |
// |
| 13 |
// * Redistributions in binary form must reproduce the above |
| 14 |
// copyright notice, this list of conditions and the following |
| 15 |
// disclaimer in the documentation and/or other materials provided |
| 16 |
// with the distribution. |
| 17 |
// |
| 18 |
// * Neither the name of NTESS nor the names of its contributors |
| 19 |
// may be used to endorse or promote products derived from this |
| 20 |
// software without specific prior written permission. |
| 21 |
// |
| 22 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 |
// |
| 34 |
|
| 35 |
#include "gtest/gtest.h" |
| 36 |
#include "stk_util/parallel/MPI.hpp" // for Loc, create_Loc, operator== |
| 37 |
#include <cstdint> // for int64_t |
| 38 |
#include <utility> // for move |
| 39 |
|
| 40 |
namespace sierra |
| 41 |
{ |
| 42 |
namespace MPI |
| 43 |
{ |
| 44 |
|
| 45 |
TEST(Loc, Constructors) |
| 46 |
{ |
| 47 |
Loc<double, int64_t> l; |
| 48 |
l.m_value = 1.; |
| 49 |
l.m_loc = 3; |
| 50 |
|
| 51 |
Loc<double, int64_t> copy(l); |
| 52 |
EXPECT_DOUBLE_EQ(l.m_value, copy.m_value); |
| 53 |
EXPECT_EQ(l.m_loc, copy.m_loc); |
| 54 |
|
| 55 |
Loc<double, int64_t> move(std::move(l)); |
| 56 |
EXPECT_DOUBLE_EQ(l.m_value, move.m_value); |
| 57 |
EXPECT_EQ(l.m_loc, move.m_loc); |
| 58 |
} |
| 59 |
|
| 60 |
TEST(Loc, Assignment) |
| 61 |
{ |
| 62 |
Loc<double, int64_t> l; |
| 63 |
l.m_value = 1.; |
| 64 |
l.m_loc = 3; |
| 65 |
|
| 66 |
Loc<double, int64_t> assign; |
| 67 |
assign = l; |
| 68 |
EXPECT_DOUBLE_EQ(l.m_value, assign.m_value); |
| 69 |
EXPECT_EQ(l.m_loc, assign.m_loc); |
| 70 |
|
| 71 |
// Assignment from a dereferenced volatile * is required for use of Loc with |
| 72 |
// Kokkos::atomic_compare_exchange(); |
| 73 |
volatile Loc<double, int64_t> * const volatile_ptr = &l; |
| 74 |
Loc<double, int64_t> assign_from_volatile; |
| 75 |
assign_from_volatile = *volatile_ptr; |
| 76 |
EXPECT_DOUBLE_EQ(l.m_value, assign_from_volatile.m_value); |
| 77 |
EXPECT_EQ(l.m_loc, assign_from_volatile.m_loc); |
| 78 |
|
| 79 |
Loc<double, int64_t> assign_to_volatile; |
| 80 |
volatile Loc<double, int64_t> * const to_volatile_ptr = &assign_to_volatile; |
| 81 |
*to_volatile_ptr = l; |
| 82 |
EXPECT_DOUBLE_EQ(l.m_value, assign_to_volatile.m_value); |
| 83 |
EXPECT_EQ(l.m_loc, assign_to_volatile.m_loc); |
| 84 |
} |
| 85 |
|
| 86 |
TEST(Loc, CompareEqual) |
| 87 |
{ |
| 88 |
double lhs_val = 1.; |
| 89 |
int64_t lhs_id = 1; |
| 90 |
auto lhs = create_Loc(lhs_val, lhs_id); |
| 91 |
|
| 92 |
EXPECT_TRUE(lhs == lhs); |
| 93 |
|
| 94 |
{ |
| 95 |
double rhs_val = 5.; |
| 96 |
int64_t rhs_id = 1; |
| 97 |
auto rhs = create_Loc(rhs_val, rhs_id); |
| 98 |
|
| 99 |
EXPECT_FALSE(lhs == rhs); |
| 100 |
} |
| 101 |
|
| 102 |
{ |
| 103 |
double rhs_val = 1.; |
| 104 |
int64_t rhs_id = 2; |
| 105 |
auto rhs = create_Loc(rhs_val, rhs_id); |
| 106 |
|
| 107 |
EXPECT_FALSE(lhs == rhs); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
} |
| 112 |
} |