Initial Course
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#include "classes_and_objects.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(ClassesAndObjects, DepositAndWithdraw) {
|
||||
oop::BankAccount account("Ada", 100.0);
|
||||
account.deposit(50.0);
|
||||
EXPECT_DOUBLE_EQ(account.balance(), 150.0);
|
||||
EXPECT_TRUE(account.withdraw(30.0));
|
||||
EXPECT_DOUBLE_EQ(account.balance(), 120.0);
|
||||
EXPECT_FALSE(account.withdraw(1000.0));
|
||||
}
|
||||
|
||||
TEST(ClassesAndObjects, OwnerName) {
|
||||
oop::BankAccount account("Grace");
|
||||
EXPECT_EQ(account.owner(), "Grace");
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "constructors.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Constructors, InitialAndAppend) {
|
||||
oop::StringBuilder builder("Hi");
|
||||
builder.append(" there");
|
||||
EXPECT_EQ(builder.str(), "Hi there");
|
||||
}
|
||||
|
||||
TEST(Constructors, CopySemantics) {
|
||||
oop::StringBuilder original("C++");
|
||||
oop::StringBuilder copy = original;
|
||||
copy.append("11");
|
||||
EXPECT_EQ(original.str(), "C++");
|
||||
EXPECT_EQ(copy.str(), "C++11");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "inheritance.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Inheritance, CircleArea) {
|
||||
oop::Circle circle(2.0);
|
||||
EXPECT_NEAR(circle.area(), 12.566370614359172, 1e-9);
|
||||
}
|
||||
|
||||
TEST(Inheritance, RectangleArea) {
|
||||
oop::Rectangle rect(3.0, 4.0);
|
||||
EXPECT_DOUBLE_EQ(rect.area(), 12.0);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "polymorphism.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Polymorphism, TotalArea) {
|
||||
std::vector<std::unique_ptr<oop::Shape>> shapes;
|
||||
shapes.push_back(std::make_unique<oop::Rectangle>(2.0, 3.0));
|
||||
shapes.push_back(std::make_unique<oop::Circle>(1.0));
|
||||
EXPECT_NEAR(oop::total_area(shapes), 6.0 + 3.141592653589793, 1e-9);
|
||||
}
|
||||
|
||||
TEST(Polymorphism, ShapeNames) {
|
||||
std::vector<std::unique_ptr<oop::Shape>> shapes;
|
||||
shapes.push_back(std::make_unique<oop::Circle>(1.0));
|
||||
shapes.push_back(std::make_unique<oop::Rectangle>(1.0, 2.0));
|
||||
EXPECT_EQ(oop::shape_names(shapes), (std::vector<std::string>{"Circle", "Rectangle"}));
|
||||
}
|
||||
Reference in New Issue
Block a user