Ad
  • Custom User Avatar

    OP solved it, closing.

  • Custom User Avatar

    To those that get inexplicable precision problems: your code most likely has a conversion of double to float at some point(like the modulo operator) and loses precision.

  • Custom User Avatar

    You must throw an exception in cases like referencing an undeclared variable or an input that doesn't evaluate to an expression

    Look at how the last basic test works, it expects a throw when trying to get a non-existent "y"

  • Custom User Avatar

    C++
    What is the meaning of this test failure:
    Expected: equal to "Error caught"
    Actual: "Error not caught"

  • Default User Avatar

    Visual Studio does have a few tricks that the Codewars editor can't match. All I meant was, if you're doing the kata on another platform, you can make your own tests (as Codewars encourages you to do anyway) and run them any way you like. You don't really need to duplicate the Codewars testing setup.

  • Custom User Avatar

    Thank you so much.
    What do you mean by "Of course, you don't really need to do this just to solve the kata."? Can I also debug with the CodeWars editor environment?

  • Default User Avatar

    You'll need the "other functions" alluded to in the description. The full class definition is below. Once you have that, you should be able to re-create the Codewars testing setup on your own platform. Of course, you don't really need to do this just to solve the kata.

    struct Image
    {
     unsigned *pixels;
     unsigned width, height;
     
     Image();
     Image(std::initializer_list<unsigned> data, unsigned w, unsigned h);
     ~Image();
     void resize(unsigned w, unsigned h);
     
     std::vector<unsigned> central_pixels(unsigned colour) const;   // to be written by the codewarrior
    };
    
    /* ---------------------------------------------------------------------------------- */
    
    Image::Image()
    : pixels(NULL), width(0), height(0)
    {}
    
    Image::Image(std::initializer_list<unsigned> data, unsigned w, unsigned h)
    : width(w), height(h)
    { 
      pixels = new unsigned[w*h];
      unsigned *p=pixels;
      for(auto d : data)
        *p++ = d;
    }
    
    /* ---------------------------------------------------------------------------------- */
    
    Image::~Image()
    {
     delete [] pixels;
    }
    
    /* ---------------------------------------------------------------------------------- */
    // Resize the image. Existing pixel data is not preserved.
    
    void Image::resize(unsigned w, unsigned h)
    {
     width = w;
     height = h;
     delete [] pixels;
     pixels = new unsigned[w*h];
    }
    
  • Custom User Avatar

    Ok, I had thought my Visual Studio was not configured. For example, that I haven't updated igloo properly. But that's probably not the case.
    But there is still one problem. If I use the definition of the class Image given in the text, then it does not compile.

    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(129,18): error C2440: 'initializing': cannot convert from 'initializer list' to 'CentralPixels::Image'
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(136,1): message : No constructor could take the source type, or constructor overload resolution was ambiguous

    On the website, however, a definition is apparently used that works. Can I have that too?

  • Default User Avatar

    Unordered_Match implements solution-checking for this kata via the Snowhouse assert framework used with C++ on Codewars. The criterion is that the actual and expected solutions (both vectors of unsigned integers) should contain the same elements, but not necessarily in the same order. The full source code is as follows.

    /** Snowhouse Assert setup for checking solutions.
    Solutions are vectors (of unsigned int), but the order of elements within them isn't important. */
    
    struct Unordered_Match
    {
     Unordered_Match(const std::vector<unsigned> &expected);
     bool Matches(const std::vector<unsigned> &actual) const;
      
     std::vector<unsigned> expected_;
    };
    
    Unordered_Match::Unordered_Match(const std::vector<unsigned> &expected)
      : expected_(expected)
    {
     sort(expected_.begin(), expected_.end());
    }
    
    bool Unordered_Match::Matches(const std::vector<unsigned> &actual) const
    {
     if( actual.size() != expected_.size() )
       return false;
      
     std::vector<unsigned> a = actual;
     sort(a.begin(), a.end());
      
     unsigned i;
     for(i=0; i != a.size() && a[i] == expected_[i]; i++)
         ;
     return i == a.size();
    }
    
    std::ostream &operator<<(std::ostream &stm, const Unordered_Match &crit)
    {
     stm << snowhouse::Stringizer<std::vector<unsigned>>::ToString(crit.expected_);
     return stm;
    }
    
  • Custom User Avatar

    I use C++, Visual Studio 2022, Language Version is C++ 17.
    When I copy the SampleTests of this Kata into Visual Studio 2022, the compile complains about undefined symbol Unordered_Match:

    1>CentralPixels.cpp
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(101,54): error C3861: 'Unordered_Match': identifier not found
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(101,1): error C2664: 'void snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That(bool)': cannot convert argument 1 from 'std::vector<unsigned int,std::allocator>' to 'bool'
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(101,40): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    1>A:\develop\Training\CodeWars.cpp\import\igloo\external\snowhouse\snowhouse\assert.h(109,19): message : see declaration of 'snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That'
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(105,54): error C3861: 'Unordered_Match': identifier not found
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(105,1): error C2664: 'void snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That(bool)': cannot convert argument 1 from 'std::vector<unsigned int,std::allocator>' to 'bool'
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(105,40): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    1>A:\develop\Training\CodeWars.cpp\import\igloo\external\snowhouse\snowhouse\assert.h(109,19): message : see declaration of 'snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That'
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(109,54): error C3861: 'Unordered_Match': identifier not found
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(109,1): error C2664: 'void snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That(bool)': cannot convert argument 1 from 'std::vector<unsigned int,std::allocator>' to 'bool'
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(109,40): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    1>A:\develop\Training\CodeWars.cpp\import\igloo\external\snowhouse\snowhouse\assert.h(109,19): message : see declaration of 'snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That'
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(113,54): error C3861: 'Unordered_Match': identifier not found
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(113,1): error C2664: 'void snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That(bool)': cannot convert argument 1 from 'std::vector<unsigned int,std::allocator>' to 'bool'
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(113,40): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    1>A:\develop\Training\CodeWars.cpp\import\igloo\external\snowhouse\snowhouse\assert.h(109,19): message : see declaration of 'snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That'
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(117,54): error C3861: 'Unordered_Match': identifier not found
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(117,1): error C2664: 'void snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That(bool)': cannot convert argument 1 from 'std::vector<unsigned int,std::allocator>' to 'bool'
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(117,40): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    1>A:\develop\Training\CodeWars.cpp\import\igloo\external\snowhouse\snowhouse\assert.h(109,19): message : see declaration of 'snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That'
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(122,54): error C3861: 'Unordered_Match': identifier not found
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(122,1): error C2664: 'void snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That(bool)': cannot convert argument 1 from 'std::vector<unsigned int,std::allocator>' to 'bool'
    1>A:\develop\Training\CodeWars.cpp\CodeWars\CentralPixels.cpp(122,40): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    1>A:\develop\Training\CodeWars.cpp\import\igloo\external\snowhouse\snowhouse\assert.h(109,19): message : see declaration of 'snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That'
    1>Done building project "CodeWars.vcxproj" -- FAILED.

  • Custom User Avatar

    Try to be helpful for those who may want to help you. You will have more chances to get an answer if you present clearly your problem:

    • What's your problem? When does it happen? What's the context? Give logs;
    • Not less important: which language are you using?
  • Custom User Avatar

    Assert::That( image.central_pixels(1), Fulfills(Unordered_Match(red_ctr)) );

  • Custom User Avatar

    Inside the tests of this kata.

  • Custom User Avatar

    Where do you see that?

  • Custom User Avatar

    What is Unordered_Match?

  • Loading more items...