6 kyu

HTML dynamic color string generation

322 of 2,386Javatlacati
Description
Loading description...
Puzzles
View
AllIssues17Questions3Suggestions1Show Resolved
  • Please sign in or sign up to leave a comment.
  • jkimbell Avatar

    My solution shouldn't have passed, but just got a lucky run when I was looking for test feedback

  • RJPlog Avatar

    This comment has been hidden.

  • FArekkusu Avatar

    The method should be made static in the initial solution in C++.

  • FArekkusu Avatar

    It is not explained anywhere what the input parameter is for in C++.

  • FArekkusu Avatar

    Tests should import the user's solution AND use that import.

  • sitgo93 Avatar

    The description is very poor in my point of view.

    Using Python 3.8

  • W3Y50 Avatar

    I have all tests passed, but the aBunchInARowTest is failed and i have no idea where the Problem is... Can anyone help me for this task?

    Many thanks to the community!

    stack trace:

    java.lang.StringIndexOutOfBoundsException: begin 0, end 8, length 7 at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319) at java.base/java.lang.String.substring(String.java:1874) at GenerateColorRGB.generateColor(GenerateColorRGB.java:13) at GenerateColorRGBTest.aBunchInARowTest(GenerateColorRGBTest.java:52) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:40) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133) at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497) at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:80) at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:71) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229) at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197) at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128) at io.qualified.junit5.RunTests.main(RunTests.java:25)

  • user5135065 Avatar

    This comment has been hidden.

  • FArekkusu Avatar

    Tests should import the user's solution AND use that import.

  • Blind4Basics Avatar

    python: not handled yet. See here and the messages in the same thread.

  • gege83 Avatar

    I think my solution should have been rejected as the length of the hexadecimal number does not garanted to be 6 digits which is not valid on the web. Am I misunderstanding something?

  • Blind4Basics Avatar

    python:

    Traceback (most recent call last):
      File "/workspace/default/src/codewars-test/codewars_test/test_framework.py", line 111, in wrapper
        func()
      File "tests.py", line 41, in bunch_in_a_row_case
        random.seed(i)
    NameError: name 'random' is not defined
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    

    => the tests are relying on the imports of the user


    Why 6000 assertions!??? => this is bad because most browsers do not like that much data to handle. => to reduce to something more managable, or if that many of tests are needed, they should be done manually "under the hood", with one single explicit assertion per batch of tests.

  • Zeprabra Avatar

    This comment has been hidden.

  • 2Math0 Avatar

    This kata ccan be transelated to python also check this: python translationn

  • rowcased Avatar

    For This solution in ruby:

    • sometimes it gets this error: Should match hexadecimal color format
    • other times it gets this one: Should have the symbol and 6 digits
    • sometimes it will get both
    • and the rest of the times it will just pass
  • zLuki Avatar

    It's funny how easy 6kyus were 5 years ago :)

  • Opabinia Avatar

    Prolog solves this kata with real ease—in theory, at least. What I've done is implement a perfectly ordinary DCG (definite clause grammar), but it just doesn't run quickly enough.

    So, then, I'm going to have to go away and figure out how to make my code run faster. As the hard part of Prolog is optimization—and, in particular, actually knowing what's going on with Prolog under the hood when it runs your program!—I'm more than happy to work on honing this important skill.

    Javatlacati, do you have any idea how many colours it is that random_test is asking for 😃? Do I have to find a way to produce them specifically in a random order, as all I've done is create a grammar that generates HTML colour strings in a very Prolog-y way...?

  • vlukyanets Avatar

    This is very minor issue: using namespace std; is required and after removing this line testing code fail with compilation error. This is not good, because e.g. I never use using namespace std;. Better to let decide use this or not. Thanks.

  • akar-0 Avatar

    In C++ tests raise an error:

    In file included from main.cpp:7:
    ./tests.cpp:7:40: error: call to non-static member function without an object argument
            Assert::That(GenerateColorRGB::generateColor( rand() % 0x1000001 ).substr(0,1), Equals("#"));
                         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
    1 error generated.
    
  • akar-0 Avatar

    The description says nothing about what we have to do with the randomnumber parameter in C++. In Javascript there's no parameter, and no need of one to solve the kata.

  • wpspires Avatar

    In Java, getting a failed test saying "there are duplicates", followed by one of the randomly generated strings. The question does not say that they all need to be unique, only that they be valid. Add that to description or change this test.

  • _Fatum_ Avatar

    If you get the errors of compile like "main.cpp:57:40: error: call to non-static member function without an object argument" Do the method 'generateColor()' as static. It helped for me

  • jsmithlw Avatar

    I'm getting the following errors in C++ :

    main.cpp:57:40: error: call to non-static member function without an object argument
    Assert::That(GenerateColorRGB::generateColor( rand() % 0x1000001 ).substr(0,1), Equals("#"));
                 ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
    main.cpp:60:40: error: call to non-static member function without an object argument
    Assert::That(GenerateColorRGB::generateColor( rand() % 0x1000001 ).length(), Equals(7));
                 ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
    main.cpp:61:40: error: call to non-static member function without an object argument
    Assert::That(GenerateColorRGB::generateColor( 0x1000000 ).length(), Equals(7));
                 ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
    main.cpp:64:53: error: call to non-static member function without an object argument
    Assert::That(regex_match (GenerateColorRGB::generateColor( rand() % 0x1000001 ),regex("^#[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$")), Equals(true));
                              ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
    main.cpp:69:55: error: call to non-static member function without an object argument
    string newColorToTest = GenerateColorRGB::generateColor(i);
                            ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
    main.cpp:85:55: error: call to non-static member function without an object argument
    string newColorToTest = GenerateColorRGB::generateColor(wad+i % 0x1000001);
                            ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
    6 errors generated.
    

    I can pass the sample test by changing:

        Assert::That(GenerateColorRGB::generateColor( rand() % 0x1000001 ).substr(0,1), Equals("#"));
        
    

    to:

        GenerateColorRGB color;
        Assert::That(color.generateColor( rand() % 0x1000001 ).substr(0,1), Equals("#"));
    
  • erichlf Avatar

    I am getting all sorts of error about undefined 'regex' and not using std when pushing attempt.

  • hakatom Avatar

    c++, Really nice Kata but no assertion for output length. I removed length validation from my solution but i was still able to pass the Kata.

  • ABHIJIT SINGH BAINS Avatar

    C++ Seem to have done everyhting correctly. If I use randomNumber for generation I fail aBunchInARowTest because of some duplicate. If srand(randomNumber) and rand function together then I fail regex test. Dont know what is causing the problem.For regex says expected true and actual 0. Tried different combinations but keep failing either regex or the bunch test. Can you please help me out?

  • JohnnySquared Avatar

    Is there perhaps an error in the aBunchInARowTest for Java? When I "attempt" the kata all tests pass except this one which returns: #baf46 expected:true but was: false

    Now, I am not sure how the test class has been written but #baf46 looks like invalid output to me so shouldn't it be false?

  • DSchwettmann Avatar

    This comment has been hidden.

  • rubs33 Avatar

    This comment has been hidden.

  • IvanKosik Avatar

    The method "generateColor(int randomNumber)" has parameter "randomNumber". Need more information about that parameter.

  • geoffp Avatar

    The description needs an explanation of what the randomNumber argument is for. Most solutions seem to be calling rand() themselves, which leaves randomNumber with nothing to do.

    Also, the word "static" is missing from the function outline provided. I guess it's OK to make people figure this out for themselves, but maybe it wasn't intentional.

  • Unnamed Avatar

    What is int randomNumber in the C++ version?

  • Unnamed Avatar

    That class with one static function in C++ looks so Java-ish... And rand -- so C-ish...