check leaks on d02 ok

This commit is contained in:
hugogogo
2022-03-14 17:42:07 +01:00
parent eec58e03ac
commit a3a82c1c18
10 changed files with 112 additions and 13 deletions

View File

@@ -20,7 +20,8 @@ SRCS = main.cpp \
Fixed.cpp
D_HEADERS = .
HEADERS = Fixed.hpp
HEADERS = Fixed.hpp \
colors.h
D_OBJS = builds
OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o)
@@ -50,6 +51,9 @@ $(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
$(NAME): $(OBJS)
$(CC) $(OBJS) -o $@ $(LIBS)
leaks: $(NAME)
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME)
clean:
rm -f $(OBJS)

25
d02/ex00/colors.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef COLORS_H
# define COLORS_H
# define GRAY "\e[0;30m"
# define RED "\e[0;31m"
# define GREEN "\e[0;32m"
# define YELLOW "\e[0;33m"
# define BLUE "\e[0;34m"
# define PURPLE "\e[0;35m"
# define CYAN "\e[0;36m"
# define WHITE "\e[0;37m"
# define B_GRAY "\e[1;30m"
# define B_RED "\e[1;31m"
# define B_GREEN "\e[1;32m"
# define B_YELLOW "\e[1;33m"
# define B_BLUE "\e[1;34m"
# define B_PURPLE "\e[1;35m"
# define B_CYAN "\e[1;36m"
# define B_WHITE "\e[1;37m"
# define RESET "\e[0m"
#endif

View File

@@ -1,17 +1,54 @@
#include "Fixed.hpp"
#include <iostream>
#include "colors.h"
#define N_TEST "1"
int main( void ) {
Fixed a;
Fixed b( a );
Fixed c;
int i = 0;
c = b;
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
<< "tests subject :" RESET "\n";
{
Fixed a;
Fixed b( a );
Fixed c;
c = b;
std::cout << a.getRawBits() << std::endl;
std::cout << b.getRawBits() << std::endl;
std::cout << c.getRawBits() << std::endl;
}
std::cout << a.getRawBits() << std::endl;
std::cout << b.getRawBits() << std::endl;
std::cout << c.getRawBits() << std::endl;
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
<< "tests sets :" RESET "\n";
{
Fixed a;
Fixed b( a );
Fixed c;
c = b;
std::cout << "\n" B_BLUE "sets a(4), b(6.3), c(-187)" RESET "\n";
a.setRawBits(4);
b.setRawBits(6.3);
c.setRawBits(-187);
std::cout << a.getRawBits() << std::endl;
std::cout << b.getRawBits() << std::endl;
std::cout << c.getRawBits() << std::endl;
std::cout << "\n" B_BLUE "sets a(76.76), b(0), c(0.0)" RESET "\n";
a.setRawBits(76.76);
b.setRawBits(0);
c.setRawBits(0.0);
std::cout << a.getRawBits() << std::endl;
std::cout << b.getRawBits() << std::endl;
std::cout << c.getRawBits() << std::endl;
}
return 0;
}