6 kyu

Versions manager

474 of 1,708bedis-elacheche
Description
Loading description...
Algorithms
Arrays
Strings
Object-oriented Programming
  • Please sign in or sign up to leave a comment.
  • BCFCODE Avatar

    "Error occured while parsing version!" >> "occured": Misspelled word.

  • TERNION2205 Avatar

    Hi! The author has given the following code in the object constructor in the Python Solution's preloaded code:

    try:
      # parse the string
    except Exception:
      raise BaseException("Error occured while parsing version!")
    

    Now my solution works for all the fixed tests, however Test 7 Exception Calls is just not passing :c I'm handling the rollback error as well But it's stopping at the error I've just written above in the code.

    What could be the issue?

    P.S. I'm getting this error:

    Traceback (most recent call last):
      File "/workspace/default/solution.py", line 14, in __init__
        self.maj = int(v[0])
                   ^^^^^^^^^
    ValueError: invalid literal for int() with base 10: 'a'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/workspace/default/tests.py", line 4, in <module>
        @test.describe("Sample tests")
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/workspace/default/.venv/lib/python3.11/site-packages/codewars_test/test_framework.py", line 112, in wrapper
        func()
      File "/workspace/default/tests.py", line 50, in sample_tests
        @test.it("Exception calls")
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/workspace/default/.venv/lib/python3.11/site-packages/codewars_test/test_framework.py", line 112, in wrapper
        func()
      File "/workspace/default/tests.py", line 53, in it_7
        VersionManager("a.b.c")
      File "/workspace/default/solution.py", line 20, in __init__
        raise BaseException("Error occured while parsing version!")
    BaseException: Error occured while parsing version!
    

    I'd appreciate your help!

  • Gpbiomed Avatar

    I'm getting a critical error when testing exceptions cases, in my code i'm calling "throw VersionException("Error occured while parsing version!");" without knowing how VersionException is defined i dont realize what is happening, any clue? thanks in advance

    log: UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f4f4e314afc bp 0x000002994ed0 sp 0x7ffc95d256b8 T1) ==1==The signal is caused by a READ memory access. ==1==Hint: address points to the zero page. ==1==WARNING: invalid path to external symbolizer! ==1==WARNING: Failed to use and restart external symbolizer! #0 0x7f4f4e314afb (/lib/x86_64-linux-gnu/libc.so.6+0x18eafb) #1 0x7f4f4ecf37dc (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x13d7dc) #2 0x42e4e2 (/workspace/test+0x42e4e2) #3 0x428f1e (/workspace/test+0x428f1e) #4 0x4288bd (/workspace/test+0x4288bd) #5 0x4285ab (/workspace/test+0x4285ab) #6 0x431735 (/workspace/test+0x431735) #7 0x427b8d (/workspace/test+0x427b8d) #8 0x7f4f4e1a7c86 (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) #9 0x404be9 (/workspace/test+0x404be9)

    UndefinedBehaviorSanitizer can not provide additional info. ==1==ABORTING

  • ValdemaruS Avatar

    Hi!

    The Random tests returns: new VersionManager("47.40.22").patch().rollback().minor().minor().rollback().patch().major().major() ==> expected: <49.0.0> but was: <2.0.0>

    but when I execute this code in local mode, it returns the correct and expected result <49.0.0>.

    Could you help me, please? Thanks!

  • Warios Avatar

    Hi,

    The "randomTests" method of "VersionManagerTest" class (VersionManagerTest.randomTests(VersionManagerTest.java:159)) has some issue because is returning errors like:

    "org.opentest4j.AssertionFailedError: new VersionManager("50").minor().major().minor().rollback() ==> expected: <51.0.0> but was: <51.1.0>"

    but when I execute that code in local it returns the correct and expected result (in this case <51.0.0>), so it shouldn't be returning that error.

    Could you have a look please? Thx!

  • hasnulaidit95 Avatar

    For C++

    I passed all the fixed test but for random test I got expected-actual problem like:

    Expected: equal to "0.1.1"
    Actual: "0.1.2"
    

    Sometimes i received this error on random test:

    Caught std::exception, what(): Error occured while parsing version!
    

    Can someone help me how can i troubleshoot my code?

  • MikChan Avatar

    Why on Earth the C++ version expects 1. and 1.2. to be valid input?

  • Shepard_182 Avatar

    This comment has been hidden.

  • piyush aneja Avatar

    can anyone tell me how to use the exception class in c++. i have no clue how to implement it without knowing its content

  • Bigoh20 Avatar

    nice one

  • Madjosz Avatar

    Fix for Java version

    • upgrade to JUnit 5
    • improve assertion messages
    • remove use of reflection.
    • add possibility of multiple rollback() calls to description
    • add sample and fixed test cases for invalid initial versions and multiple rollbacks
  • mjmattimoe Avatar

    This comment has been hidden.

  • codewars_ab Avatar

    Could someone please tell me when this is expecting null. I am passing every test but am getting things such as this expected: but was:<2.1.1> on the random test

  • bkposton Avatar

    Is there any way to figure out what randomTests are doing in Java? I can't figure out what the inputs could possibly give me expected:<8.1.0> but was:<null>

  • trashy_incel Avatar

    reflection used by the Java random tests seems to be causing problems :

    expected:<[53.4.63]> but was:<[VersionManager.patch()]>
    
  • maestroviktorin Avatar

    It's one of the nicest 6 kyu kata I have ever solved. Thanks a lot!

  • fujikawa.yuya Avatar

    All the basic tests seem to work, except for the exception calls.. It gives me the following..

      Should throw when initial version cannot be parsed
      Should throw when cannot rollback
    

    How should the exception call be handled? Just print("the error message") or raise Exception("the error message") Neither seems to work..

    My logic:

    If the passed version is not None, empty str, or a str that does not contain d.d.d in the beginning (basically any non empty str that does not contain d.d.d at the beginning where d = digit):
    
    print("Error occured while parsing version!")
    
    if self.prev == "": # defined in constructor, default = "", updated to copy.copy(self.version) in the major, minor, patch methods 
    
    print("Cannot rollback!")
    

    self.prev is to keep track of previous value so that it can be set to self.version in rollback method.

  • trashy_incel Avatar

    the description could make it clear that rollback() has to support the entire history of versions, not just the last version

  • dfhwze Avatar

    I don't really like the argument validation. 1.h is an expected error, but 1.2.5.h is not. At least, that is what I make out of the spec.

    • Why is noice after 3 apparent version numbers ok, but not after 1?
    • I don't see the spec mentioning Minor and Patch are optional arguments.
  • oliverboehme Avatar

    First of all this is a really nice Kata which I enjoyed, thanks for that! :)

    Still cannot get it submitted (Java translation), although I think I have a rather stable implementation. The random tests are always failing with smth like expected:<[53.4.63]> but was:<[VersionManager.patch()]>. It appears to me as if there is some reflection magic at work, which does not seem correct.

    Can you have a look?

  • gifti Avatar

    Factor translation:

    typo: occured -> occurred typo: Seperated -> Separated

    The methods probably shouldn't have trailing () in the description.

  • wh..?> Avatar

    Can someone provide with info where i can read how to implement such things as rolback() method ?

  • codher Avatar

    All tests passing but when I click "attempt" a randomTests() is run which I cannot see but every time returns something along the lines of expected: but was:<x.x.x> E.g expected: but was:<2.1.1> expected: but was:<2.0.0> expected: but was:<1.0.0>

    Not clear when we would expect release() to return null?

  • suic Avatar

    This was fun! Thanks!

  • Awesome A.D. Avatar

    Rust translation ready for review.

    Note: Description has been modified.

  • Kacarott Avatar
  • Blind4Basics Avatar

    the edge case constructor("0") is showing up only in the random tests. It should be either removed or tested properly in the fixed (and sample) tests as well (it's like this at least in Java and python)

  • farhanaditya Avatar

    JS: using class would be more appropiate

  • Expurple Avatar

    C++ translation kumited!

  • diegofranca Avatar

    Really enjoyable kata! I had a good time solving it. Thank you!

  • andre-dasilva Avatar

    This comment has been hidden.

  • FArekkusu Avatar

    Python translation. Please, review and approve (the author is inactive).

  • zardoxnet Avatar

    I am getting error when VersionManager is instantiated with null value,, i.e.

    (new VersionManager())->rollback();

    Reported in Test Results widow:

    "Error: Call to a member function release() on null"

    I believe I am doing this correctly in the class constructor

    public function __construct($v=false){ $this->major = 0; $this->minor = 0; $this->patch = 1; if($v){ ...

    Any idea of why this is going wrong?

  • dileader Avatar

    Bedis, this Kata is really awesome, actually one of the best I have solved on Codewars. It teaches really practical knowledge which is not commonly seen here + great test coverage. Thank you from the core of my heart.

  • hasan.guercan Avatar

    major on: 54.34.61 major on: 55.0.0 major on: 56.0.0

    expected:<5[6].0.0> but was:<5[7].0.0>

    it occurs at the random tests but three major operations would lead "54.34.61" to "57.0.0". Why is that not correct?

  • Blind4Basics Avatar

    I was playing in a fork when I realiszed that this vm('').release(); // '0.0.1' is in the description, but not in the test suite (at least in java)

  • docgunthrop Avatar

    should be spelled "occurred" with two r's

  • Blind4Basics Avatar

    Java:

    • expected and actual are inverted
    • the exceptions tests are testing that an exception is thrown, but the message of the exception is tested too. That's bad, imo:
      1. nothing is said about it in the description
      2. this is double pain for the user: it's perfectly possible to implement the parser so that it throws an exception when required, but without using a try/catch block to actually set the message (or using a regexp or whatever to check the input string. And same observation for the rollback method).

    EDIT: and that thing is not really appealing:

    Note: /workspace/java/src/VersionManagerTest.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    
  • Voile Avatar

    Empty string initial version is not mentioned.

    Please specify the full range of the possible input.

  • Voile Avatar

    It is not clear what exactly is a invalid initial version. 1.a.1 is not considered a valid initial version, but it only appears in the random tests.

  • JohanWiltink Avatar

    There don't seem to be fixed tests with version parts >= 10. The random tests sometimes get there, but mostly only for the major version. It's an obvious edge case though.

    ( A CodeWars "feature" seems to be that existing solutions will only be revalidated according to updated fixed tests, not according to updated random tests. This is not documented, but everything I've seen is consistent with that. )

    Relying on random tests generating specific tests might allow imperfect solutions to slip through the cracks anyway - just keep submitting.

    Shouldn't we have some of those?

  • JohanWiltink Avatar

    Consider using assertEquals ( or, when appropriate, assertDeepEquals) instead of assertSimilar.

    assertSimilar is just assertEquals over Test.inspect ( which is a wrapper for JSON.stringify ); it's superfluous for primitive values anyway and not the cleanest solution for Objects ( including Arrays ) - it drowns you in quotes in the output and it makes you dependent on property order ( which is not always defined or consistent ) for things like { b: 1, a: 2 }.

    There's actually exceedingly seldom a need for anything but assertDeepEquals or assertApproxEquals, though assertEquals is functionally identical to assertDeepEquals on primitives, and it's shorter. :] ( There's also expectError, but that only tests an Error has been thrown; your wrapper is better. )

  • JohanWiltink Avatar

    Obviously, we can't rollback a version if we didn't make any changes.

    vm("3.9.5").patch().rollback().rollback()

    Expected: '\'3.9.6\'', instead got: '\'Cannot rollback!\''

    Well, before 3.9.5, there was nothing to roll back to. Or was there?

  • JohanWiltink Avatar

    To parse versions, the function will use the following format MAJOR.MINOR.PATCH. Everything else will be simply ignored.

    vm("5.7.5.c")

    Expected: '\'Error occured while parsing version!\''

    Should I ignore or not ?!?

  • Avanta Avatar

    Is there a problem with Test.assertSimilar(vm().major().patch().rollback().major().rollback().release(), '1.0.0');?

    Shouldn't it be 2.0.0 not 1.0.0?

  • ZED.CWT Avatar

    Sample tests should contain cases where method calls are separated like

    var t = vm()
    t.major()
    t.release()...
    

    to make it clear that these methods are expected to modify the current object.

  • ZED.CWT Avatar

    Version format rules are not clear

    Everything else will be simply ignored.

    What do you mean by Everything else, if they are just ignored when is 'Error occured while parsing version!' expected? '' ' 2.3.4 ' '3.3.2.b' '3.3.3 . . ' '3..1'...

  • ZED.CWT Avatar
    3.3.9.9
    major
    minor
    minor
    rollback
    rollback
    release
    Expected: '\'4.2.0\'', instead got: '\'4.0.0\''