Ad
  • Custom User Avatar

    OP solved it, closing.

  • 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"

  • 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.

  • 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];
    }
    
  • 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

    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

    Where do you see that?