-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up template stuff and created box class
- Loading branch information
Showing
11 changed files
with
152 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
|
||
/** | ||
* @brief Contains code for the boxnesting problem | ||
*/ | ||
namespace BoxNesting | ||
{ | ||
/** | ||
* @brief Class representing a box | ||
*/ | ||
class Box | ||
{ | ||
public: | ||
/** | ||
* @brief Deleted default constructor | ||
*/ | ||
Box() = delete; | ||
|
||
/** | ||
* Default virtual destructor. | ||
*/ | ||
virtual ~Box() = default; | ||
|
||
/** | ||
* Default copy constructor. | ||
* \param b | ||
*/ | ||
Box(const Box& b) = default; | ||
|
||
/** | ||
* Default move constructor. | ||
* \param b | ||
*/ | ||
Box(Box&& b) = default; | ||
|
||
/** | ||
* Default copy assignment operator. | ||
* \param b | ||
* \return | ||
*/ | ||
Box& operator=(const Box& b) = default; | ||
|
||
/** | ||
* Default move assignment operator. | ||
* \param b | ||
* \return | ||
*/ | ||
Box& operator=(Box&& b) = default; | ||
|
||
/** | ||
* @brief Construct a new Box object | ||
* | ||
* @param x The length of the box in the x-direction | ||
* @param y The length of the box in the y-direction | ||
* @param z The length of the box in the z-direction | ||
* @return A new Box object | ||
*/ | ||
Box(double x, double y, double z); | ||
|
||
/** | ||
* @brief Check if this box can nest inside other box | ||
* | ||
* @param b The box to check if this box can nest inside. | ||
* @return True if this box can nest inside the passed box. False otherwise | ||
*/ | ||
bool isNestable(const Box& b) const; | ||
|
||
private: | ||
/** | ||
* @brief The lengths of each side ordered from smallest to longest | ||
*/ | ||
std::array<double, 3> sideLengths; | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <box_nesting/Box.hpp> | ||
|
||
#include <algorithm> | ||
|
||
namespace BoxNesting | ||
{ | ||
|
||
Box::Box(double x, double y, double z) : sideLengths({x, y, z}) | ||
{ | ||
std::sort(this->sideLengths.begin(), this->sideLengths.end()); | ||
} | ||
|
||
bool Box::isNestable(const Box& b) const | ||
{ | ||
for (std::size_t i = 0; i < this->sideLengths.size(); ++i) { | ||
if (this->sideLengths.at(i) >= b.sideLengths.at(i)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <box_nesting/Box.hpp> | ||
#include <catch2/catch.hpp> | ||
|
||
#include <memory> | ||
|
||
SCENARIO("Boxes can nest inside another if their dimensions allow it", "[Box]") | ||
{ | ||
GIVEN("a set of boxes") | ||
{ | ||
BoxNesting::Box a(0.6, 0.6, 0.6); | ||
BoxNesting::Box b(0.6, 0.6, 0.5); | ||
BoxNesting::Box c(0.6, 0.5, 0.6); | ||
BoxNesting::Box d(0.5, 0.6, 0.6); | ||
BoxNesting::Box e(0.5, 0.5, 0.5); | ||
BoxNesting::Box f(0.4, 0.4, 0.4); | ||
|
||
THEN("they can nest inside eachother if their dimensions allow it") | ||
{ | ||
REQUIRE(e.isNestable(a) == true); | ||
} | ||
|
||
THEN("a box cannot nest inside itself") | ||
{ | ||
REQUIRE(a.isNestable(a) == false); | ||
REQUIRE(b.isNestable(b) == false); | ||
REQUIRE(c.isNestable(c) == false); | ||
REQUIRE(d.isNestable(d) == false); | ||
REQUIRE(e.isNestable(e) == false); | ||
} | ||
|
||
THEN("a larger box cannot nest inside a smaller box") | ||
{ | ||
REQUIRE(e.isNestable(d) == false); | ||
REQUIRE(e.isNestable(c) == false); | ||
REQUIRE(e.isNestable(b) == false); | ||
} | ||
|
||
WHEN("a box a can nest inside a box b and box b can nest inside box c") | ||
{ | ||
REQUIRE(f.isNestable(e) == true); | ||
REQUIRE(e.isNestable(a) == true); | ||
|
||
THEN("box a can nest iniside box c") | ||
{ | ||
REQUIRE(f.isNestable(a) == true); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.