@@ -12,20 +12,21 @@ func TestPlayerActiveWeapon(t *testing.T) {
1212 glock := NewEquipment (EqGlock )
1313 ak47 := NewEquipment (EqAK47 )
1414
15- pl := NewPlayer ( )
15+ pl := newPlayer ( 0 )
1616 pl .RawWeapons [1 ] = & knife
1717 pl .RawWeapons [2 ] = & glock
1818 pl .RawWeapons [3 ] = & ak47
1919 pl .ActiveWeaponID = 3
2020
2121 assert .Equal (t , & ak47 , pl .ActiveWeapon (), "Should have AK-47 equipped" )
2222}
23+
2324func TestPlayerWeapons (t * testing.T ) {
2425 knife := NewEquipment (EqKnife )
2526 glock := NewEquipment (EqGlock )
2627 ak47 := NewEquipment (EqAK47 )
2728
28- pl := NewPlayer ( )
29+ pl := newPlayer ( 0 )
2930 pl .RawWeapons [1 ] = & knife
3031 pl .RawWeapons [2 ] = & glock
3132 pl .RawWeapons [3 ] = & ak47
@@ -35,7 +36,7 @@ func TestPlayerWeapons(t *testing.T) {
3536}
3637
3738func TestPlayerAlive (t * testing.T ) {
38- pl := NewPlayer ( )
39+ pl := newPlayer ( 0 )
3940
4041 pl .Hp = 100
4142 assert .Equal (t , true , pl .IsAlive (), "Should be alive" )
@@ -51,20 +52,79 @@ func TestPlayerAlive(t *testing.T) {
5152}
5253
5354func TestPlayerFlashed (t * testing.T ) {
54- pl := NewPlayer ( )
55+ pl := newPlayer ( 128 )
5556
5657 assert .False (t , pl .IsBlinded (), "Should not be flashed" )
5758
5859 pl .FlashDuration = 2.3
60+ pl .FlashTick = 50
5961 assert .True (t , pl .IsBlinded (), "Should be flashed" )
6062}
6163
64+ func TestPlayerFlashed_FlashDuration_Over (t * testing.T ) {
65+ pl := newPlayer (128 * 3 )
66+
67+ pl .FlashDuration = 1.9
68+ pl .FlashTick = 128
69+ assert .False (t , pl .IsBlinded (), "Should not be flashed" )
70+ }
71+
72+ func TestPlayer_FlashDurationTime_Default (t * testing.T ) {
73+ pl := newPlayer (0 )
74+
75+ assert .Equal (t , time .Duration (0 ), pl .FlashDurationTime ())
76+ }
77+
6278func TestPlayer_FlashDurationTime (t * testing.T ) {
63- p := NewPlayer ()
79+ pl := newPlayer (0 )
80+
81+ pl .FlashDuration = 2.3
6482
65- assert .Equal (t , time .Duration (0 ), p .FlashDurationTime ())
83+ assert .Equal (t , 2300 * time .Millisecond , pl .FlashDurationTime ())
84+ }
85+
86+ func TestPlayer_FlashDurationTimeRemaining_Default (t * testing.T ) {
87+ pl := NewPlayer (0 , tickProvider (128 ))
88+
89+ assert .Equal (t , time .Duration (0 ), pl .FlashDurationTimeRemaining ())
90+ }
6691
67- p .FlashDuration = 2.3
92+ func TestPlayer_FlashDurationTimeRemaining (t * testing.T ) {
93+ pl := newPlayer (128 * 2 )
94+
95+ pl .FlashDuration = 3
96+ pl .FlashTick = 128
97+ assert .Equal (t , 2 * time .Second , pl .FlashDurationTimeRemaining ())
98+ }
99+
100+ func TestPlayer_FlashDurationTimeRemaining_Zero (t * testing.T ) {
101+ pl := newPlayer (128 * 4 )
102+
103+ pl .FlashDuration = 3
104+ pl .FlashTick = 128
105+ assert .Equal (t , time .Duration (0 ), pl .FlashDurationTimeRemaining ())
106+ }
107+
108+ func TestPlayer_FlashDurationTimeRemaining_FlashDuration_Over (t * testing.T ) {
109+ pl := newPlayer (128 * 4 )
110+
111+ pl .FlashDuration = 1
112+ pl .FlashTick = 128
113+ assert .Equal (t , time .Duration (0 ), pl .FlashDurationTimeRemaining ())
114+ }
115+
116+ func TestPlayer_FlashDurationTimeRemaining_Fallback (t * testing.T ) {
117+ pl := NewPlayer (0 , tickProvider (128 ))
118+
119+ pl .FlashDuration = 2
120+ pl .FlashTick = 128 * 2
121+ assert .Equal (t , 2 * time .Second , pl .FlashDurationTimeRemaining ())
122+ }
123+
124+ func newPlayer (tick int ) * Player {
125+ return NewPlayer (128 , tickProvider (tick ))
126+ }
68127
69- assert .Equal (t , 2300 * time .Millisecond , p .FlashDurationTime ())
128+ func tickProvider (tick int ) ingameTickProvider {
129+ return func () int { return tick }
70130}
0 commit comments