Merge branch 'master' of bitbucket.org:hugogogo/piscine_cpp

This commit is contained in:
hugogogo
2022-08-01 20:06:44 +02:00
90 changed files with 2583 additions and 235 deletions

View File

@@ -18,7 +18,7 @@ INCLUDES = -I$(D_HEADERS)
D_SRCS = .
SRCS = main.cpp \
Zombie.cpp \
ZombieHorde.cpp
zombieHorde.cpp
D_HEADERS = .
HEADERS = Zombie.hpp

View File

@@ -1,22 +1,18 @@
#include "HumanB.hpp"
HumanB::HumanB( std::string name ) {
this->_name = name;
}
HumanB::~HumanB() {}
void HumanB::setWeapon( Weapon &weapon ) {
this->_weapon = &weapon;
}
void HumanB::attack( void ) {
if (!this->_weapon)
return;
std::cout << this->_name << " attacks with their ";
std::cout << this->_weapon->getType() << std::endl;
}

View File

@@ -1,21 +1,15 @@
#include "Weapon.hpp"
Weapon::Weapon( std::string type ) {
this->_type = type;
return;
}
Weapon::~Weapon() {}
std::string const & Weapon::getType( void ) const {
return this->_type;
}
void Weapon::setType( std::string type ) {
this->_type = type;
}

View File

@@ -14,6 +14,7 @@ int main()
{
Weapon club = Weapon("crude spiked club");
HumanB jim("Jim");
jim.attack();
jim.setWeapon(club);
jim.attack();
club.setType("some other type of club");

BIN
d01/ex03/war Executable file

Binary file not shown.

View File

@@ -16,20 +16,23 @@ void Sed::replace() {
std::ofstream new_file(this->_new_file.c_str());
int len = this->_find.length();
std::string str;
char c_str[len + 1];
char cstr[len + 1];
if (file.fail() || new_file.fail())
return;
file.get(c_str, len + 1, EOF);
str.assign(c_str);
if (len)
file.get(cstr, len + 1, EOF);
else
file.get(cstr, len + 2, EOF);
str.assign(cstr);
while (!file.eof())
{
if (this->_find.compare(str) == 0)
if (len && this->_find.compare(str) == 0)
{
new_file << this->_replacement;
file.get(c_str, len + 1, EOF);
str.assign(c_str);
file.get(cstr, len + 1, EOF);
str.assign(cstr);
continue;
}
else
@@ -39,6 +42,4 @@ void Sed::replace() {
}
str.erase(str.end() - 1);
new_file << str;
}

BIN
d01/ex04/sed Executable file

Binary file not shown.

View File

@@ -1,10 +1,11 @@
#!/bin/bash
cd $(dirname $0)
source ./colors.sh
mkdir -p test_log
mkdir -p files_log
make -C ../ &> /dev/null
EXECUTABLE="sed"
FILES_LOG="files_log"
LEAKS=""
if [ $1 == "leaks" ] || [ $1 == "valgrind" ]
then
@@ -14,8 +15,8 @@ fi
# RUN TESTS
function run_tests
{
touch $TESTNAME
echo "$CONTENT" > $TESTNAME
if [ -f $TESTNAME ];then
echo "$CONTENT" > $TESTNAME;fi
$LEAKS ../$EXECUTABLE $TESTNAME "$FIND" "$REPLACEMENT"
OUTPUT=$( cat $TESTNAME.replace )
@@ -26,11 +27,15 @@ fi
echo -e $B_RED"$TESTNAME faillure"$ENDCO
fi
mv $TESTNAME $TESTNAME.replace ./test_log
if [ -f $TESTNAME ];then
mv $TESTNAME ./$FILES_LOG;fi
if [ -f $TESTNAME.replace ];then
mv $TESTNAME.replace ./$FILES_LOG;fi
}
# TEST 1 ########################################
TESTNAME="test1"
TESTNAME="one_line_file"
touch $TESTNAME
FIND=" "
REPLACEMENT="hello"
CONTENT=" "
@@ -38,7 +43,8 @@ RESULT="hello"
run_tests
# TEST 2 ########################################
TESTNAME="test2"
TESTNAME="multi_line_file"
touch $TESTNAME
FIND="ie"
REPLACEMENT="++"
CONTENT=$(cat << EOF
@@ -60,7 +66,8 @@ EOF
run_tests
# TEST 3 ########################################
TESTNAME="test3"
TESTNAME="replace_one_character"
touch $TESTNAME
FIND="."
REPLACEMENT="+"
CONTENT=$(cat << EOF
@@ -74,7 +81,8 @@ EOF
run_tests
# TEST 4 ########################################
TESTNAME="test4"
TESTNAME="replace_two_characters"
touch $TESTNAME
FIND=".."
REPLACEMENT="++"
CONTENT=$(cat << EOF
@@ -90,7 +98,8 @@ EOF
run_tests
# TEST 5 ########################################
TESTNAME="test5"
TESTNAME="first_letter_lure"
touch $TESTNAME
FIND="mdr"
REPLACEMENT="|||"
CONTENT=$(cat << EOF
@@ -104,7 +113,8 @@ EOF
run_tests
# TEST 6 ########################################
TESTNAME="test6"
TESTNAME="half_replacement_lure"
touch $TESTNAME
FIND="toutouille"
REPLACEMENT="||||||||||"
CONTENT=$(cat << EOF
@@ -120,7 +130,8 @@ EOF
run_tests
# TEST 7 ########################################
TESTNAME="test7"
TESTNAME="special_character_'"
touch $TESTNAME
FIND="n't"
REPLACEMENT="000"
CONTENT=$(cat << EOF
@@ -186,7 +197,8 @@ EOF
run_tests
# TEST 8 ########################################
TESTNAME="test8"
TESTNAME="multiline_replacement"
touch $TESTNAME
FIND=$(cat << EOF
ry
I don't
@@ -213,3 +225,79 @@ EOF
)
run_tests
# TEST 9 ########################################
TESTNAME="empty_find"
touch $TESTNAME
FIND=""
REPLACEMENT="p"
CONTENT=$(cat << EOF
No more tears, my heart is dry
I don't laugh and I don't cry
I don't think about you all the time
But when I do - I wonder why
EOF
)
RESULT=$(cat << EOF
No more tears, my heart is dry
I don't laugh and I don't cry
I don't think about you all the time
But when I do - I wonder why
EOF
)
run_tests
# TEST 10 ########################################
TESTNAME="empty_find_and_replacement"
touch $TESTNAME
FIND=""
REPLACEMENT=""
CONTENT=$(cat << EOF
No more tears, my heart is dry
I don't laugh and I don't cry
I don't think about you all the time
But when I do - I wonder why
EOF
)
RESULT=$(cat << EOF
No more tears, my heart is dry
I don't laugh and I don't cry
I don't think about you all the time
But when I do - I wonder why
EOF
)
run_tests
# TEST 11 ########################################
TESTNAME="empty_replacement"
touch $TESTNAME
FIND="a"
REPLACEMENT=""
CONTENT=$(cat << EOF
No more tears, my heart is dry
I don't laugh and I don't cry
I don't think about you all the time
But when I do - I wonder why
EOF
)
RESULT=$(cat << EOF
No more ters, my hert is dry
I don't lugh nd I don't cry
I don't think bout you ll the time
But when I do - I wonder why
EOF
)
run_tests
# TEST 12 ########################################
TESTNAME="file_does_not_exist"
FIND="o"
REPLACEMENT="O"
CONTENT=$(cat << EOF
No more tears, my heart is dry
I don't laugh and I don't cry
I don't think about you all the time
But when I do - I wonder why
EOF
)
RESULT=""
run_tests

View File

@@ -1 +0,0 @@

View File

@@ -1 +0,0 @@
hello

View File

@@ -1,5 +0,0 @@
ce fichier
contient
plusieurs lignes
les unes au dessus des autres
youhouuu ioieux

View File

@@ -1,5 +0,0 @@
ce fich++r
cont++nt
plus++urs lignes
les unes au dessus des autres
youhouuu io++ux

View File

@@ -1 +0,0 @@
....................................................;

View File

@@ -1 +0,0 @@
++++++++++++++++++++++++++++++++++++++++++++++++++++;

View File

@@ -1,2 +0,0 @@
...................................................;
. . . . . . . . . . . . . . . . . . . . . . . . . .;

View File

@@ -1,2 +0,0 @@
++++++++++++++++++++++++++++++++++++++++++++++++++.;
. . . . . . . . . . . . . . . . . . . . . . . . . .;

View File

@@ -1 +0,0 @@
test de mmdr foubar

View File

@@ -1 +0,0 @@
test de m||| foubar

View File

@@ -1,2 +0,0 @@
trouve ce mot toutouille
et celui-la toutoutouille

View File

@@ -1,2 +0,0 @@
trouve ce mot ||||||||||
et celui-la tou||||||||||

View File

@@ -1,27 +0,0 @@
No more tears, my heart is dry
I don't laugh and I don't cry
I don't think about you all the time
But when I do - I wonder why
You have to go out of my door
And leave just like you did before
I know I said that I was sure
But rich men can't imagine poor.
One day baby, we'll be old
Oh baby, we'll be old
And think of all the stories that we could have told
Little me and little you
Kept doing all the things they do
They never really think it through
Like I can never think you're true
Here I go again - the blame
The guilt, the pain, the hurt, the shame
The founding fathers of our plane
That's stuck in heavy clouds of rain.
One day baby, we'll be old
Oh baby, we'll be old
And think of all the stories that we could have told

View File

@@ -1,27 +0,0 @@
No more tears, my heart is dry
I do000 laugh and I do000 cry
I do000 think about you all the time
But when I do - I wonder why
You have to go out of my door
And leave just like you did before
I know I said that I was sure
But rich men ca000 imagine poor.
One day baby, we'll be old
Oh baby, we'll be old
And think of all the stories that we could have told
Little me and little you
Kept doing all the things they do
They never really think it through
Like I can never think you're true
Here I go again - the blame
The guilt, the pain, the hurt, the shame
The founding fathers of our plane
That's stuck in heavy clouds of rain.
One day baby, we'll be old
Oh baby, we'll be old
And think of all the stories that we could have told

View File

@@ -1,4 +0,0 @@
No more tears, my heart is dry
I don't laugh and I don't cry
I don't think about you all the time
But when I do - I wonder why

View File

@@ -1,4 +0,0 @@
No more tears, my heart is doo
oooooooolaugh and I don't coo
oooooooothink about you all the time
But when I do - I wonder why

Binary file not shown.