forked from menault/2026_TD3_DEV51_Qualite_Algo
Optimiser F5 avec Kadane en conservant les égalités
This commit is contained in:
@@ -113,12 +113,54 @@ static void tester_totaux_jours(void)
|
||||
assert(totaux[j] == 0);
|
||||
}
|
||||
|
||||
static long periode_reference(const long *t, int n, int *debut, int *fin)
|
||||
{
|
||||
long meilleur = t[0];
|
||||
*debut = 0;
|
||||
*fin = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = i; j < n; j++) {
|
||||
long somme = 0;
|
||||
for (int k = i; k <= j; k++)
|
||||
somme += t[k];
|
||||
if (somme > meilleur) {
|
||||
meilleur = somme;
|
||||
*debut = i;
|
||||
*fin = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
return meilleur;
|
||||
}
|
||||
|
||||
static void tester_periodes(void)
|
||||
{
|
||||
long t[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] = valeurs % 5 - 2;
|
||||
valeurs /= 5;
|
||||
}
|
||||
int debut, fin, debut_attendu, fin_attendue;
|
||||
long attendu = periode_reference(t, n, &debut_attendu, &fin_attendue);
|
||||
assert(meilleure_periode(t, n, &debut, &fin) == attendu);
|
||||
assert(debut == debut_attendu);
|
||||
assert(fin == fin_attendue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
tester_tri();
|
||||
tester_clients_distincts();
|
||||
tester_totaux_clients();
|
||||
tester_totaux_jours();
|
||||
tester_periodes();
|
||||
puts("Tests banque : OK");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user