Skip to content

Commit 479faa4

Browse files
committed
feat: implemented tests in ex02
1 parent 89f2193 commit 479faa4

File tree

5 files changed

+90
-4
lines changed

5 files changed

+90
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ bin/
3535
build/
3636
to_vog*/
3737
*.idx
38+
a.out

cpp_test/Pessoa.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "Pessoa.hpp"
2+
#include <iostream>
3+
4+
Pessoa::Pessoa() : _age(0) {
5+
std::cout << "Construtor de pessoa foi chamado" << std::endl;
6+
}
7+
8+
Pessoa::~Pessoa() {
9+
std::cout << "Destrutor de pessoa foi chamado" << std::endl;
10+
}
11+
12+
void Pessoa::setName(const std::string name) {
13+
this->_name = name;
14+
}
15+
16+
std::string Pessoa::getName(void) const {
17+
if (_name.empty())
18+
return "Not named yet.";
19+
return this->_name;
20+
}
21+

cpp_test/Pessoa.hpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef PESSOA_HPP
2+
#define PESSOA_HPP
3+
4+
#include <cstddef>
5+
#include <string>
6+
7+
class Pessoa {
8+
public:
9+
Pessoa();
10+
~Pessoa();
11+
12+
std::string getName(void) const;
13+
std::size_t getAge(void) const;
14+
15+
void setName(const std::string name);
16+
void setAge(const std::size_t age);
17+
18+
private:
19+
std::string _name;
20+
std::size_t _age;
21+
};
22+
23+
#endif // !PESSOA_HPP

cpp_test/main_pessoa.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "Pessoa.hpp"
2+
#include <iostream>
3+
4+
int main () {
5+
6+
Pessoa cadete;
7+
8+
cadete.setName("Adedayo");
9+
std::cout << cadete.getName() << std::endl;
10+
11+
return 0;
12+
}

module_02/ex02/src/main.cpp

+33-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,45 @@
22
#include <cstdlib>
33
#include <iostream>
44

5-
#include <iostream>
6-
int main(void) {
7-
Fixed a;
8-
Fixed const b(Fixed(5.05f) * Fixed(2));
5+
void testOperators(void) {
6+
if (Fixed(2) > Fixed(1))
7+
std::cout << "test greater" << std::endl;
8+
if (Fixed(1) < Fixed(2))
9+
std::cout << "test lesser" << std::endl;
10+
if (Fixed(2) >= Fixed(1))
11+
std::cout << "test greater equal" << std::endl;
12+
if (Fixed(1) <= Fixed(1))
13+
std::cout << "test lesser equal" << std::endl;
14+
if (Fixed(2) == Fixed(2))
15+
std::cout << "test equal" << std::endl;
16+
if (Fixed(2) != Fixed(1))
17+
std::cout << "test different" << std::endl;
18+
}
19+
20+
void testIncrement(Fixed &a, Fixed const &b) {
921
std::cout << a << std::endl;
1022
std::cout << ++a << std::endl;
1123
std::cout << a << std::endl;
1224
std::cout << a++ << std::endl;
1325
std::cout << a << std::endl;
1426
std::cout << b << std::endl;
1527
std::cout << Fixed::max(a, b) << std::endl;
28+
}
29+
30+
void testArithmeticOperators(void) {
31+
32+
std::cout << "Sum 2 + 3 = " << (Fixed(2) + Fixed(3)) << std::endl;
33+
std::cout << "Sub 2 - 3 = " << (Fixed(2) - Fixed(3)) << std::endl;
34+
std::cout << "Div 2 / 3 = " << (Fixed(2) / Fixed(3)) << std::endl;
35+
std::cout << "Mult 2 * 3 = " << (Fixed(2) * Fixed(3)) << std::endl;
36+
}
37+
38+
int main(void) {
39+
Fixed a;
40+
Fixed const b(Fixed(5.05f) * Fixed(2));
41+
testOperators();
42+
testArithmeticOperators();
43+
testIncrement(a, b);
44+
1645
return EXIT_SUCCESS;
1746
}

0 commit comments

Comments
 (0)