@@ -381,3 +381,74 @@ fn test_drift_direction_analysis() {
381381 }
382382 }
383383}
384+
385+ #[ test]
386+ fn test_entity_data_format ( ) {
387+ let sim = Simulation :: new ( 100.0 ) ;
388+ let entities = sim. get_entities ( ) ;
389+
390+ // Each entity should have 6 components: x, y, radius, r, g, b
391+ for ( x, y, radius, r, g, b) in & entities {
392+ // Position should be within world bounds
393+ assert ! ( * x >= -50.0 && * x <= 50.0 , "x={} out of bounds" , x) ;
394+ assert ! ( * y >= -50.0 && * y <= 50.0 , "y={} out of bounds" , y) ;
395+
396+ // Radius should be positive
397+ assert ! ( * radius > 0.0 , "radius should be positive" ) ;
398+
399+ // Colors should be in 0-1 range
400+ assert ! ( * r >= 0.0 && * r <= 1.0 , "r={} out of color range" , r) ;
401+ assert ! ( * g >= 0.0 && * g <= 1.0 , "g={} out of color range" , g) ;
402+ assert ! ( * b >= 0.0 && * b <= 1.0 , "b={} out of color range" , b) ;
403+ }
404+ }
405+
406+ #[ test]
407+ fn test_entity_buffer_conversion ( ) {
408+ // Test the buffer format used by WebGPU renderer
409+ // Simulates what update_entity_buffer does in lib.rs
410+ let sim = Simulation :: new ( 100.0 ) ;
411+ let entities = sim. get_entities ( ) ;
412+
413+ // Convert to flat buffer (same as update_entity_buffer)
414+ let mut buffer: Vec < f32 > = Vec :: with_capacity ( entities. len ( ) * 6 ) ;
415+ for ( x, y, radius, r, g, b) in entities. iter ( ) {
416+ buffer. push ( * x) ;
417+ buffer. push ( * y) ;
418+ buffer. push ( * radius) ;
419+ buffer. push ( * r) ;
420+ buffer. push ( * g) ;
421+ buffer. push ( * b) ;
422+ }
423+
424+ // Buffer length should be 6 * entity count
425+ assert_eq ! ( buffer. len( ) , entities. len( ) * 6 ) ;
426+
427+ // Entity count calculation should match
428+ let entity_count = buffer. len ( ) / 6 ;
429+ assert_eq ! ( entity_count, entities. len( ) ) ;
430+
431+ // Verify data integrity by reading back
432+ for ( i, ( x, y, radius, r, g, b) ) in entities. iter ( ) . enumerate ( ) {
433+ let base = i * 6 ;
434+ assert_eq ! ( buffer[ base] , * x) ;
435+ assert_eq ! ( buffer[ base + 1 ] , * y) ;
436+ assert_eq ! ( buffer[ base + 2 ] , * radius) ;
437+ assert_eq ! ( buffer[ base + 3 ] , * r) ;
438+ assert_eq ! ( buffer[ base + 4 ] , * g) ;
439+ assert_eq ! ( buffer[ base + 5 ] , * b) ;
440+ }
441+ }
442+
443+ #[ test]
444+ fn test_update_config ( ) {
445+ let mut sim = Simulation :: new ( 100.0 ) ;
446+ let original_velocity = sim. config . physics . max_velocity ;
447+
448+ let mut new_config = sim. config . clone ( ) ;
449+ new_config. physics . max_velocity = 5.0 ;
450+ sim. update_config ( new_config) ;
451+
452+ assert_ne ! ( sim. config. physics. max_velocity, original_velocity) ;
453+ assert_eq ! ( sim. config. physics. max_velocity, 5.0 ) ;
454+ }
0 commit comments