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.
approved
in
tester()
, theinput
parameter should beconst
, and usingstrdup()
to copy it to the user's string would be cleaner than using a VLA (though you will need to declarestrdup()
and freeword
at the end):some of your test cases seem invalid, e.g. in the fixed tests:
this happens in the random tests too
I cannot seem to upgrade this kata to PHP
8.0
. Since this version, the Codewars runner no longer concatenates the user file and the tests file, though the user file is autoloaded. The specific combination that seems to prevent the upgrade is that, in this kata, the user has to define a class as well as several variables.require "_solution.php";
seems necessary to pull the user's variables into the test suite's scope (they still need to be declared withglobal
, e.g.global $user_variable; var_dump ($user_variable);
.This works when there is no class in the user's file. But when there is a class, e.g.
class UserClass {}
, the tests do not compile:Fatal error: Cannot declare class UserClass, because the name is already in use in /workspace/default/_solution.php on line 1
. Usingrequire_once
instead ofrequire
makes the test compile again, but then the user variables are no longer visible (they default toNULL
).It seems that the autoloading conflicts with
require
when there are classes.cr_assert_str_eq()
instead of callingstrcmp()
yourself for the content equality assertion ?unsigned
is not robust. if you want to display those addresses (though i think it is not necessary), you can use the%p
format instead (you will need to cast the addresses tovoid *
in theprintf()
arguments in that case):fixed
enables PHP 8.0 (cf. this issue)
this was fixed by the upgrade to C# 12
PHP 8.0 should be enabled
fixed
this is not surprising and that's exactly the problem with undefined behavior in C/C++ ... many things can happen depending on the platform, the way the code is run, the compiler, etc. the worst case scenario is when nothing special happens, until that one day when a cryptic bug pops up from nowhere. there are some tools that can help, such as static analyzers. when i ran your code in this one, it correctly detected UB when run with an empty string (warning, this analyzer is free and online but it's a bit slow and the UB diagnostics can be a bit cryptic if you're not well versed on low-level details)
the issue was due to the tests computing the actual answer before the expected one. fixed. I also modified the type signature for C#, as it was not in line with the description, it was taking an
object[]
instead of anint[]
as promised by the description. you will need to refresh the page and reset the sample tests to see the changes.breaking change:
changing the signature from
to
as the description promises:
the only reasons to pass an
object[]
array containing only integer were to mimic dynamically-typed languages and to allow programming by mutation, which is not typical for C# arrays.Loading more items...