3 kyu

Magic Compare

Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • windhu Avatar

    only leave should_work_for_random_tests fail, why?

  • uwdo Avatar

    This comment has been hidden.

    • o2001 Avatar

      Seeing that you've eventually solved this without segfaults, do you wish to resolve the outstanding issue or is there something still unresolved?

    • uwdo Avatar

      Nothing unresolved remaining.

      Issue marked resolved by uwdo 11 months ago
  • nomennescio Avatar

    The description has We have to write cumbersone a < b && b < c && c < d instead of simply a < b < c. However, these are not equivalent, as there no d in the second expression.

  • v1taly Avatar

    I've passed all tests except random with results:

    Expected: false Actual : true

    That's not too much clear. In most katas we can make debug output of incoming data, but here incoming data is the expression itsels.

    Then question: how can I see the case I failed on?

    • K01egA Avatar

      I had simular issue. You should check if you processing correctrly cases where more then two chained operators. Like a < b < c < d.

  • Tausendacht Avatar

    What is the expectation of the mentioned example in the description: ((a != b) > c != d) < e < f Let's assume a,b,c,d,e,f distinct numbers greater than 1. Should then (a != b) be true, (true (1) > c) be false, (false (0) != d) be true, (true (1) < e) be true ? Then (under the given assumptions) the expression would break down to (e < f)

    I feel like I'm failing at the random tests that use the != operator. So I'm wondering if my assumption above is correct.

    • K01egA Avatar

      Example ((a != b) > c != d) < e < f can be rewritten as a != b && b > c && c != d && d < e && e < f. Operator != isn't special, it's like any other operator.

  • SzymonOzog Avatar

    Great kata, had a lot of fun solving it but I would propose to choose a few operators you will be using and pointing them out in the description because in the end we are basically doing the same thing for every operator which is not as fun.

  • virgesmith Avatar

    I'm completely stumped by exit code 139, presumably a segfault, running the sample tests in the web interface. I can't reproduce locally and valgrind/ubsan/asan don't see anything wrong in my code. My code does no heap allocations and the vector indexing in the sample tests dont overrun the vector. So haven't a clue. I'm using g++ 7.3 and clang++ 6.0.

    Not posting the solution code here (yet), but here's the steps I'm taking locally:

    $ g++ -Wall -Wno-deprecated-declarations -g -O2 -std=c++14 -I../igloo-igloo.1.1.1 cw_test.cpp -fsanitize=address,undefined -o cw
    cw_test.cpp: In member function ‘virtual void Tests::should_work_for_basic_relations()’:
    cw_test.cpp:14:35: warning: suggest parentheses around comparison in operand of ‘!=’ [-Wparentheses]
         bool res_5gtalt7neqa = (5 > a < 7 != a);
                                 ~~~~~~^~~
    $ ./cw
    ...
    Test run complete. 3 tests run, 3 succeeded, 0 failed.
    $ valgrind ./cw
    ==22141== Memcheck, a memory error detector
    ==22141== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
    ==22141== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
    ==22141== Command: ./cw
    ==22141== 
    ==22141==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
    ==22141== 
    ==22141== HEAP SUMMARY:
    ==22141==     in use at exit: 0 bytes in 0 blocks
    ==22141==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
    ==22141== 
    ==22141== All heap blocks were freed -- no leaks are possible
    ==22141== 
    ==22141== For counts of detected and suppressed errors, rerun with: -v
    ==22141== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
    
    • s4pfyr Avatar

      I had the same issue at first. I don't know if you have the same issue, but give the following a thought: What happens if you use your MagicCompare instance in a for loop's body for your comparison and then re-use it as your loop index. Hope this helps ;)

  • zotovigor1973 Avatar

    Good kata. You should have added sample tests with different comparison operators combined, e.g. i < 2*j > k or i == j <= k < l.

  • siebenschlaefer Avatar

    This comment has been hidden.