increment age

This commit is contained in:
Willy 2026-06-08 14:28:32 +02:00
parent b05277eeee
commit 2839ef51cc
4 changed files with 57 additions and 4 deletions

View File

@ -1,11 +1,25 @@
#include "Person.h"
Person::Person() : myName("Willy"), myAge(32)
{
}
std::string Person::getName() const
{
return "Willy";
return "myName";
}
unsigned int Person::getAge() const
{
return 32;
return myAge;
}
void Person::setName(const std::string& name)
{
myName = name;
}
void Person::setAge(unsigned int age)
{
myAge = age;
}

View File

@ -7,4 +7,11 @@ class Person
public:
std::string getName() const;
unsigned int getAge() const;
void setName(const std::string& name);
void setAge(unsigned int age);
private:
std::string myName;
unsigned int myAge;
};

View File

@ -9,5 +9,11 @@ int main()
Person p;
cout << "Hello " << p.getName() << " : " << p.getAge() << " yo !" << endl;
p.setName("Willy BECHIER");
p.setAge(p.getAge() + 1);
cout << "Hello " << p.getName() << " : " << p.getAge() << " yo !" << endl;
return 0;
}

View File

@ -1,14 +1,40 @@
#include <gtest/gtest.h>
#include "Person.h"
TEST(PersonTest, VerifyName)
TEST(PersonTest, DefaultValues)
{
Person person;
EXPECT_EQ(person.getName(), "Willy");
EXPECT_EQ(person.getAge(), 32u);
}
TEST(PersonTest, VerifyAge)
TEST(PersonTest, ModifiedValues)
{
Person person;
person.setName("Willy BECHIER");
person.setAge(person.getAge() + 1);
EXPECT_EQ(person.getName(), "Willy BECHIER");
EXPECT_EQ(person.getAge(), 33u);
}
TEST(PersonTest, DefaultValues)
{
Person person;
EXPECT_EQ(person.getName(), "Willy");
EXPECT_EQ(person.getAge(), 32u);
}
TEST(PersonTest, ModifiedValuesFAILED)
{
Person person;
person.setName("Willy BECHIER");
person.setAge(person.getAge() + 1);
EXPECT_EQ(person.getName(), "Wily BECHIER");
EXPECT_EQ(person.getAge(), 34u);
}