AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ResetAttackTimerTest.cpp File Reference
#include "gtest/gtest.h"
#include <algorithm>
#include <cstdint>

Go to the source code of this file.

Functions

 TEST (ResetAttackTimerTest, NormalReset_TimerAtZero)
 
 TEST (ResetAttackTimerTest, NormalReset_SmallNegativeTimer)
 
 TEST (ResetAttackTimerTest, LagSpike_LargeNegativeTimer)
 
 TEST (ResetAttackTimerTest, GluthParryHaste_BurstAttack)
 
 TEST (ResetAttackTimerTest, ParryHasteFloor_MultipleParries)
 
 TEST (ResetAttackTimerTest, ConsecutiveBursts_OldFormulaChainAttacks)
 
 TEST (ResetAttackTimerTest, HasteModifier_CorrectCalculation)
 
 TEST (ResetAttackTimerTest, EdgeCase_TimerEqualsNegativeFullTime)
 
 TEST (ResetAttackTimerTest, EdgeCase_PositiveTimer)
 
 TEST (ResetAttackTimerTest, Invariant_AlwaysReturnsFullTime)
 

Function Documentation

◆ TEST() [1/10]

TEST ( ResetAttackTimerTest  ,
ConsecutiveBursts_OldFormulaChainAttacks   
)
147{
148 int32_t fullTime = CalcFullTime(1600, 0.8f); // Gluth enraged: 1280ms
149 int32_t timer = -2500; // Large lag spike
150
151 int attackCount = 0;
152 // Simulate old formula: how many attacks fire before timer > 0?
153 while (timer <= 0)
154 {
155 attackCount++;
156 timer = OldResetFormula(timer, fullTime);
157 }
158
159 // Old formula allows multiple attacks in burst
160 EXPECT_GT(attackCount, 1);
161
162 // New formula: always exactly 1 attack then timer is positive
163 timer = -2500;
164 int newAttackCount = 0;
165 // Only one attack fires (the one that triggered the reset)
166 timer = NewResetFormula(timer, fullTime);
167 if (timer > 0)
168 newAttackCount = 1;
169
170 EXPECT_EQ(newAttackCount, 1);
171 EXPECT_GT(timer, 0);
172}

◆ TEST() [2/10]

TEST ( ResetAttackTimerTest  ,
EdgeCase_PositiveTimer   
)
206{
207 int32_t fullTime = CalcFullTime(2000, 1.0f);
208 int32_t currentTimer = 500; // 500ms remaining
209
210 // Old formula: min(500 + 2000, 2000) = min(2500, 2000) = 2000
211 // Capped at full time — correct behavior
212 EXPECT_EQ(OldResetFormula(currentTimer, fullTime), 2000);
213
214 // New formula: same result
215 EXPECT_EQ(NewResetFormula(currentTimer, fullTime), 2000);
216}

◆ TEST() [3/10]

TEST ( ResetAttackTimerTest  ,
EdgeCase_TimerEqualsNegativeFullTime   
)
192{
193 int32_t fullTime = CalcFullTime(2000, 1.0f);
194 int32_t currentTimer = -2000;
195
196 // Old formula: min(-2000 + 2000, 2000) = min(0, 2000) = 0
197 // Timer exactly 0 — attack is immediately ready again
198 EXPECT_EQ(OldResetFormula(currentTimer, fullTime), 0);
199
200 // New formula: 2000 — proper delay
201 EXPECT_EQ(NewResetFormula(currentTimer, fullTime), 2000);
202}

◆ TEST() [4/10]

TEST ( ResetAttackTimerTest  ,
GluthParryHaste_BurstAttack   
)
101{
102 // Gluth: 1600ms base, 25% enrage haste
103 // GetAttackTime returns base (1600), modSpeedPct = 0.8 (25% haste)
104 int32_t fullTime = CalcFullTime(1600, 0.8f); // = 1280ms
105 EXPECT_EQ(fullTime, 1280);
106
107 // After parry-haste reduces timer to near-zero and a lag spike
108 // causes 2+ seconds of unprocessed time
109 int32_t currentTimer = -2000;
110
111 // Old formula: min(-2000 + 1280, 1280) = min(-720, 1280) = -720
112 // Timer deeply negative — immediate burst attack
113 EXPECT_LT(OldResetFormula(currentTimer, fullTime), 0);
114
115 // New formula: 1280ms — proper cooldown before next swing
116 EXPECT_EQ(NewResetFormula(currentTimer, fullTime), 1280);
117}

◆ TEST() [5/10]

TEST ( ResetAttackTimerTest  ,
HasteModifier_CorrectCalculation   
)
176{
177 // No haste: 2000ms base
178 EXPECT_EQ(CalcFullTime(2000, 1.0f), 2000);
179
180 // 25% haste (modSpeedPct = 0.8)
181 EXPECT_EQ(CalcFullTime(2000, 0.8f), 1600);
182
183 // 50% slow (modSpeedPct = 1.5)
184 EXPECT_EQ(CalcFullTime(2000, 1.5f), 3000);
185
186 // Enrage (25% haste on 1600ms base)
187 EXPECT_EQ(CalcFullTime(1600, 0.8f), 1280);
188}

◆ TEST() [6/10]

TEST ( ResetAttackTimerTest  ,
Invariant_AlwaysReturnsFullTime   
)
220{
221 int32_t fullTime = CalcFullTime(1600, 1.0f);
222
223 // Test a wide range of current timer values
224 for (int32_t timer = -10000; timer <= 10000; timer += 100)
225 EXPECT_EQ(NewResetFormula(timer, fullTime), fullTime);
226}

◆ TEST() [7/10]

TEST ( ResetAttackTimerTest  ,
LagSpike_LargeNegativeTimer   
)
87{
88 int32_t fullTime = CalcFullTime(2000, 1.0f);
89 int32_t currentTimer = -3000; // 3 second lag spike
90
91 // Old formula: min(-3000 + 2000, 2000) = min(-1000, 2000) = -1000
92 // Timer is STILL negative — attack fires immediately again!
93 EXPECT_LT(OldResetFormula(currentTimer, fullTime), 0);
94
95 // New formula: always 2000 — no burst
96 EXPECT_EQ(NewResetFormula(currentTimer, fullTime), 2000);
97}

◆ TEST() [8/10]

TEST ( ResetAttackTimerTest  ,
NormalReset_SmallNegativeTimer   
)
73{
74 int32_t fullTime = CalcFullTime(2000, 1.0f);
75 int32_t currentTimer = -50; // 50ms overshoot
76
77 // Old formula: min(-50 + 2000, 2000) = min(1950, 2000) = 1950
78 // Carries 50ms debt — next attack 50ms sooner
79 EXPECT_EQ(OldResetFormula(currentTimer, fullTime), 1950);
80
81 // New formula: always 2000 — clean reset
82 EXPECT_EQ(NewResetFormula(currentTimer, fullTime), 2000);
83}

◆ TEST() [9/10]

TEST ( ResetAttackTimerTest  ,
NormalReset_TimerAtZero   
)
62{
63 int32_t fullTime = CalcFullTime(2000, 1.0f); // 2.0s base, no haste
64 int32_t currentTimer = 0;
65
66 // Both formulas produce the same result when timer is exactly 0
67 EXPECT_EQ(OldResetFormula(currentTimer, fullTime), 2000);
68 EXPECT_EQ(NewResetFormula(currentTimer, fullTime), 2000);
69}

◆ TEST() [10/10]

TEST ( ResetAttackTimerTest  ,
ParryHasteFloor_MultipleParries   
)
121{
122 // Creature with 1600ms base, no haste
123 int32_t fullTime = CalcFullTime(1600, 1.0f);
124
125 // Parry-haste can reduce timer to 20% of base = 320ms
126 // If server tick is 200ms and timer was at 320ms, after tick: 120ms
127 // Attack fires, resetAttackTimer called with timer = 120 - 200 = -80
128 // (timer went from 120 to -80 during the next tick)
129 int32_t currentTimer = -80;
130
131 // Old formula: min(-80 + 1600, 1600) = min(1520, 1600) = 1520
132 // Small debt is carried — minor issue
133 EXPECT_EQ(OldResetFormula(currentTimer, fullTime), 1520);
134
135 // Now consider two rapid parries reducing timer to 320ms,
136 // followed by a 500ms server hiccup
137 currentTimer = 320 - 500; // = -180
138 // Old formula: min(-180 + 1600, 1600) = min(1420, 1600) = 1420
139 EXPECT_EQ(OldResetFormula(currentTimer, fullTime), 1420);
140
141 // New formula: always full time
142 EXPECT_EQ(NewResetFormula(currentTimer, fullTime), 1600);
143}