Skip to content

Commit

Permalink
Add a shadowcasting unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingranade committed Sep 26, 2020
1 parent 8ed6729 commit c198a52
Showing 1 changed file with 186 additions and 6 deletions.
192 changes: 186 additions & 6 deletions tests/shadowcasting_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ TEST_CASE( "shadowcasting_vision_along_a_wall", "[shadowcasting]" )

TEST_CASE( "shadowcasting_edgewise_wall_view", "[shadowcasting]" )
{
grid_overlay test_case( { 1, 2 }, LIGHT_TRANSPARENCY_CLEAR );
grid_overlay test_case( { 1, 2 }, LIGHT_TRANSPARENCY_OPEN_AIR );
test_case.data = { {
{T, T, O, T, T, T, T},
{T, T, O, T, T, T, T},
Expand All @@ -689,7 +689,7 @@ TEST_CASE( "shadowcasting_edgewise_wall_view", "[shadowcasting]" )
}
};

grid_overlay expected_results( { 1, 2 }, LIGHT_TRANSPARENCY_CLEAR );
grid_overlay expected_results( { 1, 2 }, LIGHT_TRANSPARENCY_OPEN_AIR );
expected_results.data = { {
{V, V, V, O, O, O, O},
{V, V, V, O, O, O, O},
Expand All @@ -706,7 +706,7 @@ TEST_CASE( "shadowcasting_edgewise_wall_view", "[shadowcasting]" )

TEST_CASE( "shadowcasting_opaque_floors", "[shadowcasting]" )
{
grid_overlay test_case( { 2, 2, 1 }, LIGHT_TRANSPARENCY_CLEAR );
grid_overlay test_case( { 2, 2, 1 }, LIGHT_TRANSPARENCY_OPEN_AIR );
test_case.data = {
{
{T, T, T, T, T},
Expand All @@ -731,7 +731,7 @@ TEST_CASE( "shadowcasting_opaque_floors", "[shadowcasting]" )
}
};

grid_overlay expected_results( { 2, 2, 1 }, LIGHT_TRANSPARENCY_CLEAR );
grid_overlay expected_results( { 2, 2, 1 }, LIGHT_TRANSPARENCY_OPEN_AIR );
expected_results.data = {
{
{O, O, O, O, O},
Expand Down Expand Up @@ -761,7 +761,7 @@ TEST_CASE( "shadowcasting_opaque_floors", "[shadowcasting]" )

TEST_CASE( "shadowcasting_transparent_floors", "[shadowcasting]" )
{
grid_overlay test_case( { 2, 2, 1 }, LIGHT_TRANSPARENCY_CLEAR );
grid_overlay test_case( { 2, 2, 1 }, LIGHT_TRANSPARENCY_OPEN_AIR );
test_case.data = {
{
{T, T, T, T, T},
Expand All @@ -787,7 +787,7 @@ TEST_CASE( "shadowcasting_transparent_floors", "[shadowcasting]" )
};
test_case.default_floor = false;

grid_overlay expected_results( { 2, 2, 1 }, LIGHT_TRANSPARENCY_CLEAR );
grid_overlay expected_results( { 2, 2, 1 }, LIGHT_TRANSPARENCY_OPEN_AIR );
expected_results.data = {
{
{V, V, V, V, V},
Expand Down Expand Up @@ -815,6 +815,186 @@ TEST_CASE( "shadowcasting_transparent_floors", "[shadowcasting]" )
run_spot_check( test_case, expected_results, true );
}

// From origin looking out, we should check every combination of 2x2 transparent and opaque patterns.
// T T O O
// T T O O
//
// T T T T O T T O
// O T T O T T T T
//
// T T O T T O O T T O O O
// O O O T O T T O T O T T
//
// O T T O O O O O
// O O O O O T T O


TEST_CASE( "shadowcasting_floating_wall", "[shadowcasting]" )
{
grid_overlay test_case( { 2, 16, 3 }, LIGHT_TRANSPARENCY_OPEN_AIR );
test_case.data = {
{
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T}
},
{
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T}
},
{
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, O, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T}
},
{
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, T, T, T},
{T, T, X, T, T}
}
};
test_case.default_floor = false;

grid_overlay expected_results( { 2, 16, 3 }, LIGHT_TRANSPARENCY_OPEN_AIR );
expected_results.data = {
{
{O, O, O, O, O},
{O, O, O, O, O},
{O, O, O, O, O},
{V, O, O, O, V},
{V, O, O, O, V},
{V, O, O, O, V},
{V, O, O, O, V},
{V, O, O, O, V},
{V, V, O, V, V},
{V, V, O, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V}
},
{
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, O, O, O, V},
{V, V, O, V, V},
{V, V, O, V, V},
{V, V, O, V, V},
{V, V, O, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V}
},
{
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V}
},
{
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, V, V, V},
{V, V, X, V, V}
}
};

run_spot_check( test_case, expected_results, true );
}

// Some random edge cases aren't matching.
TEST_CASE( "shadowcasting_runoff", "[.]" )
{
Expand Down

0 comments on commit c198a52

Please sign in to comment.