@@ -290,3 +290,263 @@ pub struct TripleAxisData {
290290 /// The `triple` of the action in the `FixedMain` schedule
291291 pub fixed_update_triple : Vec3 ,
292292}
293+
294+ #[ cfg( test) ]
295+ mod tests {
296+ use crate :: buttonlike:: ButtonState ;
297+
298+ #[ test]
299+ fn test_tick_triple_axis ( ) {
300+ use super :: ActionData ;
301+ use super :: ActionKindData ;
302+ use super :: TripleAxisData ;
303+ use bevy:: platform:: time:: Instant ;
304+
305+ let mut action_data = ActionData {
306+ disabled : false ,
307+ kind_data : ActionKindData :: TripleAxis ( TripleAxisData {
308+ triple : bevy:: math:: Vec3 :: new ( 1.0 , 2.0 , 3.0 ) ,
309+ update_triple : bevy:: math:: Vec3 :: new ( 4.0 , 5.0 , 6.0 ) ,
310+ fixed_update_triple : bevy:: math:: Vec3 :: new ( 7.0 , 8.0 , 9.0 ) ,
311+ } ) ,
312+ } ;
313+
314+ let previous_instant = Instant :: now ( ) ;
315+ let current_instant = previous_instant + std:: time:: Duration :: from_secs ( 1 ) ;
316+
317+ action_data. tick ( current_instant, previous_instant) ;
318+
319+ if let ActionKindData :: TripleAxis ( data) = & action_data. kind_data {
320+ assert_eq ! ( data. triple, bevy:: math:: Vec3 :: new( 1.0 , 2.0 , 3.0 ) ) ;
321+ } else {
322+ panic ! ( "Expected TripleAxisData" ) ;
323+ }
324+ }
325+
326+ #[ test]
327+ fn test_swap_update_to_update_state_triple_axis ( ) {
328+ use super :: ActionData ;
329+ use super :: ActionKindData ;
330+ use super :: TripleAxisData ;
331+ use bevy:: math:: Vec3 ;
332+
333+ let mut action_data = ActionData {
334+ disabled : false ,
335+ kind_data : ActionKindData :: TripleAxis ( TripleAxisData {
336+ triple : Vec3 :: new ( 1.0 , 2.0 , 3.0 ) ,
337+ update_triple : Vec3 :: new ( 4.0 , 5.0 , 6.0 ) ,
338+ fixed_update_triple : Vec3 :: new ( 7.0 , 8.0 , 9.0 ) ,
339+ } ) ,
340+ } ;
341+
342+ action_data. kind_data . swap_to_update_state ( ) ;
343+
344+ if let ActionKindData :: TripleAxis ( data) = & action_data. kind_data {
345+ assert_eq ! ( data. triple, Vec3 :: new( 4.0 , 5.0 , 6.0 ) ) ;
346+ } else {
347+ panic ! ( "Expected TripleAxisData" ) ;
348+ }
349+ }
350+
351+ #[ test]
352+ fn test_swap_to_fixed_update_state_triple_axis ( ) {
353+ use super :: ActionData ;
354+ use super :: ActionKindData ;
355+ use super :: TripleAxisData ;
356+ use bevy:: math:: Vec3 ;
357+
358+ let mut action_data = ActionData {
359+ disabled : false ,
360+ kind_data : ActionKindData :: TripleAxis ( TripleAxisData {
361+ triple : Vec3 :: new ( 1.0 , 2.0 , 3.0 ) ,
362+ update_triple : Vec3 :: new ( 4.0 , 5.0 , 6.0 ) ,
363+ fixed_update_triple : Vec3 :: new ( 7.0 , 8.0 , 9.0 ) ,
364+ } ) ,
365+ } ;
366+
367+ action_data. kind_data . swap_to_fixed_update_state ( ) ;
368+
369+ if let ActionKindData :: TripleAxis ( data) = & action_data. kind_data {
370+ assert_eq ! ( data. triple, Vec3 :: new( 7.0 , 8.0 , 9.0 ) ) ;
371+ } else {
372+ panic ! ( "Expected TripleAxisData" ) ;
373+ }
374+ }
375+
376+ #[ test]
377+ fn test_set_update_state_from_state_axis ( ) {
378+ use super :: ActionData ;
379+ use super :: ActionKindData ;
380+ use super :: AxisData ;
381+
382+ let mut action_data = ActionData {
383+ disabled : false ,
384+ kind_data : ActionKindData :: Axis ( AxisData {
385+ value : 1.0 ,
386+ update_value : 2.0 ,
387+ fixed_update_value : 3.0 ,
388+ } ) ,
389+ } ;
390+
391+ action_data. kind_data . set_update_state_from_state ( ) ;
392+
393+ if let ActionKindData :: Axis ( data) = & action_data. kind_data {
394+ assert_eq ! ( data. update_value, 1.0 ) ;
395+ } else {
396+ panic ! ( "Expected AxisData" ) ;
397+ }
398+ }
399+
400+ #[ test]
401+ fn test_set_update_state_from_state_dual_axis ( ) {
402+ use super :: ActionData ;
403+ use super :: ActionKindData ;
404+ use super :: DualAxisData ;
405+ use bevy:: math:: Vec2 ;
406+
407+ let mut action_data = ActionData {
408+ disabled : false ,
409+ kind_data : ActionKindData :: DualAxis ( DualAxisData {
410+ pair : Vec2 :: new ( 1.0 , 2.0 ) ,
411+ update_pair : Vec2 :: new ( 3.0 , 4.0 ) ,
412+ fixed_update_pair : Vec2 :: new ( 5.0 , 6.0 ) ,
413+ } ) ,
414+ } ;
415+
416+ action_data. kind_data . set_update_state_from_state ( ) ;
417+
418+ if let ActionKindData :: DualAxis ( data) = & action_data. kind_data {
419+ assert_eq ! ( data. update_pair, Vec2 :: new( 1.0 , 2.0 ) ) ;
420+ } else {
421+ panic ! ( "Expected DualAxisData" ) ;
422+ }
423+ }
424+
425+ #[ test]
426+ fn test_set_update_state_from_state_triple_axis ( ) {
427+ use super :: ActionData ;
428+ use super :: ActionKindData ;
429+ use super :: TripleAxisData ;
430+ use bevy:: math:: Vec3 ;
431+
432+ let mut action_data = ActionData {
433+ disabled : false ,
434+ kind_data : ActionKindData :: TripleAxis ( TripleAxisData {
435+ triple : Vec3 :: new ( 1.0 , 2.0 , 3.0 ) ,
436+ update_triple : Vec3 :: new ( 4.0 , 5.0 , 6.0 ) ,
437+ fixed_update_triple : Vec3 :: new ( 7.0 , 8.0 , 9.0 ) ,
438+ } ) ,
439+ } ;
440+
441+ action_data. kind_data . set_update_state_from_state ( ) ;
442+
443+ if let ActionKindData :: TripleAxis ( data) = & action_data. kind_data {
444+ assert_eq ! ( data. update_triple, Vec3 :: new( 1.0 , 2.0 , 3.0 ) ) ;
445+ } else {
446+ panic ! ( "Expected TripleAxisData" ) ;
447+ }
448+ }
449+
450+ #[ test]
451+ fn test_set_fixed_update_state_from_state_button ( ) {
452+ use super :: ActionData ;
453+ use super :: ActionKindData ;
454+ use super :: ButtonData ;
455+
456+ let mut action_data = ActionData {
457+ disabled : false ,
458+ kind_data : ActionKindData :: Button ( ButtonData {
459+ state : ButtonState :: Pressed ,
460+ update_state : ButtonState :: JustPressed ,
461+ fixed_update_state : ButtonState :: Released ,
462+ value : 1.0 ,
463+ update_value : 0.5 ,
464+ fixed_update_value : 0.0 ,
465+ #[ cfg( feature = "timing" ) ]
466+ timing : Default :: default ( ) ,
467+ } ) ,
468+ } ;
469+
470+ action_data. kind_data . set_fixed_update_state_from_state ( ) ;
471+ if let ActionKindData :: Button ( data) = & action_data. kind_data {
472+ assert_eq ! ( data. fixed_update_state, ButtonState :: Pressed ) ;
473+ assert_eq ! ( data. fixed_update_value, 1.0 ) ;
474+ } else {
475+ panic ! ( "Expected ButtonData" ) ;
476+ }
477+ }
478+
479+ #[ test]
480+ fn test_set_fixed_update_state_from_state_axis ( ) {
481+ use super :: ActionData ;
482+ use super :: ActionKindData ;
483+ use super :: AxisData ;
484+
485+ let mut action_data = ActionData {
486+ disabled : false ,
487+ kind_data : ActionKindData :: Axis ( AxisData {
488+ value : 1.0 ,
489+ update_value : 2.0 ,
490+ fixed_update_value : 3.0 ,
491+ } ) ,
492+ } ;
493+
494+ action_data. kind_data . set_fixed_update_state_from_state ( ) ;
495+
496+ if let ActionKindData :: Axis ( data) = & action_data. kind_data {
497+ assert_eq ! ( data. fixed_update_value, 1.0 ) ;
498+ } else {
499+ panic ! ( "Expected AxisData" ) ;
500+ }
501+ }
502+
503+ #[ test]
504+ fn test_set_fixed_update_state_from_state_dual_axis ( ) {
505+ use super :: ActionData ;
506+ use super :: ActionKindData ;
507+ use super :: DualAxisData ;
508+ use bevy:: math:: Vec2 ;
509+
510+ let mut action_data = ActionData {
511+ disabled : false ,
512+ kind_data : ActionKindData :: DualAxis ( DualAxisData {
513+ pair : Vec2 :: new ( 1.0 , 2.0 ) ,
514+ update_pair : Vec2 :: new ( 3.0 , 4.0 ) ,
515+ fixed_update_pair : Vec2 :: new ( 5.0 , 6.0 ) ,
516+ } ) ,
517+ } ;
518+
519+ action_data. kind_data . set_fixed_update_state_from_state ( ) ;
520+
521+ if let ActionKindData :: DualAxis ( data) = & action_data. kind_data {
522+ assert_eq ! ( data. fixed_update_pair, Vec2 :: new( 1.0 , 2.0 ) ) ;
523+ } else {
524+ panic ! ( "Expected DualAxisData" ) ;
525+ }
526+ }
527+
528+ #[ test]
529+ fn test_set_fixed_update_state_from_state_triple_axis ( ) {
530+ use super :: ActionData ;
531+ use super :: ActionKindData ;
532+ use super :: TripleAxisData ;
533+ use bevy:: math:: Vec3 ;
534+
535+ let mut action_data = ActionData {
536+ disabled : false ,
537+ kind_data : ActionKindData :: TripleAxis ( TripleAxisData {
538+ triple : Vec3 :: new ( 1.0 , 2.0 , 3.0 ) ,
539+ update_triple : Vec3 :: new ( 4.0 , 5.0 , 6.0 ) ,
540+ fixed_update_triple : Vec3 :: new ( 7.0 , 8.0 , 9.0 ) ,
541+ } ) ,
542+ } ;
543+
544+ action_data. kind_data . set_fixed_update_state_from_state ( ) ;
545+
546+ if let ActionKindData :: TripleAxis ( data) = & action_data. kind_data {
547+ assert_eq ! ( data. fixed_update_triple, Vec3 :: new( 1.0 , 2.0 , 3.0 ) ) ;
548+ } else {
549+ panic ! ( "Expected TripleAxisData" ) ;
550+ }
551+ }
552+ }
0 commit comments