forked from menault/2026_TD3_DEV51_Qualite_Algo
Réduire la complexité de F9 en séparant débits et crédits
This commit is contained in:
@@ -224,6 +224,55 @@ static void tester_monnaie(void)
|
||||
assert(nb_facons_rendre(s, k) == monnaie_reference(s, k));
|
||||
}
|
||||
|
||||
static int categorie_reference(const Transaction *t)
|
||||
{
|
||||
if (t->montant < 0) {
|
||||
if (t->montant < -20000) {
|
||||
if (t->jour % 7 == 5 || t->jour % 7 == 6)
|
||||
return 1;
|
||||
else
|
||||
return 2;
|
||||
} else if (t->montant < -5000) {
|
||||
return 3;
|
||||
} else {
|
||||
if (t->client % 10 == 0)
|
||||
return 4;
|
||||
return 5;
|
||||
}
|
||||
} else if (t->montant == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
if (t->montant > 30000) {
|
||||
if (t->client % 10 == 0 && t->jour % 7 < 5)
|
||||
return 6;
|
||||
return 7;
|
||||
} else if (t->montant > 10000) {
|
||||
return 8;
|
||||
} else if (t->montant > 1000) {
|
||||
if (t->jour % 30 == 0)
|
||||
return 9;
|
||||
return 10;
|
||||
}
|
||||
return 11;
|
||||
}
|
||||
}
|
||||
|
||||
static void tester_categories(void)
|
||||
{
|
||||
const long montants[] = {
|
||||
LONG_MIN, -20001, -20000, -19999, -5001, -5000, -4999, -1,
|
||||
0, 1, 999, 1000, 1001, 9999, 10000, 10001, 29999, 30000, 30001, LONG_MAX
|
||||
};
|
||||
for (size_t m = 0; m < sizeof(montants) / sizeof(*montants); m++) {
|
||||
for (int c = 0; c < 20; c++) {
|
||||
for (int j = 0; j < 210; j++) {
|
||||
Transaction t = {0, c, j, montants[m]};
|
||||
assert(categorie(&t) == categorie_reference(&t));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
tester_tri();
|
||||
@@ -234,6 +283,7 @@ int main(void)
|
||||
tester_recherches();
|
||||
tester_paires();
|
||||
tester_monnaie();
|
||||
tester_categories();
|
||||
puts("Tests banque : OK");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user