From 07984f97df52057ab9b36bc392b7fed614ee4845 Mon Sep 17 00:00:00 2001 From: lfainsin Date: Wed, 23 Dec 2020 14:40:04 +0000 Subject: [PATCH] =?UTF-8?q?am=C3=A9lioration=20de=20la=20robustesse=20des?= =?UTF-8?q?=20arguments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@210347 e13453a9-b01f-0410-a051-f404c4f0c485 --- src/pagerank.adb | 34 ++++++++--- src/test_tri.adb | 2 +- src/vector.adb | 154 +---------------------------------------------- src/vector.ads | 3 +- 4 files changed, 30 insertions(+), 163 deletions(-) diff --git a/src/pagerank.adb b/src/pagerank.adb index 4bf5b24..7f076e7 100644 --- a/src/pagerank.adb +++ b/src/pagerank.adb @@ -13,7 +13,8 @@ procedure pageRank is ERROR_args: Exception; ERROR_alpha: Exception; ERROR_ite: Exception; - ERROR_unexpected: Exception; + ERROR_filename: Exception; + INFO_tips: Exception; INFO_help: Exception; -- définition du type T_Double @@ -76,24 +77,30 @@ procedure pageRank is i := i + 2; put_line("parsed ite_max"); - elsif Argument(i)(Argument(i)'Last-3 .. Argument(i)'Last) = ".net" then + elsif Argument(i)'Length > 3 and then Argument(i)(Argument(i)'Last-3 .. Argument(i)'Last) = ".net" then filename := To_Unbounded_String(Argument(i)(Argument(i)'First .. Argument(i)'Last-4)); i := i + 1; put_line("parsed filename"); else new_line; - put("Option: '"); + put("Argument: '"); put(Argument(i)); put("' non reconnu"); new_line; - raise ERROR_unexpected; + raise INFO_tips; end if; exit when i > Argument_Count; + end loop; + + if Length(filename) = 0 then + raise ERROR_filename; + end if; + end if; - + new_line; put("alpha = "); put(alpha, Fore=>1, Aft=>10); new_line; put("naif = "); put(Boolean'Pos(naif), 1); new_line; @@ -108,6 +115,9 @@ procedure pageRank is raise ERROR_alpha; elsif Argument(i) = "-i" or Argument(i) = "--ite-max" then raise ERROR_ite; + else + put_line("Unexpected contrain_error"); + raise ERROR_args; end if; end get_args; @@ -268,7 +278,7 @@ procedure pageRank is -- on trie les poids par ordre décroissant, on tri en même temps les indices des pages initialize(pi_index); - sort_with_index_desc(pi, pi_index); + sort_insert_desc(pi, pi_index); -- new_line; -- put_line("sorted pi:"); @@ -301,6 +311,7 @@ begin put_line("args OK"); -- on ouvre le fichier .net + put("ouverture de: "); put(To_String(filename & ".net")); new_line; open(file, In_File, To_String(filename & ".net")); put_line("file OK"); @@ -327,9 +338,6 @@ exception put_line("Erreur lors de la saisi de la commande."); put_line("Usage: pagerank [-P] [-i max_iterations] [-a alpha] [-h] fichier_reseau.net"); - when ERROR_unexpected => - put_line("Essayez 'pagerank --help' pour plus d'informations."); - when ERROR_alpha => new_line; put_line("Erreur lors de la saisi de alpha."); @@ -340,6 +348,14 @@ exception put_line("Erreur lors de la saisi de ite_max."); put_line("ite_max ∈ ⟦0, 150⟧"); + when ERROR_filename => + new_line; + put_line("Erreur lors de la saisi du fichier réseau."); + put_line("Veuillez rentrer un nom valide."); + + when INFO_tips => + put_line("Essayez 'pagerank --help' pour plus d'informations."); + when INFO_help => new_line; put_line("Usage: pagerank [OPTIONS] network.net"); diff --git a/src/test_tri.adb b/src/test_tri.adb index 65cd38f..9901495 100644 --- a/src/test_tri.adb +++ b/src/test_tri.adb @@ -32,7 +32,7 @@ begin put_line("avant:"); put(vec); new_line; - Quick_Sort(vec); + quicksort(vec, vec_index, 0, N-1); put_line("après:"); put(vec); diff --git a/src/vector.adb b/src/vector.adb index 1bd2d1c..84cc796 100644 --- a/src/vector.adb +++ b/src/vector.adb @@ -50,7 +50,7 @@ package body vector is end loop; end put; - procedure sort_with_index_desc(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural) is + procedure sort_insert_desc(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural) is tmp_Element: T_Element; tmp_Natural: Natural; max: Natural; @@ -72,48 +72,8 @@ package body vector is vec_index(max) := tmp_Natural; end if; end loop; - end sort_with_index_desc; + end sort_insert_desc; -<<<<<<< .mine -||||||| .r210321 - procedure quicksort(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural; a, b: in Natural) is - pivot: Natural := a; - i: Natural := a; - tmp: T_Element; - begin - if b - a > 1 then - for j in a..b loop - if vec(j) <= vec(pivot) then - i := i + 1; - tmp := vec(i); - vec(i) := vec(j); - vec(j) := tmp; - else - null; - end if; - end loop; - - tmp := vec(i); - vec(i) := vec(pivot); - vec(pivot) := tmp; - - pivot := i; - - put(vec); new_line; - - if pivot - 1 > 0 then - quicksort(vec, vec_index, a, pivot-1); - elsif b - pivot - 1 > 0 then - quicksort(vec, vec_index, pivot+1, b); - else - null; - end if; - else - null; - end if; - end quicksort; - -======= procedure quicksort(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural; a, b: in Natural) is pivot: Natural := a; i: Natural := a; @@ -151,114 +111,4 @@ package body vector is end if; end quicksort; ->>>>>>> .r210345 end vector; -<<<<<<< .mine -||||||| .r210321 - --- def triRapide(L): # Quicksort --- if len(L) <= 1: --- return L --- pvt = L[0] --- L1, L2 = [], [] --- for i in range(1, len(L)): --- if L[i] < pvt: --- L1.append(L[i]) --- else: --- L2.append(L[i]) --- return triRapide(L1) + [pvt] + triRapide(L2) - --- procedure Quick_Sort (A : in out Element_Array) is - --- procedure Swap(Left, Right : Index) is --- Temp : Element := A (Left); --- begin --- A (Left) := A (Right); --- A (Right) := Temp; --- end Swap; - --- begin --- if A'Length > 1 then --- declare --- Pivot_Value : Element := A (A'First); --- Right : Index := A'Last; --- Left : Index := A'First; --- begin --- loop --- while Left < Right and not (Pivot_Value < A (Left)) loop --- Left := Index'Succ (Left); --- end loop; --- while Pivot_Value < A (Right) loop --- Right := Index'Pred (Right); --- end loop; --- exit when Right <= Left; --- Swap (Left, Right); --- Left := Index'Succ (Left); --- Right := Index'Pred (Right); --- end loop; --- if Right = A'Last then --- Right := Index'Pred (Right); --- Swap (A'First, A'Last); --- end if; --- if Left = A'First then --- Left := Index'Succ (Left); --- end if; --- Quick_Sort (A (A'First .. Right)); --- Quick_Sort (A (Left .. A'Last)); --- end; --- end if; --- end Quick_Sort;======= - --- def triRapide(L): # Quicksort --- if len(L) <= 1: --- return L --- pvt = L[0] --- L1, L2 = [], [] --- for i in range(1, len(L)): --- if L[i] < pvt: --- L1.append(L[i]) --- else: --- L2.append(L[i]) --- return triRapide(L1) + [pvt] + triRapide(L2) - --- procedure Quick_Sort (A : in out Element_Array) is - --- procedure Swap(Left, Right : Index) is --- Temp : Element := A (Left); --- begin --- A (Left) := A (Right); --- A (Right) := Temp; --- end Swap; - --- begin --- if A'Length > 1 then --- declare --- Pivot_Value : Element := A (A'First); --- Right : Index := A'Last; --- Left : Index := A'First; --- begin --- loop --- while Left < Right and not (Pivot_Value < A (Left)) loop --- Left := Index'Succ (Left); --- end loop; --- while Pivot_Value < A (Right) loop --- Right := Index'Pred (Right); --- end loop; --- exit when Right <= Left; --- Swap (Left, Right); --- Left := Index'Succ (Left); --- Right := Index'Pred (Right); --- end loop; --- if Right = A'Last then --- Right := Index'Pred (Right); --- Swap (A'First, A'Last); --- end if; --- if Left = A'First then --- Left := Index'Succ (Left); --- end if; --- Quick_Sort (A (A'First .. Right)); --- Quick_Sort (A (Left .. A'Last)); --- end; --- end if; --- end Quick_Sort; ->>>>>>> .r210345 diff --git a/src/vector.ads b/src/vector.ads index 02b6bc5..4f983de 100644 --- a/src/vector.ads +++ b/src/vector.ads @@ -24,6 +24,7 @@ package Vector is procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur_Element); procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur_Natural); - procedure sort_with_index_desc(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural); + procedure sort_insert_desc(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural); + procedure quicksort(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural; a, b: in Natural); end Vector;