~denisebitca/c-piscine

6d3307c48d5c49639f98ba81de6cd689aec4d5df — Denise Bitca 1 year, 9 months ago f7cac6a
Improved testing conditions
2 files changed, 84 insertions(+), 2 deletions(-)

M test11/04.c
A test11/07.c
M test11/04.c => test11/04.c +6 -2
@@ 6,7 6,7 @@
/*   By: rbitca <marvin@42.fr>                      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/08/25 16:25:02 by rbitca            #+#    #+#             */
/*   Updated: 2022/08/25 16:32:57 by rbitca           ###   ########.fr       */
/*   Updated: 2022/08/26 10:54:47 by rbitca           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */



@@ 27,8 27,12 @@ int	main(void)
	int tab1[] = {1, 2, 3, 4, 5, 6, 7, 9};
	int tab2[] = {1, 1, 1, 1, 1, 2, 3, 4};
	int tab3[] = {1, 1, 1, 2, 3, 4, 5, -10};
	int tab4[] = {9, 8, 7, 6, 5, 4, 3, 2};
	int tab5[] = {9, 9, 9, 8, 8, 8, 7, 5};

	test_int(1, ft_is_sort(tab1, 8, &ft_diff), "ex04 - ft diff sorted");
	test_int(1, ft_is_sort(tab1, 8, &ft_diff), "ex04 - ft diff sorted forwards");
	test_int(1, ft_is_sort(tab2, 8, &ft_diff), "ex04 - ft diff differently sorted");
	test_int(0, ft_is_sort(tab3, 8, &ft_diff), "ex04 - ft diff not sorted");
	test_int(1, ft_is_sort(tab4, 8, &ft_diff), "ex04 - ft diff sorted backwards");
	test_int(1, ft_is_sort(tab5, 8, &ft_diff), "ex04 - ft diff differently sorted backwards");
}

A test11/07.c => test11/07.c +78 -0
@@ 0,0 1,78 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   07.c                                               :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbitca <marvin@42.fr>                      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/08/26 11:04:49 by rbitca            #+#    #+#             */
/*   Updated: 2022/08/26 11:27:31 by rbitca           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <stdio.h>

void	ft_advanced_sort_string_tab(char **tab, int (*cmp)(char *, char *));

int	ft_strcmp(char *s1, char *s2)
{
	int	i;

	i = 0;
	while(s1[i] || s2[i])
	{
		if(s1[i] != s2[i])
			return (s1[i] - s2[i]);
		i++;
	}
	return (0);
}

int	ft_strlencmp(char *s1, char *s2)
{
	int	i;
	int	j;

	i = 0;
	j = 0;

	while (s1[i++])
		;
	while (s2[j++])
		;
	if(i != j)
		return (i - j);
	return (0);
}

int	main(void)
{
	char *tab[10];

	tab[0] = "j2MI73a1VqJ";
	tab[1] = "3N6FTSG";
	tab[2] = "BuUbwON"; 
	tab[3] = "EimlXb";
	tab[4] = "6";
	tab[5] = "Uag";
	tab[6] = "yciW";
	tab[7] = "5NLmMtu";
	tab[8] = "WfB9";
	tab[9] = 0;
	
	ft_advanced_sort_string_tab(tab, &ft_strlencmp);

	int i = 0;
	printf("tab start\n");
	while (i < 9)
		printf("%s\n", tab[i++]);
	printf("tab end\n");

	ft_advanced_sort_string_tab(tab, &ft_strcmp);
	
	i = 0;
	printf("tab start\n");
	while (i < 9)
		printf("%s\n", tab[i++]);
	printf("tab end\n");
}