@@ -12,7 +12,9 @@ namespace flamegpu {
12
12
namespace test_io {
13
13
bool validate_has_run = false ;
14
14
// Used by MiniSim3 where file name is required during a host function
15
- const char * current_test_file_name = nullptr ;
15
+ const char *current_test_file_name = " " ;
16
+ // JSON IO converts inf to nan, so requires validation to change pre/post load
17
+ bool is_loaded = false ;
16
18
const char *XML_FILE_NAME = " test.xml" ;
17
19
const char *JSON_FILE_NAME = " test.json" ;
18
20
const char *BIN_FILE_NAME = " test.bin" ;
@@ -52,12 +54,20 @@ FLAMEGPU_STEP_FUNCTION(VALIDATE_ENV) {
52
54
// Limits
53
55
EXPECT_TRUE (std::isnan (FLAMEGPU->environment .getProperty <float >(" float_qnan" )));
54
56
EXPECT_TRUE (std::isnan (FLAMEGPU->environment .getProperty <float >(" float_snan" )));
55
- EXPECT_EQ (FLAMEGPU->environment .getProperty <float >(" float_inf" ), std::numeric_limits<float >::infinity ());
56
- EXPECT_EQ (FLAMEGPU->environment .getProperty <float >(" float_inf_neg" ), -std::numeric_limits<float >::infinity ());
57
57
EXPECT_TRUE (std::isnan (FLAMEGPU->environment .getProperty <double >(" double_qnan" )));
58
58
EXPECT_TRUE (std::isnan (FLAMEGPU->environment .getProperty <double >(" double_snan" )));
59
- EXPECT_EQ (FLAMEGPU->environment .getProperty <double >(" double_inf" ), std::numeric_limits<double >::infinity ());
60
- EXPECT_EQ (FLAMEGPU->environment .getProperty <double >(" double_inf_neg" ), -std::numeric_limits<double >::infinity ());
59
+ if (std::string (current_test_file_name) == JSON_FILE_NAME && is_loaded) {
60
+ // JSON spec does not support NaN/Inf, so they are all represented as Null values, which we load as nan
61
+ EXPECT_TRUE (std::isnan (FLAMEGPU->environment .getProperty <float >(" float_inf" )));
62
+ EXPECT_TRUE (std::isnan (FLAMEGPU->environment .getProperty <float >(" float_inf_neg" )));
63
+ EXPECT_TRUE (std::isnan (FLAMEGPU->environment .getProperty <double >(" double_inf" )));
64
+ EXPECT_TRUE (std::isnan (FLAMEGPU->environment .getProperty <double >(" double_inf_neg" )));
65
+ } else {
66
+ EXPECT_EQ (FLAMEGPU->environment .getProperty <float >(" float_inf" ), std::numeric_limits<float >::infinity ());
67
+ EXPECT_EQ (FLAMEGPU->environment .getProperty <float >(" float_inf_neg" ), -std::numeric_limits<float >::infinity ());
68
+ EXPECT_EQ (FLAMEGPU->environment .getProperty <double >(" double_inf" ), std::numeric_limits<double >::infinity ());
69
+ EXPECT_EQ (FLAMEGPU->environment .getProperty <double >(" double_inf_neg" ), -std::numeric_limits<double >::infinity ());
70
+ }
61
71
}
62
72
FLAMEGPU_STEP_FUNCTION (RESET_ENV) {
63
73
FLAMEGPU->environment .setProperty <float >(" float" , {});
@@ -204,7 +214,9 @@ class MiniSim {
204
214
::remove (test_file.c_str());
205
215
}
206
216
void run (const std::string &test_file_name) {
217
+ current_test_file_name = test_file_name.c_str ();
207
218
this ->test_file = test_file_name;
219
+ is_loaded = false ;
208
220
// Assertions for limits
209
221
ASSERT_TRUE (std::numeric_limits<float >::has_quiet_NaN);
210
222
ASSERT_TRUE (std::numeric_limits<float >::has_signaling_NaN);
@@ -407,12 +419,20 @@ class MiniSim {
407
419
// Limit values
408
420
EXPECT_TRUE (std::isnan (agent_in.getVariable <float >(" float_qnan" )));
409
421
EXPECT_TRUE (std::isnan (agent_in.getVariable <float >(" float_snan" )));
410
- EXPECT_EQ (agent_in.getVariable <float >(" float_inf" ), std::numeric_limits<float >::infinity ());
411
- EXPECT_EQ (agent_in.getVariable <float >(" float_inf_neg" ), -std::numeric_limits<float >::infinity ());
412
422
EXPECT_TRUE (std::isnan (agent_in.getVariable <double >(" double_qnan" )));
413
423
EXPECT_TRUE (std::isnan (agent_in.getVariable <double >(" double_snan" )));
414
- EXPECT_EQ (agent_in.getVariable <double >(" double_inf" ), std::numeric_limits<double >::infinity ());
415
- EXPECT_EQ (agent_in.getVariable <double >(" double_inf_neg" ), -std::numeric_limits<double >::infinity ());
424
+ if (test_file_name == JSON_FILE_NAME) {
425
+ // JSON spec does not support NaN/Inf, so they are all represented as Null values, which we load as nan
426
+ EXPECT_TRUE (std::isnan (agent_in.getVariable <float >(" float_inf" )));
427
+ EXPECT_TRUE (std::isnan (agent_in.getVariable <float >(" float_inf_neg" )));
428
+ EXPECT_TRUE (std::isnan (agent_in.getVariable <double >(" double_inf" )));
429
+ EXPECT_TRUE (std::isnan (agent_in.getVariable <double >(" double_inf_neg" )));
430
+ } else {
431
+ EXPECT_EQ (agent_in.getVariable <float >(" float_inf" ), std::numeric_limits<float >::infinity ());
432
+ EXPECT_EQ (agent_in.getVariable <float >(" float_inf_neg" ), -std::numeric_limits<float >::infinity ());
433
+ EXPECT_EQ (agent_in.getVariable <double >(" double_inf" ), std::numeric_limits<double >::infinity ());
434
+ EXPECT_EQ (agent_in.getVariable <double >(" double_inf_neg" ), -std::numeric_limits<double >::infinity ());
435
+ }
416
436
}
417
437
// Valid agent array vars
418
438
ASSERT_EQ (pop_b_in.size (), pop_b_out.size ());
@@ -452,6 +472,7 @@ class MiniSim {
452
472
// Reload env vars from file
453
473
am.SimulationConfig ().input_file = test_file_name;
454
474
am.applyConfig ();
475
+ is_loaded = true ;
455
476
// Step again, check they have been loaded
456
477
validate_has_run = false ;
457
478
am.step ();
@@ -477,6 +498,7 @@ class MiniSim {
477
498
// Perform import
478
499
const char *argv[3 ] = { " prog.exe" , " --in" , test_file_name.c_str ()};
479
500
EXPECT_NO_THROW (am.initialise (sizeof (argv) / sizeof (char *), argv));
501
+ is_loaded = true ;
480
502
// Validate config matches
481
503
EXPECT_EQ (am.getSimulationConfig ().input_file , test_file_name);
482
504
EXPECT_EQ (am.getSimulationConfig ().step_log_file , " step" );
@@ -515,12 +537,20 @@ class MiniSim {
515
537
// Limit values
516
538
EXPECT_TRUE (std::isnan (agent_in.getVariable <float >(" float_qnan" )));
517
539
EXPECT_TRUE (std::isnan (agent_in.getVariable <float >(" float_snan" )));
518
- EXPECT_EQ (agent_in.getVariable <float >(" float_inf" ), std::numeric_limits<float >::infinity ());
519
- EXPECT_EQ (agent_in.getVariable <float >(" float_inf_neg" ), -std::numeric_limits<float >::infinity ());
520
540
EXPECT_TRUE (std::isnan (agent_in.getVariable <double >(" double_qnan" )));
521
541
EXPECT_TRUE (std::isnan (agent_in.getVariable <double >(" double_snan" )));
522
- EXPECT_EQ (agent_in.getVariable <double >(" double_inf" ), std::numeric_limits<double >::infinity ());
523
- EXPECT_EQ (agent_in.getVariable <double >(" double_inf_neg" ), -std::numeric_limits<double >::infinity ());
542
+ if (test_file_name == JSON_FILE_NAME) {
543
+ // JSON spec does not support NaN/Inf, so they are all represented as Null values, which we load as nan
544
+ EXPECT_TRUE (std::isnan (agent_in.getVariable <float >(" float_inf" )));
545
+ EXPECT_TRUE (std::isnan (agent_in.getVariable <float >(" float_inf_neg" )));
546
+ EXPECT_TRUE (std::isnan (agent_in.getVariable <double >(" double_inf" )));
547
+ EXPECT_TRUE (std::isnan (agent_in.getVariable <double >(" double_inf_neg" )));
548
+ } else {
549
+ EXPECT_EQ (agent_in.getVariable <float >(" float_inf" ), std::numeric_limits<float >::infinity ());
550
+ EXPECT_EQ (agent_in.getVariable <float >(" float_inf_neg" ), -std::numeric_limits<float >::infinity ());
551
+ EXPECT_EQ (agent_in.getVariable <double >(" double_inf" ), std::numeric_limits<double >::infinity ());
552
+ EXPECT_EQ (agent_in.getVariable <double >(" double_inf_neg" ), -std::numeric_limits<double >::infinity ());
553
+ }
524
554
}
525
555
// Valid agent array vars
526
556
ASSERT_EQ (pop_b_in.size (), pop_b_out.size ());
0 commit comments