6 kyu
Versions manager
474 of 1,708bedis-elacheche
Loading description...
Algorithms
Arrays
Strings
Object-oriented Programming
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
"Error occured while parsing version!" >> "occured": Misspelled word.
Hi! The author has given the following code in the object constructor in the Python Solution's preloaded code:
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:
I'd appreciate your help!
The initial solution in python does not have any function body for
__init__
, I'm not sure where you're getting that from.That said, you should never raise a
BaseException
. The exact exception type doesn't matter for this kata, but it should be a concrete type, not the base class. Tryraise ValueError(...)
, it will fix your issue.Really sorry, I didn't know that I had tried to attempt this kata a long period back. That code was mine actually :/ My bad!
Thanks for the reply!
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
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!
This comment has been hidden.
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!
But how do you know that your local test is correct?
It's difficult to tell what is wrong with your solution without seeing your solution.
Because it's returning the expected value (<51.0.0>), not the value that the "randomTests" method is telling that it's returning (<51.1.0>)
It's difficult to tell what is wrong with your solution without seeing your solution.
This comment has been hidden.
The problem is that since all the version methods operate on the same instance,
rollback()
also should alter theVersionManager
instance. Your solution returns another instance onrollback()
which works with chaining but not with separate method call like the random tests are performing.I added some more assertions in sample and fixed tests which should show where your solution fails.
solved & submitted! many thanks Madjosz 👍
For C++
I passed all the fixed test but for random test I got expected-actual problem like:
Sometimes i received this error on random test:
Can someone help me how can i troubleshoot my code?
OP solved it, closing. Based on the error message, seems like you are trying to parse a non-digit character into integer
Why on Earth the C++ version expects
1.
and1.2.
to be valid input?Should be fixed.
This comment has been hidden.
Kata suggestions are meant to suggest improvements on the kata, you should use
question
label instead.Based on your latest code, I get this error -->
TypeError: Opsys.create is not a constructor
. Clearly, you are not instantiating the class correctly and everything should be placed in the constructor (including theversion
) andmajor
,minor
&&patch
values.can anyone tell me how to use the exception class in c++. i have no clue how to implement it without knowing its content
This comment has been hidden.
for throw exception you just need to type "throw VersionException("Error occured while parsing version!");" because it already have built-in VersionException Class for tester. Means to submit you dont have to use try and catch block. I hope my explaination is clear, sorry for my broken english
nice one
Fix for Java version
rollback()
calls to descriptionapproved by someone
This comment has been hidden.
You should read about "method chaining".
This comment has been hidden.
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
The random test as a whole is causing me so many problems that are just not asked for in the instructions
The assertion messages are not so good in Java, I will improve this.
For your solution:
<null>
but was<2.1.1>
" shows up when the initial version number is invalid but your code doesn't recognize it. Here is a test case you are failing:"25.g.28.18.38"
rollback()
is not working as intended.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>
rollback()
can be called more than once in a row. Your code doesn't support this. (This has to be added to description, see suggestion from trashy_incel below)reflection used by the Java random tests seems to be causing problems :
This comment has been hidden.
This solution passes now with the improved random tests.
It's one of the nicest 6 kyu kata I have ever solved. Thanks a lot!
Totally agree. I had a lot of fun solving it while being able to dive into Python OOP concepts a bit more. I did actually get the hang of using self inside of a class and learned about method chaining.
All the basic tests seem to work, except for the exception calls.. It gives me the following..
How should the exception call be handled? Just print("the error message") or raise Exception("the error message") Neither seems to work..
My logic:
self.prev is to keep track of previous value so that it can be set to self.version in rollback method.
This comment has been hidden.
I tried to improve the assertion messages of Python a bit and also added more test cases. Maybe this helps you to find the errors in your codes.
the description could make it clear that
rollback()
has to support the entire history of versions, not just the last versionAdded with improved Java version
resolved
I don't really like the argument validation.
1.h
is an expected error, but1.2.5.h
is not. At least, that is what I make out of the spec.i'd add that converting from an empty string to a default value, while there is already an overload / default argument to handle the case nicely, is awkward
that's the thing with input validation in kata's, either it should be very clear, logical and consistent, or you should not have to deal with validation at all; this is in between, which is messy
This implies that major and/or minor are optional. That anything after
patch
should be ignored can be viewed as a convenience (i.e. "we have the values we need, anything else doesn't break things so we'll just silently ignore it").Ok I completely read over that part. Perhaps because of all those capz.
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?
please tag this as a
question
, not anissue
. it is very likely that the error comes from your code, not the tests suite, as 160+ people passed the Java version without complaints. are you making sure that your methods are chainable ?okay, i checked your code, you made the same mistake as me initially,
rollback()
has to support the entire history of versions, not just the last one. i think the description should make this clearerMy code supports the entire history of versions.
For example
assertEquals("0.0.1", VersionManager().patch().patch().rollback().rollback().release())
holds.Also what do you say to the test error message which states that a method call has been returned? Pretty sure looks to me like some reflection issue.
Ok, sincere apologies, you were correct, I reopened the issue at the top of the page. the tests are indeed using reflection, i dont know why your code is failing
I improved the random tests and the solution passes now.
Factor translation:
typo: occured -> occurred typo: Seperated -> Separated
The methods probably shouldn't have trailing () in the description.
I fixed the
Seperated
typo, however theoccured
typo is from the original kata, and I believe present in every translation. Somewhat of a historical feaure :P.I also don't think it is worth wrapping the entire main description part in language-specific blocks just to remove the
()
, but if you want to rewrite the description to be somewhat more language agnostic I think you'd be welcome to.Can someone provide with info where i can read how to implement such things as rolback() method ?
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?
This was fun! Thanks!
Rust translation ready for review.
Note: Description has been modified.
Approved
Factor translation
has been approved
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)Python translation forked with random tests updated so they do not emit
"0"
as an input.approved.
JS: using class would be more appropiate
C++ translation kumited!
The author seems inactive. Can anyone else review it?
Approved.
Is there a reason why std::string_view is used instead of std::string? It looks like converting from string to int
stoi
is not supported in string_view.@numice you can change the signature of the constructor to
VersionManager(const std::string& version)
. As long as it compiles, it is a valid solution.Really enjoyable kata! I had a good time solving it. Thank you!
This comment has been hidden.
Python translation. Please, review and approve (the author is inactive).
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?
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.
Happy to hear that ^_^
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?
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)I added the test case. Thank you!
should be spelled "occurred" with two r's
oh! my bad! I guess it's a little bit late to fix that typo, all solutions mill marked as invalid :/
Java:
EDIT: and that thing is not really appealing:
Hi!
Fixed.
I updated the description
Didn't unserstand your point
Fixed.
I mean, if you look at my code, it would perfectly work as expected without it throwing the exceptions explicitly if you weren't checking for the error message. It's quite unusual to test for the strings themselves (on CW at least).
Testing error's message will help especially for random tests, to make sure you're throwing the right exception
Ok. But then:
Description updated, Thank you :)
just put quotes around the messages (they are strings) ;)
Empty string initial version is not mentioned.
Please specify the full range of the possible input.
I updated the description
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.I updated the description
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?
I changed the version generator algorithm. thank you for your feedback :)
Consider using
assertEquals
( or, when appropriate,assertDeepEquals
) instead ofassertSimilar
.assertSimilar
is justassertEquals
overTest.inspect
( which is a wrapper forJSON.stringify
); it's superfluous for primitive values anyway and not the cleanest solution forObject
s ( includingArray
s ) - 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
orassertApproxEquals
, thoughassertEquals
is functionally identical toassertDeepEquals
on primitives, and it's shorter. :] ( There's alsoexpectError
, but that only tests anError
has been thrown; your wrapper is better. )Done
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?Seems fixed.
vm("5.7.5.c")
Expected: '\'Error occured while parsing version!\''
Should I ignore or not ?!?
I updated both the description and tests.
.
Is there a problem with
Test.assertSimilar(vm().major().patch().rollback().major().rollback().release(), '1.0.0');
?Shouldn't it be
2.0.0
not1.0.0
?const v = vm() // 0.0.1 v.major() // 1.0.0 v.patch() // 1.0.1 v.rollback() // 1.0.0 v.major() // 2.0.0 v.rollback() // 1.0.0 v.release()
My bad, I misread the description.
Sample tests should contain cases where method calls are separated like
to make it clear that these methods are expected to modify the current object.
Done
Version format rules are not clear
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'
...'Error occured while parsing version!' is raised when the initial version contains characters
That's not what the description says.
Please fix something.
I updated both the description and tests. Thank you :)
.
Thank you for your feedback! I just fixed the issue.