aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-11-10 09:26:04 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-11-10 09:26:04 +0100
commit9dd7a48967f99793b818f7362ac8e95717186774 (patch)
treed96d81af7cd6d36de7b5e01cab7688b60446f03a
parent631a8d7b6c214da48f7748e78fc8c308960414fb (diff)
downloadpiscine_cpp-9dd7a48967f99793b818f7362ac8e95717186774.tar.gz
piscine_cpp-9dd7a48967f99793b818f7362ac8e95717186774.tar.bz2
piscine_cpp-9dd7a48967f99793b818f7362ac8e95717186774.zip
Added more tests for cpp01/07
-rw-r--r--cpp01/ex05/Human.cpp4
-rw-r--r--cpp01/ex05/Human.hpp4
-rw-r--r--cpp01/ex06/HumanA.cpp4
-rw-r--r--cpp01/ex06/HumanA.hpp8
-rw-r--r--cpp01/ex06/HumanB.cpp4
-rw-r--r--cpp01/ex06/HumanB.hpp8
-rw-r--r--cpp01/ex06/main.cpp2
-rw-r--r--cpp01/ex07/files/nowrite.orig (renamed from cpp01/ex07/test1)0
-rw-r--r--cpp01/ex07/files/test1.orig6
-rw-r--r--cpp01/ex07/files/test2.orig (renamed from cpp01/ex07/test2)0
-rw-r--r--cpp01/ex07/files/test3.orig6
-rw-r--r--cpp01/ex07/files/test4.orig6
-rw-r--r--cpp01/ex07/main.cpp16
-rwxr-xr-xcpp01/ex07/test.sh54
-rw-r--r--cpp02/ex00/Fixed.cpp5
-rw-r--r--cpp02/ex00/Fixed.hpp6
-rw-r--r--cpp02/ex00/main_DO_NOT_TURN_ME_IN.cpp (renamed from cpp02/ex00/main.cpp)0
-rw-r--r--cpp02/ex01/Fixed.cpp5
-rw-r--r--cpp02/ex01/Fixed.hpp4
-rw-r--r--subjects/cpp01.en.pdfbin1407857 -> 1407090 bytes
-rw-r--r--subjects/cpp02.en.pdfbin1445717 -> 1479870 bytes
21 files changed, 108 insertions, 34 deletions
diff --git a/cpp01/ex05/Human.cpp b/cpp01/ex05/Human.cpp
index e7f55bd..e5f2099 100644
--- a/cpp01/ex05/Human.cpp
+++ b/cpp01/ex05/Human.cpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 12:52:38 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:04:09 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:31:38 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,7 +19,7 @@ std::string Human::identify() const
return m_brain.identify();
}
-const Brain& Human::getBrain() const
+Brain const& Human::getBrain() const
{
return m_brain;
}
diff --git a/cpp01/ex05/Human.hpp b/cpp01/ex05/Human.hpp
index fc89d03..bf872e4 100644
--- a/cpp01/ex05/Human.hpp
+++ b/cpp01/ex05/Human.hpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 12:52:39 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:03:44 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:31:46 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,7 +20,7 @@ class Human
public:
Human();
std::string identify() const;
- const Brain& getBrain() const;
+ Brain const& getBrain() const;
private:
const Brain m_brain;
diff --git a/cpp01/ex06/HumanA.cpp b/cpp01/ex06/HumanA.cpp
index ab4e5f3..6d73ab2 100644
--- a/cpp01/ex06/HumanA.cpp
+++ b/cpp01/ex06/HumanA.cpp
@@ -6,13 +6,13 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 16:44:03 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:09:22 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:34:33 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanA.hpp"
-HumanA::HumanA(std::string const& name, Weapon& weapon)
+HumanA::HumanA(std::string const& name, Weapon const& weapon)
: m_name(name), m_weapon(weapon)
{}
diff --git a/cpp01/ex06/HumanA.hpp b/cpp01/ex06/HumanA.hpp
index d05d2fd..30144bd 100644
--- a/cpp01/ex06/HumanA.hpp
+++ b/cpp01/ex06/HumanA.hpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 16:37:23 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:08:55 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:34:26 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,11 +19,11 @@
class HumanA
{
public:
- HumanA(std::string const& name, Weapon& weapon);
+ HumanA(std::string const& name, Weapon const& weapon);
void attack();
private:
- std::string m_name;
- Weapon& m_weapon;
+ std::string m_name;
+ Weapon const& m_weapon;
};
#endif
diff --git a/cpp01/ex06/HumanB.cpp b/cpp01/ex06/HumanB.cpp
index e6adb22..7aa2a5f 100644
--- a/cpp01/ex06/HumanB.cpp
+++ b/cpp01/ex06/HumanB.cpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 16:46:02 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:13:34 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:36:16 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,7 +24,7 @@ void HumanB::attack()
std::cout << m_name << " attack with his " << m_weapon->getType() << std::endl;
}
-void HumanB::setWeapon(Weapon& weapon)
+void HumanB::setWeapon(Weapon const& weapon)
{
m_weapon = &weapon;
}
diff --git a/cpp01/ex06/HumanB.hpp b/cpp01/ex06/HumanB.hpp
index fc9236c..d21cb9d 100644
--- a/cpp01/ex06/HumanB.hpp
+++ b/cpp01/ex06/HumanB.hpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 16:42:54 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:09:56 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:39:45 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,10 +21,10 @@ class HumanB
public:
HumanB(std::string const& name);
void attack();
- void setWeapon(Weapon& weapon);
+ void setWeapon(Weapon const& weapon);
private:
- std::string m_name;
- Weapon* m_weapon;
+ std::string m_name;
+ Weapon const* m_weapon;
};
#endif
diff --git a/cpp01/ex06/main.cpp b/cpp01/ex06/main.cpp
index 5c92b43..97dbb39 100644
--- a/cpp01/ex06/main.cpp
+++ b/cpp01/ex06/main.cpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 16:40:20 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:13:54 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:39:52 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/cpp01/ex07/test1 b/cpp01/ex07/files/nowrite.orig
index 2851ba4..2851ba4 100644
--- a/cpp01/ex07/test1
+++ b/cpp01/ex07/files/nowrite.orig
diff --git a/cpp01/ex07/files/test1.orig b/cpp01/ex07/files/test1.orig
new file mode 100644
index 0000000..2851ba4
--- /dev/null
+++ b/cpp01/ex07/files/test1.orig
@@ -0,0 +1,6 @@
+bonjour je suis un
+charles
+avec quelque bonjour
+dans ce fichier
+bonjour
+hi im bonj
diff --git a/cpp01/ex07/test2 b/cpp01/ex07/files/test2.orig
index 227746e..227746e 100644
--- a/cpp01/ex07/test2
+++ b/cpp01/ex07/files/test2.orig
diff --git a/cpp01/ex07/files/test3.orig b/cpp01/ex07/files/test3.orig
new file mode 100644
index 0000000..8950d92
--- /dev/null
+++ b/cpp01/ex07/files/test3.orig
@@ -0,0 +1,6 @@
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+abababababababababababababababababab
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+abababababababababababababababababab
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
diff --git a/cpp01/ex07/files/test4.orig b/cpp01/ex07/files/test4.orig
new file mode 100644
index 0000000..0b1cda4
--- /dev/null
+++ b/cpp01/ex07/files/test4.orig
@@ -0,0 +1,6 @@
+aaaaaaaaaaaaaaa
+abababababababa
+aaaaaaaaaaaaaaa
+aaaaaaaaaaaaaaa
+abababababababa
+aaaaaaaaaaaaaaa
diff --git a/cpp01/ex07/main.cpp b/cpp01/ex07/main.cpp
index d98168a..3965d3d 100644
--- a/cpp01/ex07/main.cpp
+++ b/cpp01/ex07/main.cpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 17:08:28 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:22:46 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 09:25:28 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,22 +25,26 @@ int main(int argc, char **argv)
std::string filename(argv[1]);
std::string s1(argv[2]);
std::string s2(argv[3]);
- if (filename.empty() || s1.empty() || s2.empty())
+ if (s1.empty() || s2.empty())
{
- std::cerr << "Error: filename, s1 and s2 should not be empty" << std::endl;
+ std::cerr << "Error: s1 and s2 should not be empty" << std::endl;
return 1;
}
std::ifstream file(filename);
- std::ofstream outfile(filename + ".replace");
+ std::ofstream outfile(filename + ".replace", std::ofstream::trunc);
if (!file.is_open())
{
- std::cerr << "Could not open " << filename;
+ std::cerr << "Could not open " << filename
+ << ": " << std::strerror(errno) << std::endl;
+ outfile.close();
return 1;
}
if (!outfile.is_open())
{
- std::cerr << "Could not create " << filename << ".replace";
+ std::cerr << "Could not create " << filename << ".replace"
+ << ": " << std::strerror(errno) << std::endl;
+ file.close();
return 1;
}
diff --git a/cpp01/ex07/test.sh b/cpp01/ex07/test.sh
index 69cdc43..8a10120 100755
--- a/cpp01/ex07/test.sh
+++ b/cpp01/ex07/test.sh
@@ -1,5 +1,55 @@
#!/bin/sh
make all
-./replace test1 bonjour aurevoir
-./replace test2 occ many
+
+replace_test () {
+ echo "----------------------------------"
+ echo "$ ./replace $1 $2 $3"
+ ./replace "$1" "$2" "$3"
+ echo "=== ORIGIN"
+ cat "$1"
+ echo "=== REPLACED"
+ cat "$1.replace"
+}
+
+replace_test_error() {
+ echo "----------------------------------"
+ echo "$ ./replace $1 $2 $3"
+ ./replace "$1" "$2" "$3"
+}
+
+echo '======== BASIC ======='
+replace_test files/test1.orig bonjour aurevoir
+replace_test files/test2.orig occ many
+replace_test files/test3.orig a A
+replace_test files/test4.orig a zZz
+
+echo '======== ARGUMENT ERROR ======='
+./replace
+./replace files/test1.orig
+./replace files/test1.orig bonjour aurevoir ye
+./replace files/test1.orig bonjour
+./replace files/test1.orig '' aurevoir
+./replace files/test1.orig bonjour ''
+./replace '' bonjour aurevoir
+
+echo '======== FILE ERROR ======='
+./replace files/doesnotexist a b
+
+touch files/noperm
+chmod 000 files/noperm
+./replace files/noperm a b
+rm -f files/noperm
+
+touch files/noread
+chmod 333 files/noread
+./replace files/noread a b
+rm -f files/noread
+
+touch files/nowrite.orig.replace
+chmod 555 files/nowrite.orig.replace
+./replace files/nowrite.orig bonjour aurevoir
+rm -f files/nowrite.orig.replace
+
+
+find files -name '*.replace' -exec rm -f \{\} \;
diff --git a/cpp02/ex00/Fixed.cpp b/cpp02/ex00/Fixed.cpp
index eb0501b..fc50102 100644
--- a/cpp02/ex00/Fixed.cpp
+++ b/cpp02/ex00/Fixed.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 11:45:18 by charles #+# #+# */
-/* Updated: 2020/04/13 11:58:37 by charles ### ########.fr */
+/* Updated: 2020/11/09 13:07:28 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -29,10 +29,11 @@ Fixed::~Fixed()
std::cout << "Destructor called" << std::endl;
}
-void Fixed::operator=(Fixed const& other)
+Fixed& Fixed::operator=(Fixed const& other)
{
std::cout << "Assignation operator called" << std::endl;
m_value = other.getRawBits();
+ return *this;
}
int Fixed::getRawBits() const
diff --git a/cpp02/ex00/Fixed.hpp b/cpp02/ex00/Fixed.hpp
index 2ffe775..c8bdfb0 100644
--- a/cpp02/ex00/Fixed.hpp
+++ b/cpp02/ex00/Fixed.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 11:40:49 by charles #+# #+# */
-/* Updated: 2020/10/19 08:27:01 by cacharle ### ########.fr */
+/* Updated: 2020/11/09 13:10:35 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,13 +21,13 @@ public:
Fixed();
Fixed(Fixed const& other);
~Fixed();
- void operator=(Fixed const& other);
+ Fixed& operator=(Fixed const& other);
int getRawBits() const;
void setRawBits(int const raw);
private:
- int m_value;
+ int m_value;
static int const m_fractional_bits = 8;
};
diff --git a/cpp02/ex00/main.cpp b/cpp02/ex00/main_DO_NOT_TURN_ME_IN.cpp
index 494dbb3..494dbb3 100644
--- a/cpp02/ex00/main.cpp
+++ b/cpp02/ex00/main_DO_NOT_TURN_ME_IN.cpp
diff --git a/cpp02/ex01/Fixed.cpp b/cpp02/ex01/Fixed.cpp
index a81c1cf..14ba1c6 100644
--- a/cpp02/ex01/Fixed.cpp
+++ b/cpp02/ex01/Fixed.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 11:45:18 by charles #+# #+# */
-/* Updated: 2020/11/08 13:38:40 by charles ### ########.fr */
+/* Updated: 2020/11/09 13:11:29 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -28,10 +28,11 @@ Fixed::~Fixed()
std::cout << "Destructor called" << std::endl;
}
-void Fixed::operator=(Fixed const& other)
+Fixed& Fixed::operator=(Fixed const& other)
{
std::cout << "Assignation operator called" << std::endl;
m_value = other.getRawBits();
+ return *this;
}
Fixed::Fixed(const int from)
diff --git a/cpp02/ex01/Fixed.hpp b/cpp02/ex01/Fixed.hpp
index a262c59..1f768f6 100644
--- a/cpp02/ex01/Fixed.hpp
+++ b/cpp02/ex01/Fixed.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 11:40:49 by charles #+# #+# */
-/* Updated: 2020/11/08 13:38:48 by charles ### ########.fr */
+/* Updated: 2020/11/09 13:11:15 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,7 +22,7 @@ public:
Fixed();
Fixed(Fixed const& other);
~Fixed();
- void operator=(Fixed const& other);
+ Fixed& operator=(Fixed const& other);
Fixed(const int from);
Fixed(const float from);
diff --git a/subjects/cpp01.en.pdf b/subjects/cpp01.en.pdf
index 14ca9bd..9b819ef 100644
--- a/subjects/cpp01.en.pdf
+++ b/subjects/cpp01.en.pdf
Binary files differ
diff --git a/subjects/cpp02.en.pdf b/subjects/cpp02.en.pdf
index db75155..a652eaf 100644
--- a/subjects/cpp02.en.pdf
+++ b/subjects/cpp02.en.pdf
Binary files differ