Optimiser F3 par accumulation directe des soldes clients

This commit is contained in:
rabot
2026-10-21 11:12:21 +02:00
parent 2b34b35f2b
commit 14c18a3975
3 changed files with 35 additions and 5 deletions
+23
View File
@@ -69,10 +69,33 @@ static void tester_clients_distincts(void)
assert(nb_clients_distincts(t, 1) == 1);
}
static void tester_totaux_clients(void)
{
Transaction t[] = {
{0, 0, 0, 100}, {1, NB_CLIENTS - 1, 1, -50},
{2, 0, 2, -40}, {3, NB_CLIENTS - 1, 3, 50}, {4, 7, 4, 0}
};
long totaux[NB_CLIENTS];
for (int i = 0; i < NB_CLIENTS; i++)
totaux[i] = 123;
total_par_client(t, 5, totaux);
for (int c = 0; c < NB_CLIENTS; c++) {
long attendu = 0;
for (int i = 0; i < 5; i++)
if (t[i].client == c)
attendu += t[i].montant;
assert(totaux[c] == attendu);
}
total_par_client(NULL, 0, totaux);
for (int c = 0; c < NB_CLIENTS; c++)
assert(totaux[c] == 0);
}
int main(void)
{
tester_tri();
tester_clients_distincts();
tester_totaux_clients();
puts("Tests banque : OK");
return 0;
}