~denisebitca/c-piscine

f7cac6a5044a831e3acf6c16410df20e2ab16b7c — Denise Bitca 1 year, 8 months ago 8ea03f7
Adding test cases (rudementary) for c11
6 files changed, 170 insertions(+), 0 deletions(-)

A test11/00.c
A test11/01.c
A test11/02.c
A test11/03.c
A test11/04.c
A test11/Makefile
A test11/00.c => test11/00.c +32 -0
@@ 0,0 1,32 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   00.c                                               :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbitca <marvin@42.fr>                      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/08/25 15:00:06 by rbitca            #+#    #+#             */
/*   Updated: 2022/08/25 15:17:20 by rbitca           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <unistd.h>

void	ft_foreach(int *tab, int length, void (*f)(int));

void ft_minusone(int i)
{
	char c;

	c = (char) i;
	c -= 1;
	write(1, &c, 1);
}

int	main(void)
{
	int	mainarray[] = {66, 67, 68, 69, 70};

	ft_foreach(mainarray, 5, &ft_minusone);
	write(1, "\n", 1);
}

A test11/01.c => test11/01.c +26 -0
@@ 0,0 1,26 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   01.c                                               :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbitca <marvin@42.fr>                      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/08/25 15:17:26 by rbitca            #+#    #+#             */
/*   Updated: 2022/08/25 15:25:54 by rbitca           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

void	test_int_tab(int *expected, int *received, int size, char *description);
int		*ft_map(int *tab, int length, int (*f)(int));

int ft_double(int i)
{
	return (i * 2);
}

int	main(void)
{
	int	expected[6] = {2, 4, 6, 8, 10, 12};
	int	mainarray[6] = {1, 2, 3, 4, 5, 6};
	test_int_tab(expected, ft_map(mainarray, 6, &ft_double), 6, "ex01: ft_double");
}

A test11/02.c => test11/02.c +29 -0
@@ 0,0 1,29 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   02.c                                               :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbitca <marvin@42.fr>                      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/08/25 15:27:06 by rbitca            #+#    #+#             */
/*   Updated: 2022/08/25 16:21:35 by rbitca           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

int	ft_any(char **tab, int (*f)(char*));
void	test_int(int expected, int received, char *description);

int ft_is_a(char* str)
{
	if (str[1] == '\0' && str[0] == 'a')
		return (1);
	return (0);
}

int	main(void)
{
	char *test[] = {"yeyaeyy", "f", "r", "e", 0};
	char *test2[] = {"a", "r", "m", "r", 0};
	test_int(0, ft_any(test, &ft_is_a), "ex02 - ft_is_a no a");
	test_int(1, ft_any(test2, &ft_is_a), "ex02 - ft_is_a yes a");
}

A test11/03.c => test11/03.c +29 -0
@@ 0,0 1,29 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   03.c                                               :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbitca <marvin@42.fr>                      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/08/25 15:27:06 by rbitca            #+#    #+#             */
/*   Updated: 2022/08/25 16:24:22 by rbitca           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

int	ft_count_if(char **tab, int length, int (*f)(char*));
void	test_int(int expected, int received, char *description);

int ft_is_a(char* str)
{
	if (str[1] == '\0' && str[0] == 'a')
		return (1);
	return (0);
}

int	main(void)
{
	char *test[] = {"yeyaeyy", "f", "r", "e", 0};
	char *test2[] = {"a", "a", "a", "r", 0};
	test_int(0, ft_count_if(test, 4, &ft_is_a), "ex03 - ft_is_a no a");
	test_int(3, ft_count_if(test2, 4, &ft_is_a), "ex03 - ft_is_a yes a");
}

A test11/04.c => test11/04.c +34 -0
@@ 0,0 1,34 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   04.c                                               :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbitca <marvin@42.fr>                      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/08/25 16:25:02 by rbitca            #+#    #+#             */
/*   Updated: 2022/08/25 16:32:57 by rbitca           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

void	test_int(int expected, int received, char *description);
int	ft_is_sort(int *tab, int length, int (*f)(int, int));

int ft_diff(int a, int b)
{
	if (a > b)
		return (1);
	if (a == b)
		return (0);
	return (-1);
}

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};

	test_int(1, ft_is_sort(tab1, 8, &ft_diff), "ex04 - ft diff sorted");
	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");
}

A test11/Makefile => test11/Makefile +20 -0
@@ 0,0 1,20 @@
C :=gcc
CFLAGS :=-Wall -Wextra -Werror -lbsd
SRC :=$(wildcard *.c)
EXE :=$(SRC:.c=)
EXNUM :=11

.SILENT:

all:$(EXE)

$(EXE):$(SRC)
	$C ../test-libraries.c ../$(EXNUM)/ex$@/*.c $@.c $(CFLAGS) -o $@.test
	./$@.test
	rm -rf ./$@.test
	echo "Norminette says:\n"
	norminette -R CheckForbiddenSourceHeader ../$(EXNUM)/ex$@
	echo "\n"

runNorminette:
	norminette -R CheckForbiddenSourceHeader ../$(EXNUM)