]> git.localhorst.tv Git - blank.git/blobdiff - tst/world/ChunkTest.cpp
more unit tests for Packet
[blank.git] / tst / world / ChunkTest.cpp
index 3ecf0f6912b7d42ae2f5853c5ad71e6effbad170..0da68d045d0dd04b0dada4d0150c9435355fade8 100644 (file)
@@ -305,7 +305,7 @@ void ChunkTest::testNeighbor() {
        for (int i = 0; i < Block::FACE_COUNT; ++i) {
                Block::Face face = Block::Face(i);
                neighbor->Position(Block::FaceNormal(face));
-               chunk->SetNeighbor(*neighbor);
+               chunk->SetNeighbor(face, *neighbor);
                CPPUNIT_ASSERT_MESSAGE(
                        "chunk did not link right neighbor",
                        chunk->HasNeighbor(face)
@@ -323,16 +323,6 @@ void ChunkTest::testNeighbor() {
                        &*chunk, &neighbor->GetNeighbor(Block::Opposite(face))
                );
                chunk->Unlink();
-               chunk->ClearNeighbors();
-       }
-
-       neighbor->Position({1, 1, 1});
-       chunk->SetNeighbor(*neighbor);
-       for (int i = 0; i < Block::FACE_COUNT; ++i) {
-               CPPUNIT_ASSERT_MESSAGE(
-                       "chunk linked with non-neighbor",
-                       !chunk->HasNeighbor(Block::Face(i))
-               );
        }
 }
 
@@ -451,6 +441,81 @@ void ChunkTest::testLightPropagation() {
 
        // now block the light to the left
        chunk->SetBlock(Chunk::Pos(6, 7, 7), Block(1));
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               5, chunk->GetLight(Chunk::Pos(7, 7, 7))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               4, chunk->GetLight(Chunk::Pos(8, 7, 7))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               4, chunk->GetLight(Chunk::Pos(7, 8, 7))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               4, chunk->GetLight(Chunk::Pos(7, 6, 7))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               4, chunk->GetLight(Chunk::Pos(7, 7, 8))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               4, chunk->GetLight(Chunk::Pos(7, 7, 6))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               3, chunk->GetLight(Chunk::Pos(6, 6, 7))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               3, chunk->GetLight(Chunk::Pos(6, 8, 7))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               3, chunk->GetLight(Chunk::Pos(6, 7, 6))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               3, chunk->GetLight(Chunk::Pos(6, 7, 6))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               2, chunk->GetLight(Chunk::Pos(5, 6, 7))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               2, chunk->GetLight(Chunk::Pos(5, 8, 7))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               2, chunk->GetLight(Chunk::Pos(5, 7, 6))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle affected unrelated index",
+               2, chunk->GetLight(Chunk::Pos(5, 7, 6))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "adding obstacle resulted in unexpected light level behind it",
+               1, chunk->GetLight(Chunk::Pos(5, 7, 7))
+       );
+
+       // and remove it again
+       chunk->SetBlock(Chunk::Pos(6, 7, 7), Block(0));
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "removing obstacle did not refill light correctly",
+               4, chunk->GetLight(Chunk::Pos(6, 7, 7))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "removing obstacle did not refill light correctly",
+               3, chunk->GetLight(Chunk::Pos(5, 7, 7))
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "removing obstacle did not refill light correctly",
+               2, chunk->GetLight(Chunk::Pos(4, 7, 7))
+       );
 }
 
 }