Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Minor C++ Fork to allow the assertion software to log out
std::pair
(matters for the fixed tests). Without it, the fixed tests still work as expected, but the log messages are unhelpful ([unsupported type]
) (the assertion software CW uses requires boilerplate to know how to log out standard library types). I prematurely removed this snippet once I switched to the no-ref-sol approach, forgetting that the fixed tests still do the typical assert-equals stuff. Added it back. (Also, made the initial solution return[]
instead of [[0, 0]]`, to reduce clutter)C++ Translation
C++ Translation. (Omits the reference solution, per the new JS fork)
Approved
LGTM! I would've personally loved to see
generateTestCase
further simplified as below, but it's good as-isI heavily encourage you to add the Python fixed tests, splitting them into an
It(all_consecutive)
andIt(non_consecutive)
. The two tests from JS are too little imoFrom the description:
This means
std::generate(result.begin(), result.end(), [&] { return randint(-1e6, 1e6); } );
is non-compliant since it can generate duplicates and is not guaranteed to be sortedOptioal, but
fmt::format("numbers = {{{}}}\n", fmt::join(numbers, ", "))
is unnecessary becausefmt::format("numbers = {}\n", numbers)
will output the same exact thingYeah that's fair, but I hope OP reconsiders including that part. Omitting it is better for clarity, and is more language-agnostic if this kata ever gets translated to languages where unsigned integers are the idiomatic encodings for indices (so a negative index isn't even possible)
Where would an index <
0
come from, given this guarantee?The solutions under here aren't being pushed into a company's repository. Sometimes, best practices advice like this is unsolicited
Oh wow
It need not be a consideration, yes, but in this case the discussion is about whether or not the task should be changed. If a change is objectively beneficial, then the effort to set it up should be irrelevant. But since I can't really see a gain of ditching unit application, I think it then becomes fair to bring up possible hurdles
No, it's not that simple in C++ for many reasons. I mean I'd get into it in depth if you want to, but I don't think it'd be worthwhile unless someone else who's well aware of these hurdles wants to chime in. If you want to get an idea of the types of challenges that can encounter someone trying to make random tests of this kata, you can take a glimpse at the C++ random tests. Again, these are testing-only challenges - the task is pretty straightforward to implenent in tons of ways from the solver's side. Again, this change is possible, but unless I'm wrong, it will require a new
invoke_op
function in the vein of theinvoke_num
function available in the tests. Again, would love if a C++ programmer can chime in.I don't encourage changing to
x(op(y))
. Although it's a seemingly minor change, doing it like this would make random testing in C++ way more inconvenient. Long story short, some of the techniques lots of people use to solve this problem (but not all) can mean thaty
as an expression is ambiguous, because there could be multiple overloads ofy
, or multiple template instantiations ofy
, and as someone who's outside the solver's head, I can't make the informed decision to guess the signature of the correct overload (for example, what if they use some defaulted arguments I would have no idea about?). On the other hand, withx(op(y()))
, I never need to deal with the problems ofy
as an expression, because all I need to concern myself with isy()
, which returns a guaranteed integer. I'm not saying adjusting the random tests forx(op(y))
is impossible - it's not - but it would require more hacking around the strict type system.C++ Translation.
Although extremely rare, the random tests have a chance of producing incorrect expected values if the generated random
substring
happens to repeat itself (ex:bzbz
,earear
). The chances of this happening are super low, but seeing how the readability of the random tests in this kata is low, could this be a case where it would be more readable + foolproof to make use of a reference solution instead of trying to completely pregenerate the output?Loading more items...