Bonjour
main.c/* ISEN 3 - TP 2 de C */
/* jpdelx - octobre 2014 */
#include <stdio.h>
#include <string.h>
#include "seatest.h"
#include "seatest.c"
#include "mesFonctions.h"
#include "mesFonctions.c"
/*----------[ mes Tests Unitaires ]----------*/
void test_tp2()
{
puts("** T.U. pour isdigit() **");
assert_true(isdigit('0'));
assert_false(isdigit('0'));
assert_true(isdigit('A'));
assert_false(isdigit('A'));
puts("** T.U. pour my_isdigit() **");
assert_true(my_isdigit('0'));
assert_false(my_isdigit('0'));
assert_true(my_isdigit('A'));
assert_false(my_isdigit('A'));
puts("** T.U. pour toupper() **");
assert_true(toupper('a')=='A');
assert_false(toupper('a')=='A');
assert_true(toupper('z')!='Z');
assert_false(toupper('z')!='Z');
puts("** T.U. pour my_toupper() **");
assert_true(my_toupper('a')=='A');
assert_false(my_toupper('a')=='A');
assert_true(my_toupper('z')!='Z');
assert_false(my_toupper('z')!='Z');
puts("** T.U. pour strcpy() **");
char chaine[255];
strcpy(chaine,"jpdelx");
assert_string_equal(chaine,"jpdelx");
assert_true(!strcmp(chaine,"jpdelx")); /* /!\ strcmp retourne FAUX si les 2 chaînes sont identiques */
assert_true(strcmp(chaine,"jpdelx"));
puts("** T.U. pour my_strcpy() **");
my_strcpy(chaine,"jpdelx");
assert_string_equal(chaine,"jpdelx");
assert_true(!strcmp(chaine,"jpdelx")); /* /!\ strcmp retourne FAUX si les 2 chaînes sont identiques */
assert_true(strcmp(chaine,"jpdelx"));
puts("** T.U. pour strlen() **");
assert_int_equal(strlen("jpdelx"),6);
assert_int_equal(strlen("J.Phil. DELCROIX"),123);
puts("** T.U. pour my_strlen() **");
assert_int_equal(my_strlen("jpdelx"),6);
assert_int_equal(my_strlen("J.Phil. DELCROIX"),123);
}
/* procédure d'installation des T.U. */
void test_fixture_tp2( void )
{
test_fixture_start();
run_test(test_tp2);
test_fixture_end();
}
/* suite de l'installation des T.U. */
void all_tests( void )
{
test_fixture_tp2();
}
/* procédure principale avec exécution des T.U. */
int main(){
/* Exemple d'utilisation de isdigit() */
char symbole;
char* chaine;
symbole='0';
puts("** isdigit() **");
if( isdigit(symbole)) printf("%c est un digit\n",symbole); else printf("%c n'est pas un digit\n",symbole);
symbole='A';
if( isdigit(symbole)) printf("%c est un digit\n",symbole); else printf("%c n'est pas un digit\n",symbole);
/* Exemple d'utilisation de my_isdigit() */
puts("** my_isdigit() **");
symbole='0';
if( my_isdigit(symbole)) printf("%c est un digit\n",symbole); else printf("%c n'est pas un digit\n",symbole);
symbole='A';
if( my_isdigit(symbole)) printf("%c est un digit\n",symbole); else printf("%c n'est pas un digit\n",symbole);
/* Exemple d'utilisation de toupper() */
puts("** toupper() **");
symbole='a';
printf("minuscule : %c => majuscule %c\n",symbole,toupper(symbole));
symbole='z';
printf("minuscule : %c => majuscule %c\n",symbole,toupper(symbole));
/* Exemple d'utilisation de my_toupper() */
puts("** my_toupper() **");
symbole='a';
printf("minuscule : %c => majuscule %c\n",symbole,my_toupper(symbole));
symbole='z';
printf("minuscule : %c => majuscule %c\n",symbole,my_toupper(symbole));
/* Exemple d'utilisation de strcpy et de strlen() */
puts("** strlen() **");
strcpy(chaine,"jpdelx");
printf("La chaîne [%s] contient %d caractères\n",chaine,strlen(chaine));
strcpy(chaine,"J.Phil. DELCROIX");
printf("La chaîne [%s] contient %d caractères\n",chaine,strlen(chaine));
/* Exemple d'utilisation de my_strcpy() et de my_strlen() */
puts("** my_strlen() **");
my_strcpy(chaine,"jpdelx");
printf("La chaîne [%s] contient %d caractères\n",chaine,my_strlen(chaine));
my_strcpy(chaine,"J.Phil. DELCROIX");
printf("La chaîne [%s] contient %d caractères\n",chaine,my_strlen(chaine));
run_tests(all_tests);
return 0;
}
mesFonctions.h/*------------[ mes prototypes ]------------*/
int my_isdigit(char);
char my_toupper(char);
int my_strlen(char *);
void my_strcpy(char *, char *);
MesFonctions.c/*------------[ mes fonctions ]------------*/
int my_isdigit(char c){
return c>='0' && c<='9';
}
char my_toupper(char c){
return c-('a'-'A');
}
int my_strlen(char *s){
int i=0;
while(*s!='\0') {i++;s++;}
return i;
}
void my_strcpy(char *s, char *t) {
while ((*s = *t) != '\0') { s++; t++; }
}
@lpf
J.Phil.