Skip to content

Commit 4f55f85

Browse files
committed
test: improve globalTimer validation and history structure checks
1 parent a7fa82d commit 4f55f85

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tests/src/Timer/TimerTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,24 @@
8080
}
8181
});
8282

83-
test('globalTimer is the wall-clock of the full computation (nested entries sum to more)', function (): void {
83+
test('globalTimer equals the span from first chrono start to last chrono end', function (): void {
8484
$this->election->parseVotes('A>B>C');
8585
$this->election->getResult('Schulze');
8686

8787
$history = $this->election->getTimerManager()->getHistory();
88-
$sumProcessIn = (float) array_sum(array_column($history, 'process_in'));
8988

9089
expect($this->election->getGlobalTimer())->toBeGreaterThan(0.0);
9190

92-
// Nested chronos overlap in time: their individual durations add up to MORE than
93-
// the outer wall-clock. globalTimer = last_end - first_start (no double-counting).
94-
expect($sumProcessIn)->toBeGreaterThanOrEqual($this->election->getGlobalTimer());
91+
// globalTimer = last_end - startDeclare.
92+
// startDeclare is the start of the very first chrono (history[0].timer_start).
93+
// The last chrono to destruct is always the outermost one (history last entry).
94+
$expectedGlobalTimer = end($history)['timer_end'] - $history[0]['timer_start'];
95+
expect($this->election->getGlobalTimer())->toEqualWithDelta($expectedGlobalTimer, 1e-9);
96+
97+
// Each individual process_in fits within the global span (no entry can be longer than total).
98+
foreach ($history as $entry) {
99+
expect($entry['process_in'])->toBeLessThanOrEqual($this->election->getGlobalTimer() + 1e-9);
100+
}
95101
});
96102

97103
test('history contains Do Pairwise entry on first vote', function (): void {

0 commit comments

Comments
 (0)