Skip to content

Commit

Permalink
[Data/Vertex] Added a printing operator<<
Browse files Browse the repository at this point in the history
- This will allow for easier testing of vertices by outputting their values when different from each other
  • Loading branch information
Razakhel committed May 20, 2024
1 parent 866fbf7 commit 2234766
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/RaZ/Data/Submesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ struct Vertex {
constexpr bool operator!=(const Vertex& vert) const noexcept { return !(*this == vert); }
};

inline std::ostream& operator<<(std::ostream& stream, const Vertex& vert) {
stream << "{\n"
<< " " << vert.position << '\n'
<< " " << vert.texcoords << '\n'
<< " " << vert.normal << '\n'
<< " " << vert.tangent << '\n'
<< '}';
return stream;
}

class Submesh {
public:
Submesh() noexcept = default;
Expand Down
22 changes: 22 additions & 0 deletions tests/src/RaZ/Data/Submesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <catch2/catch_test_macros.hpp>

#include <sstream>

TEST_CASE("Vertex basic", "[data]") {
constexpr Raz::Vertex vertex1{ Raz::Vec3f(0.f), Raz::Vec2f(1.f), Raz::Axis::Z, Raz::Axis::X };
CHECK(vertex1.position == Raz::Vec3f(0.f));
Expand All @@ -21,6 +23,26 @@ TEST_CASE("Vertex basic", "[data]") {
CHECK_FALSE(std::hash<Raz::Vertex>()(vertex1) == std::hash<Raz::Vertex>()(vertex2));
}

TEST_CASE("Vertex printing", "[data]") {
constexpr Raz::Vertex vertex{
Raz::Vec3f(1.f, 2.f, 3.f),
Raz::Vec2f(0.123456789f, 0.987654321f),
Raz::Vec3f(4.f, 5.f, 6.f),
Raz::Vec3f(7.f, 8.f, 9.f),
};

std::stringstream stream;

stream << vertex;
CHECK(stream.str() ==
"{\n"
" [ 1, 2, 3 ]\n"
" [ 0.123457, 0.987654 ]\n"
" [ 4, 5, 6 ]\n"
" [ 7, 8, 9 ]\n"
"}");
}

TEST_CASE("Submesh basic", "[data]") {
Raz::Submesh submesh;
CHECK(submesh.getVertexCount() == 0);
Expand Down

0 comments on commit 2234766

Please sign in to comment.