Ellen's Alien Game - C++ - Why Task 1 Fails

Why does task 1 fail complaining about a function (hit) from task 2 in C++ track? Shouldn’t task 1 pass, then I can move on to task 2?

namespace targets {
    class Alien {
        public:
            Alien(int x, int y) : x_coordinate(x), y_coordinate(y), health(3) {
                
            }
            
            int get_health() 
            {
                return health;
            }
            int x_coordinate{};
            int y_coordinate{};

        private:
            int health{3};
    };
}

Error:

In file included from /usr/local/include/catch2/benchmark/catch_benchmark.hpp:14,
                 from /usr/local/include/catch2/benchmark/catch_benchmark_all.hpp:24,
                 from /usr/local/include/catch2/catch_all.hpp:25,
                 from /tmp/ellens-alien-game/ellens_alien_game_test.cpp:3:
/tmp/ellens-alien-game/ellens_alien_game_test.cpp: In function 'void CATCH2_INTERNAL_TEST_6()':
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:32:19: error: 'class targets::Alien' has no member named 'hit'
   32 |     REQUIRE(alien.hit());
      |                   ^~~
In file included from /usr/local/include/catch2/catch_test_macros.hpp:11,
                 from /usr/local/include/catch2/catch_template_test_macros.hpp:20,
                 from /usr/local/include/catch2/catch_all.hpp:36:
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:32:19: error: 'class targets::Alien' has no member named 'hit'
   32 |     REQUIRE(alien.hit());
      |                   ^~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:32:19: error: 'class targets::Alien' has no member named 'hit'
   32 |     REQUIRE(alien.hit());
      |                   ^~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp: In function 'void CATCH2_INTERNAL_TEST_8()':
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:37:19: error: 'class targets::Alien' has no member named 'is_alive'
   37 |     REQUIRE(alien.is_alive());
      |                   ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:37:19: error: 'class targets::Alien' has no member named 'is_alive'
   37 |     REQUIRE(alien.is_alive());
      |                   ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:37:19: error: 'class targets::Alien' has no member named 'is_alive'
   37 |     REQUIRE(alien.is_alive());
      |                   ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:38:11: error: 'class targets::Alien' has no member named 'hit'
   38 |     alien.hit();
      |           ^~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:39:19: error: 'class targets::Alien' has no member named 'is_alive'
   39 |     REQUIRE(alien.is_alive());
      |                   ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:39:19: error: 'class targets::Alien' has no member named 'is_alive'
   39 |     REQUIRE(alien.is_alive());
      |                   ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:39:19: error: 'class targets::Alien' has no member named 'is_alive'
   39 |     REQUIRE(alien.is_alive());
      |                   ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:40:11: error: 'class targets::Alien' has no member named 'hit'
   40 |     alien.hit();
      |           ^~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:41:19: error: 'class targets::Alien' has no member named 'is_alive'
   41 |     REQUIRE(alien.is_alive());
      |                   ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:41:19: error: 'class targets::Alien' has no member named 'is_alive'
   41 |     REQUIRE(alien.is_alive());
      |                   ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:41:19: error: 'class targets::Alien' has no member named 'is_alive'
   41 |     REQUIRE(alien.is_alive());
      |                   ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:42:11: error: 'class targets::Alien' has no member named 'hit'
   42 |     alien.hit();
      |           ^~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:43:20: error: 'class targets::Alien' has no member named 'is_alive'
   43 |     REQUIRE(!alien.is_alive());
      |                    ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:43:20: error: 'class targets::Alien' has no member named 'is_alive'
   43 |     REQUIRE(!alien.is_alive());
      |                    ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:43:20: error: 'class targets::Alien' has no member named 'is_alive'
   43 |     REQUIRE(!alien.is_alive());
      |                    ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:44:11: error: 'class targets::Alien' has no member named 'hit'
   44 |     alien.hit();
      |           ^~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:45:20: error: 'class targets::Alien' has no member named 'is_alive'
   45 |     REQUIRE(!alien.is_alive());
      |                    ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:45:20: error: 'class targets::Alien' has no member named 'is_alive'
   45 |     REQUIRE(!alien.is_alive());
      |                    ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:45:20: error: 'class targets::Alien' has no member named 'is_alive'
   45 |     REQUIRE(!alien.is_alive());
      |                    ^~~~~~~~
/tmp/ellens-alien-game/ellens_alien_game_test.cpp: In function 'void CATCH2_INTERNAL_TEST_10()':
/tmp/ellens-alien-game/ellens_alien_game_test.cpp:50:19: error: 'class targets::Alien' has no member named 'teleport'
   50 |     REQUIRE(alien.teleport(99, 8));
      |                   ^~~~~~~~
[.....]
1 Like

(I’m not 100% certain, but I think this is true.) Alas, while tests can be run one task/set at a time, the entire test suite and your code needs to be compiled on each test run. That means, while the contents of those functions may not be tested, they still need to have a valid signature which matches what the tests expect. It’s a shortcoming of how the test runner works.

1 Like

@IsaacG I will try to create a valid signature for each function to see if that works. Thanks!

Yes, that did work. I can move forward now I know task 1 passed.

task_2_missing

FYI,
I think this is a bug. Task 1, 2, and 3 passed but task 2 is not visible.

I agree! @bwa11 would you like to propose a PR to fix this? I believe @vaeng is open to PRs like this.

1 Like

Thanks for finding that @bwa11. I made a PR.

1 Like

The PR has been merged. That bug should now be fixed.

1 Like