| 1 | #include <deque> |
|---|
| 2 | #include <fstream> |
|---|
| 3 | #include <cerrno> |
|---|
| 4 | #include <boost/assign/std/vector.hpp> |
|---|
| 5 | |
|---|
| 6 | #include "../../../../io/testinitializer.h" |
|---|
| 7 | #include "../../../../misc/testcell.h" |
|---|
| 8 | #include "../../mockpatchaccepter.h" |
|---|
| 9 | #include "../../partitions/zcurvepartition.h" |
|---|
| 10 | #include "../../updategroup.h" |
|---|
| 11 | |
|---|
| 12 | using namespace boost::assign; |
|---|
| 13 | using namespace LibGeoDecomp; |
|---|
| 14 | using namespace HiParSimulator; |
|---|
| 15 | |
|---|
| 16 | namespace LibGeoDecomp { |
|---|
| 17 | namespace HiParSimulator { |
|---|
| 18 | |
|---|
| 19 | class UpdateGroupTest : public CxxTest::TestSuite |
|---|
| 20 | { |
|---|
| 21 | public: |
|---|
| 22 | typedef ZCurvePartition<3> Partition; |
|---|
| 23 | typedef VanillaStepper<TestCell<3> > MyStepper; |
|---|
| 24 | typedef UpdateGroup<TestCell<3>, Partition, MyStepper> MyUpdateGroup; |
|---|
| 25 | typedef MyStepper::GridType GridType; |
|---|
| 26 | |
|---|
| 27 | void setUp() |
|---|
| 28 | { |
|---|
| 29 | rank = MPILayer().rank(); |
|---|
| 30 | dimensions = Coord<3>(28, 50, 32); |
|---|
| 31 | partition = Partition(Coord<3>(), dimensions); |
|---|
| 32 | weights.clear(); |
|---|
| 33 | weights << dimensions.prod(); |
|---|
| 34 | ghostZoneWidth = 10; |
|---|
| 35 | init = new TestInitializer<3>(dimensions); |
|---|
| 36 | updateGroup.reset( |
|---|
| 37 | new MyUpdateGroup( |
|---|
| 38 | partition, |
|---|
| 39 | weights, |
|---|
| 40 | 0, |
|---|
| 41 | CoordBox<3>(Coord<3>(), dimensions), |
|---|
| 42 | ghostZoneWidth, |
|---|
| 43 | init)); |
|---|
| 44 | mockPatchAccepter.reset(new MockPatchAccepter<GridType>()); |
|---|
| 45 | mockPatchAccepter->pushRequest(5); |
|---|
| 46 | mockPatchAccepter->pushRequest(7); |
|---|
| 47 | mockPatchAccepter->pushRequest(8); |
|---|
| 48 | updateGroup->addPatchAccepter(mockPatchAccepter, MyStepper::INNER_SET); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | void tearDown() |
|---|
| 52 | { |
|---|
| 53 | delete init; |
|---|
| 54 | updateGroup.reset(); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | void testBasic() |
|---|
| 58 | { |
|---|
| 59 | updateGroup->update(10); |
|---|
| 60 | std::deque<long> expected; |
|---|
| 61 | expected.push_back(5); |
|---|
| 62 | expected.push_back(7); |
|---|
| 63 | expected.push_back(8); |
|---|
| 64 | std::deque<long> actual = mockPatchAccepter->getOfferedNanoSteps(); |
|---|
| 65 | TS_ASSERT_EQUALS(actual, expected); |
|---|
| 66 | TS_ASSERT_EQUALS(10, updateGroup->grid()[Coord<3>(1, 2, 3)].cycleCounter); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | private: |
|---|
| 70 | unsigned rank; |
|---|
| 71 | Coord<3> dimensions; |
|---|
| 72 | SuperVector<long> weights; |
|---|
| 73 | Partition partition; |
|---|
| 74 | unsigned ghostZoneWidth; |
|---|
| 75 | Initializer<TestCell<3> > *init; |
|---|
| 76 | boost::shared_ptr<UpdateGroup<TestCell<3>, Partition > > updateGroup; |
|---|
| 77 | boost::shared_ptr<MockPatchAccepter<GridType> > mockPatchAccepter; |
|---|
| 78 | }; |
|---|
| 79 | |
|---|
| 80 | } |
|---|
| 81 | } |
|---|