Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

queen-attack: compile error without useful information #722

Closed
nozomirin opened this issue Oct 10, 2023 · 5 comments
Closed

queen-attack: compile error without useful information #722

nozomirin opened this issue Oct 10, 2023 · 5 comments

Comments

@nozomirin
Copy link

Here is my solution:
queen_attack.h

#if !defined(QUEEN_ATTACK_H)
#define QUEEN_ATTACK_H
#include <utility>
namespace queen_attack {
    class chess_board {
    public:
        chess_board(std::pair<int, int> white, std::pair<int, int> black);
        std::pair<int, int> white() const;
        std::pair<int, int> black() const;
        bool can_attack() const;
    private:
        bool is_valid(std::pair<int, int> chess) const;
        bool at_diagonal() const;
        std::pair<int, int> white_;
        std::pair<int, int> black_;
    };
}  // namespace queen_attack

#endif // QUEEN_ATTACK_H

queen_attack.cpp

#include "queen_attack.h"
#include <stdexcept>
#include <cmath>
namespace queen_attack {
chess_board::chess_board(std::pair<int, int> white, std::pair<int, int> black): white_(white), black_(black) {
    if (!is_valid(white) || !is_valid(black) || white == black) {
        //throw std::domain_error("The range should be in [1-8]");
    }
}

std::pair<int, int> chess_board::white() const {
    return white_;
}
std::pair<int, int> chess_board::black() const {
    return black_;
}

bool chess_board::can_attack() const {
    return white_.first == black_.first || white_.second == black_.second || at_diagonal();
}

bool chess_board::is_valid(std::pair<int, int> chess) const{
    if (chess.first <= 8 && chess.first > 0 && chess.second <= 8 && chess.second > 0) {
        return true;
    }
    return false;
}
bool chess_board::at_diagonal() const {
    return std::abs(white_.first - black_.first) == std::abs(white_.second - black_.second);
}
}  // namespace queen_attack

If I just commented the line that throws the domain_error exception, it compiles but can't pass the test.
But if I throw the exception there, I got this:
We received the following error when we ran your code:
make[2]: *** [CMakeFiles/test_queen-attack.dir/build.make:70: CMakeFiles/test_queen-attack] Error 3
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/test_queen-attack.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

And somehow, the Test page get wired...
test

@github-actions
Copy link
Contributor

Hello. Thanks for opening an issue on Exercism. We are currently in a phase of our journey where we have paused community contributions to allow us to take a breather and redesign our community model. You can learn more in this blog post. As such, all issues and PRs in this repository are being automatically closed.

That doesn't mean we're not interested in your ideas, or that if you're stuck on something we don't want to help. The best place to discuss things is with our community on the Exercism Community Forum. You can use this link to copy this into a new topic there.


Note: If this issue has been pre-approved, please link back to this issue on the forum thread and a maintainer or staff member will reopen it.

@siebenschlaefer
Copy link
Contributor

siebenschlaefer commented Oct 10, 2023

This error report has three aspects:

  • First, and maybe the most important one four you (@nozomirin) this solution considers coordinates valid that are in the range [1, 8]. You might want to double-check the tests, they use a slightly different range.
  • When a solution throws an error where the tests do not expect one that results in an empty error message. I know that is sub-optimal but we haven't yet come to an agreement how that should be handled, on a conceptual and a technical level.
  • The "weird" test page looks like a bug. @nozomirin, would you be so kind to tell us about your browser, it's version, your operating system, and if possible how to reproduce this issue?

@nozomirin
Copy link
Author

@siebenschlaefer Thanks for your help!
I changed the range and it works.
For the weird page, I can't reproduce it. I just modified the code and ran tests. I relaunched the browser before, the problem just gone.
If these information can help you,

the browser: chrome Version 116.0.5845.110 (Official Build) (64-bit)
os: gentoo
core: 6.1.46

@nozomirin
Copy link
Author

@siebenschlaefer It seems that the weird test page problem happens every time I open a new exercise. After I clicked back to exercise and continue in editor, it disappeared.

@nozomirin
Copy link
Author

eh... I just opened two and it appeared twice but the third one doesn't appear. I don't know whether some build errors in the last exercise triggered it. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants