diff --git a/src/.main.ml.swo b/src/.main.ml.swo new file mode 100644 index 0000000000000000000000000000000000000000..53a5604a7f95c0e97265fcd4f3943164df02e097 Binary files /dev/null and b/src/.main.ml.swo differ diff --git a/src/.main.ml.swp b/src/.main.ml.swp index c009b3db6b016b66dc3426586b056e5266320297..34d5878009e44404920fe5d97996ed8e289c0a39 100644 Binary files a/src/.main.ml.swp and b/src/.main.ml.swp differ diff --git a/src/.tests.ml.swo b/src/.tests.ml.swo new file mode 100644 index 0000000000000000000000000000000000000000..16f2b38f9a012e7c1505f9246b4b151d71156b3d Binary files /dev/null and b/src/.tests.ml.swo differ diff --git a/src/.tests.ml.swp b/src/.tests.ml.swp index 01958b360a204e56c8820bc68704b55951b4dcad..6a3ef196f6df3a463adf1906d11263a06dc9083a 100644 Binary files a/src/.tests.ml.swp and b/src/.tests.ml.swp differ diff --git a/src/tests.ml b/src/tests.ml index 607e622393442b14f2b8b0cd6daa7647b1b4e303..e2460cdacbbd9e345632c2890cdd6e123eaa7da2 100644 --- a/src/tests.ml +++ b/src/tests.ml @@ -11,7 +11,7 @@ open Printf;; exception InvalidTest;; printf "======DEBUT DES TESTS======\n";; -printf "------Tests de la phase 1------\n";; +printf "------Tests de la phase 1------\n\n";; (* Test de tourner c n roue *) printf " Fonction [tourner c n roue]\n";; printf "Test tourner une roue vide.....";; @@ -73,27 +73,136 @@ let rec test_tourner_2 n = test_tourner_2 27;; +(*Test de char_to_index i c roue *) +printf " Fonction [char_to_index i c roue]\n";; +printf "indice d'un caractère invalide 'a' dans la roue initiale.....";; + +try( let _ = char_to_index 0 'a' roue in () ) +with +| BadCharacter -> printf "fait\n" +| _ -> raise InvalidTest +;; + +let rec test_char_to_index_1 n = + if n>0 then ( + let c = List.nth roue (27-n) in ( + printf "recupération de l'indice de '%c' dans la roue initiale....." c; + if (char_to_index 0 c roue) = (27-n) + then (printf "fait\n";test_char_to_index_1 (n-1)) + else raise InvalidTest + ) + ) else ( + printf "\n" + );; + +test_char_to_index_1 27;; + (*Test de translate c roue*) +let list_test_translate = + [("E",0);("NE",1);("NNE",2);("NNNE",3);("NNNNE",4);("NNNNNE",5);("NNNNNNE",6);("NNNNNNNE",7);("NNNNNNNNE",8);("NNNNNNNNNE",9);("NNNNNNNNNNE",10);("NNNNNNNNNNNE",11);("NNNNNNNNNNNNE",12);("NNNNNNNNNNNNNE",13);("PPPPPPPPPPPPPE",13);("PPPPPPPPPPPPE",12);("PPPPPPPPPPPE",11);("PPPPPPPPPPE",10);("PPPPPPPPPE",9);("PPPPPPPPE",8);("PPPPPPPE",7);("PPPPPPE",6);("PPPPPE",5);("PPPPE",4);("PPPE",3);("PPE",2);("PE",1);("E",0)];; + printf " Fonction [translate c roue]\n";; +let rec test_translate_1 n = + if n>0 then ( + let caract = List.nth roue (27-n) in ( + printf "Traduire '%c' avec la roue initiale....." caract; + if (translate caract roue) = (List.nth list_test_translate (27-n)) + then (printf "fait\n";test_translate_1 (n-1)) + + else (raise InvalidTest) + ) + ) + else ( + printf "\n" + );; + +test_translate_1 27;; -(*Test de char_to_index i c roue *) (*test de commande (i,l) roue *) +printf " Fonction [commande (i,l) roue]\n";; + + +let m = "BONJOUR";; +printf "Envoie du message '%s'....." m;; +if (commande (1,(split_string m)) roue) = "NNENNNNNNNNNNNNNEPEPPPPENNNNNENNNNNNEPPPE" then (printf "fait\n") else (raise InvalidTest);; -(*Test de temps_lettre l*) +let m = "LES EXTRATERRESTRES";; +printf "Envoie du message '%s'....." m;; +if (commande (1,(split_string m)) roue) = "NNNNNNNNNNNNEPPPPPPPEPPPPPPPPPPPPPENNNNNNNNENNNNNEPPPPPPPPEPPPPEPPENNNNNNNNNNEPPPPPPPPENNNNNNNNNNNNENNNNNNNNNNNNNEEPPPPPPPPPPPPPEPPPPPPPPPPPPPENEPPEPPPPPPPPPPPPPEPPPPPPPPPPPPPE" then (printf "fait\n") else (raise InvalidTest);; -(*test temps_commande s*) + +let m = "ENSIIE";; +printf "Envoie du message '%s'....." m;; +if (commande (1,(split_string m)) roue) = "NNNNNENNNNNNNNNENNNNNEPPPPPPPPPPEEPPPPE" then (printf "fait\n") else (raise InvalidTest);; + +printf "\n------Tests de la phase 2------\n\n";; (*Test make_liste_index l c*) +printf " Fonction [make_list_index l c]\n";; +let list_test_index = [ + [0;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0]; + [1;0;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1]; + [2;1;0;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4;3;2]; + [3;2;1;0;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4;3]; + [4;3;2;1;0;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4]; + [5;4;3;2;1;0;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5]; + [6;5;4;3;2;1;0;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6]; + [7;6;5;4;3;2;1;0;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7]; + [8;7;6;5;4;3;2;1;0;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8]; + [9;8;7;6;5;4;3;2;1;0;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9]; + [10;9;8;7;6;5;4;3;2;1;0;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10]; + [11;10;9;8;7;6;5;4;3;2;1;0;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11]; + [12;11;10;9;8;7;6;5;4;3;2;1;0;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12]; + [13;12;11;10;9;8;7;6;5;4;3;2;1;0;26;25;24;23;22;21;20;19;18;17;16;15;14;13]; + [14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;26;25;24;23;22;21;20;19;18;17;16;15;14]; + [15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;26;25;24;23;22;21;20;19;18;17;16;15]; + [16;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;26;25;24;23;22;21;20;19;18;17;16]; + [17;16;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;26;25;24;23;22;21;20;19;18;17]; + [18;17;16;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;26;25;24;23;22;21;20;19;18]; + [19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;26;25;24;23;22;21;20;19]; + [20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;26;25;24;23;22;21;20]; + [21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;26;25;24;23;22;21]; + [22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;26;25;24;23;22]; + [23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;26;25;24;23]; + [24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;26;25;24]; + [25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;26;25]; + [26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;26]; +];; +let rec test_make_liste_index n = + if n>0 then ( + printf "liste des indices de '%c' dans chaque roue de la liste de toutes les roues possible....." (List.nth roue (27-n)); + if (make_liste_index list_test_roues (List.nth roue (27-n))) = (List.nth list_test_index (27-n)) + then (printf "fait\n"; test_make_liste_index (n-1)) + else (raise InvalidTest) + ) else ( printf "\n");; +test_make_liste_index 27;; (*Test quelle_roue l c index_init*) +printf " Fonction [quelle_roue l c i]\n";; (*test tourner_list c n i l *) +printf " Fonction [tourner_list c n i l]\n";; (*test initialize_list n a*) +printf " Fonction [initialize_list n a]\n";; (*test commande2 (n,m) *) +printf " Fonction [commande2 (n,m)]\n";; +let m = "BONJOUR";; +printf "Envoie du message '%s'....." m;; +if (commande2 (3,(split_string m))) = "NNES1PPPPPPPPPPPPEPEPPPPENNNNNENNNNNNEPPPE" then (printf "fait\n") else (raise InvalidTest);; + +let m = "LES EXTRATERRESTRES";; +printf "Envoie du message '%s'....." m;; +if (commande2 (4,(split_string m))) = + "NNNNNNNNNNNNES1NNNNNES0NNNNNNNES2ES1ES2PPPES0NEPPES3NES0NNES1ES0PPEES1ES0NENEPPES1ES0NE" then (printf "fait\n") else (raise InvalidTest);; + +let m = "ENSIIE";; +printf "Envoie du message '%s'....." m;; +if (commande2 (2,(split_string m))) = "NNNNNENNNNNNNNNENNNNNES1NNNNNNNNNEEPPPPE" then (printf "fait\n") else (raise InvalidTest);; + printf "======FIN DES TESTS=======\n";;