forked from menault/2026_TD3_DEV51_Qualite_Algo
Optimiser F7 par tri et parcours à deux pointeurs
This commit is contained in:
@@ -177,6 +177,36 @@ static void tester_recherches(void)
|
||||
}
|
||||
}
|
||||
|
||||
static long paires_reference(const Transaction *t, int n)
|
||||
{
|
||||
long nb = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
for (int j = i + 1; j < n; j++)
|
||||
if (t[i].montant + t[j].montant == 0)
|
||||
nb++;
|
||||
return nb;
|
||||
}
|
||||
|
||||
static void tester_paires(void)
|
||||
{
|
||||
assert(nb_paires_opposees(NULL, 0) == 0);
|
||||
Transaction t[7], original[7];
|
||||
int nb_cas = 1;
|
||||
for (int n = 1; n <= 7; n++) {
|
||||
nb_cas *= 5;
|
||||
for (int cas = 0; cas < nb_cas; cas++) {
|
||||
int valeurs = cas;
|
||||
for (int i = 0; i < n; i++) {
|
||||
t[i] = (Transaction){i, i, i, valeurs % 5 - 2};
|
||||
valeurs /= 5;
|
||||
}
|
||||
memcpy(original, t, (size_t)n * sizeof(*t));
|
||||
assert(nb_paires_opposees(t, n) == paires_reference(t, n));
|
||||
assert(memcmp(original, t, (size_t)n * sizeof(*t)) == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
tester_tri();
|
||||
@@ -185,6 +215,7 @@ int main(void)
|
||||
tester_totaux_jours();
|
||||
tester_periodes();
|
||||
tester_recherches();
|
||||
tester_paires();
|
||||
puts("Tests banque : OK");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user