Skip to content

Commit 8b241c6

Browse files
committed
Tests: Add edge cases for wrapped spatial which currently fail
1 parent d5badbb commit 8b241c6

2 files changed

Lines changed: 44 additions & 28 deletions

File tree

tests/test_cases/runtime/messaging/test_spatial_2d.cu

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
* Tests cover:
55
* > mandatory messaging, send/recieve
66
*/
7+
#include <array>
78
#include <unordered_map>
8-
99
#include "flamegpu/flamegpu.h"
10-
1110
#include "gtest/gtest.h"
1211

1312
namespace flamegpu {
1413

15-
1614
namespace test_message_spatial2d {
1715

1816
FLAMEGPU_AGENT_FUNCTION(out_mandatory2D, MessageNone, MessageSpatial2D) {
@@ -918,15 +916,12 @@ FLAMEGPU_AGENT_FUNCTION(in_wrapped_EnvDimsNotFactor, MessageSpatial2D, MessageNo
918916
}
919917
return ALIVE;
920918
}
921-
TEST(Spatial2DMessageTest, Wrapped_EnvDimsNotFactor) {
922-
// This tests that bug #1157 is fixed
923-
// When the interaction radius is not a factor of the width
924-
// that agent's near the max env bound all have the full interaction radius
919+
void wrapped_2d_test_bounds(std::array<float, 2> lower, std::array<float, 2> upper, float radius, bool exceptionExpected) {
925920
ModelDescription m("model");
926921
MessageSpatial2D::Description message = m.newMessage<MessageSpatial2D>("location");
927-
message.setMin(0, 0);
928-
message.setMax(50.1f, 50.1f);
929-
message.setRadius(10);
922+
message.setMin(lower.at(0), lower.at(1));
923+
message.setMax(upper.at(0), upper.at(1));
924+
message.setRadius(radius);
930925
message.newVariable<flamegpu::id_t>("id"); // unused by current test
931926
AgentDescription agent = m.newAgent("agent");
932927
agent.newVariable<float>("x");
@@ -947,11 +942,24 @@ TEST(Spatial2DMessageTest, Wrapped_EnvDimsNotFactor) {
947942
// Vertical pair that can interact
948943
// Top side
949944
AgentVector::Agent i1 = population[0];
950-
i1.setVariable<float>("x", 25.0f);
951-
i1.setVariable<float>("y", 25.0f);
945+
i1.setVariable<float>("x", upper.at(0));
946+
i1.setVariable<float>("y", upper.at(1));
952947
c.setPopulationData(population);
953948
c.SimulationConfig().steps = 1;
954-
EXPECT_THROW(c.simulate(), exception::DeviceError);
949+
if (exceptionExpected) {
950+
EXPECT_THROW(c.simulate(), exception::DeviceError);
951+
} else {
952+
EXPECT_NO_THROW(c.simulate());
953+
}
954+
}
955+
TEST(Spatial2DMessageTest, Wrapped_EnvDimsNotFactor) {
956+
// This tests that bug #1157 is fixed
957+
// When the interaction radius is not a factor of the width
958+
// that agent's near the max env bound all have the full interaction radius
959+
wrapped_2d_test_bounds({0, 0}, {50.1f, 50.1f}, 10, true);
960+
// also includes a number of potential edge cases to ensure that no false positives are included (#1177)
961+
wrapped_2d_test_bounds({0, 0}, {1, 1}, 0.05f, false);
962+
wrapped_2d_test_bounds({0, 0}, {2, 1}, 0.05f, false);
955963
}
956964
#else
957965
TEST(Spatial2DMessageTest, DISABLED_Wrapped_OutOfBounds) { }

tests/test_cases/runtime/messaging/test_spatial_3d.cu

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
* Tests cover:
55
* > mandatory messaging, send/recieve
66
*/
7+
#include <array>
78
#include <unordered_map>
8-
99
#include "flamegpu/flamegpu.h"
10-
1110
#include "gtest/gtest.h"
1211

1312
namespace flamegpu {
1413

15-
1614
namespace test_message_spatial3d {
1715

1816
FLAMEGPU_AGENT_FUNCTION(out_mandatory3D, MessageNone, MessageSpatial3D) {
@@ -900,7 +898,7 @@ FLAMEGPU_AGENT_FUNCTION(inWrapped3D, MessageSpatial3D, MessageNone) {
900898
void wrapped_3d_test(const float x_offset, const float y_offset, const float z_offset, const float out_of_bounds = 0) {
901899
std::unordered_map<int, unsigned int> bin_counts;
902900
// Construct model
903-
ModelDescription model("Spatial2DMessageTestModel");
901+
ModelDescription model("Spatial3DMessageTestModel");
904902
{ // Location message
905903
MessageSpatial3D::Description message = model.newMessage<MessageSpatial3D>("location");
906904
message.setMin(0 + x_offset, 0 + y_offset, 0 + z_offset);
@@ -987,15 +985,12 @@ FLAMEGPU_AGENT_FUNCTION(in_wrapped_EnvDimsNotFactor, MessageSpatial3D, MessageNo
987985
}
988986
return ALIVE;
989987
}
990-
TEST(Spatial3DMessageTest, Wrapped_EnvDimsNotFactor) {
991-
// This tests that bug #1157 is fixed
992-
// When the interaction radius is not a factor of the width
993-
// that agent's near the max env bound all have the full interaction radius
988+
void wrapped_3d_test_bounds(std::array<float, 3> lower, std::array<float, 3> upper, float radius, bool exceptionExpected) {
994989
ModelDescription m("model");
995990
MessageSpatial3D::Description message = m.newMessage<MessageSpatial3D>("location");
996-
message.setMin(0, 0, 0);
997-
message.setMax(50.1f, 50.1f, 50.1f);
998-
message.setRadius(10);
991+
message.setMin(lower.at(0), lower.at(1), lower.at(2));
992+
message.setMax(upper.at(0), upper.at(1), upper.at(2));
993+
message.setRadius(radius);
999994
message.newVariable<flamegpu::id_t>("id"); // unused by current test
1000995
AgentDescription agent = m.newAgent("agent");
1001996
agent.newVariable<float>("x");
@@ -1017,12 +1012,25 @@ TEST(Spatial3DMessageTest, Wrapped_EnvDimsNotFactor) {
10171012
// Vertical pair that can interact
10181013
// Top side
10191014
AgentVector::Agent i1 = population[0];
1020-
i1.setVariable<float>("x", 25.0f);
1021-
i1.setVariable<float>("y", 25.0f);
1022-
i1.setVariable<float>("z", 25.0f);
1015+
i1.setVariable<float>("x", upper.at(0));
1016+
i1.setVariable<float>("y", upper.at(1));
1017+
i1.setVariable<float>("z", upper.at(2));
10231018
c.setPopulationData(population);
10241019
c.SimulationConfig().steps = 1;
1025-
EXPECT_THROW(c.simulate(), exception::DeviceError);
1020+
if (exceptionExpected) {
1021+
EXPECT_THROW(c.simulate(), exception::DeviceError);
1022+
} else {
1023+
EXPECT_NO_THROW(c.simulate());
1024+
}
1025+
}
1026+
TEST(Spatial3DMessageTest, Wrapped_EnvDimsNotFactor) {
1027+
// This tests that bug #1157 is fixed
1028+
// When the interaction radius is not a factor of the width
1029+
// that agent's near the max env bound all have the full interaction radius
1030+
wrapped_3d_test_bounds({0, 0, 0}, {50.1f, 50.1f, 50.1f}, 10, true);
1031+
// also includes a number of potential edge cases to ensure that no false positives are included (#1177)
1032+
wrapped_3d_test_bounds({0, 0, 0}, {1, 1, 1}, 0.05f, false);
1033+
wrapped_3d_test_bounds({0, 0, 0}, {3, 2, 1}, 0.05f, false);
10261034
}
10271035
#else
10281036
TEST(Spatial3DMessageTest, DISABLED_Wrapped_OutOfBounds) { }

0 commit comments

Comments
 (0)