Projet Informatique Théorique 2016
Instructions et Documentation
test_automate_du_melange.c
1 /*
2  * Ce fichier fait partie d'un projet de programmation donné en Licence 3
3  * à l'Université de Bordeaux
4  *
5  * Copyright (C) 2015 Adrien Boussicault
6  *
7  * This Library is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This Library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this Library. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #include "automate.h"
23 #include "outils.h"
24 
25 void wrap_liberer_automate( Automate * aut ){
26  if( aut ){
27  liberer_automate(aut);
28  }
29 }
30 
31 int test_automate_du_melange(){
32 
33  int result = 1;
34 
35  {
36  Automate * aut1 = mot_to_automate("a");
37  Automate * aut2 = mot_to_automate("b");
38 
39  Automate * mela = creer_automate_du_melange( aut1, aut2 );
40 
41  TEST(
42  1
43  && mela
44  && le_mot_est_reconnu( mela, "ab" )
45  && le_mot_est_reconnu( mela, "ba" )
46  && ! le_mot_est_reconnu( mela, "" )
47  && ! le_mot_est_reconnu( mela, "a" )
48  && ! le_mot_est_reconnu( mela, "b" )
49  && ! le_mot_est_reconnu( mela, "aa" )
50  && ! le_mot_est_reconnu( mela, "bb" )
51  && ! le_mot_est_reconnu( mela, "aaa" )
52  && ! le_mot_est_reconnu( mela, "aab" )
53  && ! le_mot_est_reconnu( mela, "aba" )
54  && ! le_mot_est_reconnu( mela, "abb" )
55  && ! le_mot_est_reconnu( mela, "baa" )
56  && ! le_mot_est_reconnu( mela, "bab" )
57  && ! le_mot_est_reconnu( mela, "bba" )
58  && ! le_mot_est_reconnu( mela, "bbb" )
59  , result
60  );
61  wrap_liberer_automate( aut1 );
62  wrap_liberer_automate( aut2 );
63  wrap_liberer_automate( mela );
64  }
65 
66 
67  {
68  Automate * aut1 = creer_automate();
69 
70  ajouter_transition( aut1, 0, 'a', 1 );
71  ajouter_transition( aut1, 1, 'b', 2 );
72  ajouter_transition( aut1, 2, 'a', 2 );
73  ajouter_transition( aut1, 2, 'b', 1 );
74  ajouter_etat_initial( aut1, 0 );
75  ajouter_etat_final( aut1, 1 );
76 
77 
78  Automate * aut2 = creer_automate();
79 
80  ajouter_transition( aut2, 0, 'c', 1 );
81  ajouter_transition( aut2, 1, 'd', 1 );
82  ajouter_transition( aut2, 0, 'd', 0 );
83  ajouter_transition( aut2, 1, 'e', 0 );
84  ajouter_etat_initial( aut2, 0 );
85  ajouter_etat_final( aut2, 1 );
86 
87  Automate * mela = creer_automate_du_melange( aut1, aut2 );
88 
89  TEST(
90  1
91  && mela
92  && ! le_mot_est_reconnu( mela, "" )
93  && ! le_mot_est_reconnu( mela, "a" )
94  && ! le_mot_est_reconnu( mela, "b" )
95  && ! le_mot_est_reconnu( mela, "c" )
96  && ! le_mot_est_reconnu( mela, "d" )
97  && ! le_mot_est_reconnu( mela, "e" )
98 
99  && le_mot_est_reconnu( mela, "ca" )
100  && le_mot_est_reconnu( mela, "ac" )
101  && ! le_mot_est_reconnu( mela, "aa" )
102  && ! le_mot_est_reconnu( mela, "cc" )
103 
104  && le_mot_est_reconnu( mela, "cabb" )
105  && le_mot_est_reconnu( mela, "acbb" )
106  && le_mot_est_reconnu( mela, "abcb" )
107  && le_mot_est_reconnu( mela, "abbc" )
108 
109  && le_mot_est_reconnu( mela, "cda" )
110  && le_mot_est_reconnu( mela, "cad" )
111  && le_mot_est_reconnu( mela, "acd" )
112 
113  && le_mot_est_reconnu( mela, "cdeca" )
114  && le_mot_est_reconnu( mela, "cdeac" )
115  && le_mot_est_reconnu( mela, "cdaec" )
116  && le_mot_est_reconnu( mela, "cadec" )
117  && le_mot_est_reconnu( mela, "acdec" )
118 
119  && le_mot_est_reconnu( mela, "cdabb" )
120  && le_mot_est_reconnu( mela, "cadbb" )
121  && le_mot_est_reconnu( mela, "cabdb" )
122  && le_mot_est_reconnu( mela, "cabbd" )
123  && le_mot_est_reconnu( mela, "acdbb" )
124  && le_mot_est_reconnu( mela, "acbdb" )
125  && le_mot_est_reconnu( mela, "acbbd" )
126  && le_mot_est_reconnu( mela, "abcdb" )
127  && le_mot_est_reconnu( mela, "abcbd" )
128  && le_mot_est_reconnu( mela, "abbcd" )
129 
130  , result
131  );
132  wrap_liberer_automate( aut1 );
133  wrap_liberer_automate( aut2 );
134  wrap_liberer_automate( mela );
135  }
136 
137  return result;
138 }
139 
140 
141 int main(){
142 
143  if( ! test_automate_du_melange() ){ return 1; }
144 
145  return 0;
146 }
Le type d'un automate.
Definition: automate.h:39
void liberer_automate(Automate *automate)
Détruit un automate.
Definition: automate.c:168
Automate * creer_automate_du_melange(const Automate *automate1, const Automate *automate2)
Definition: automate.c:496
Automate * mot_to_automate(const char *mot)
Renvoie un automate qui reconnaît un unique mot passé en paramètre.
Definition: automate.c:462
int le_mot_est_reconnu(const Automate *automate, const char *mot)
Renvoie vrai si le mot passé en paramètre est reconu par l'automate passé en paramètre, et renvoie 0 sinon.
Definition: automate.c:442
void ajouter_transition(Automate *automate, int origine, char lettre, int fin)
Ajoute une transition à l'automate passé en paramètre.
Definition: automate.c:206
Automate * creer_automate()
Crée un automate vide, sans états, sans lettres et sans transitions.
Definition: automate.c:91
void ajouter_etat_final(Automate *automate, int etat_final)
Ajoute un état final à un automate passé en paramètre.
Definition: automate.c:226
void ajouter_etat_initial(Automate *automate, int etat_initial)
Ajoute un état initial à un automate passé en paramètre.
Definition: automate.c:233