6 kyu
Shop Inventory Manager
82 of 288GiacomoSorbi
Loading description...
Debugging
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.
The description says "the quality of an item can never be negative or increase beyond 50". Both of these limits are not true (and not just in cases where the item is "Sulfuras"), as in the tests, some items start with quality values that are negative, while others start with quality values that are above 50. For clarification, this Kata tests that quality values above 50 should be reduced if necessary, but should otherwise not be altered, and negative quality values are changed to 0 the first time they are encountered, and then increased as indicated by the other requirements.
(I have seen the issue of items with an initial quality value greater than 50 pointed out by other commenters, but haven't seen anyone point out the negative quality value issue.)
Part of the description of the kata is poorly worded and misleading, namely:
"the quality of an item can never be negative or increase beyond 50"
It should be replaced with (the author himself gave this explanation at the very bottom in response to old comments, but for some reason did not correct the description):
"cannot increase above 50: if it was already 56, it will either go down or stay 56, according to the category; just not increase."
To be honest, i cant understand what is going on with random tests. Description says that quality cant be higher that 50(if item isnt "Sulfurus") but it in tests they may be higher and i have no idea how to finish solution. That is a very intresting kata but broken (Imho) (JS)
The description is a total mess so is Item class. It is hard to write anything useful without changing it.
Some products starts with sell_in above 50 or quality below 0. Nowhere in the description is it specified what should be done with it. Moreover Item constructor should be prepared for it and fix those numbers if neccessary or they should never apear!
Random test are almost useless, without a way of repeating specific product you need to brute-force them in order to check every case. Special edge cases should be described or be taken into fixed tests!
Starting code is a total mess it is better without it. Also without the access to Item class it is hard to make it close to domain model so I didn't even bother.
I had high hopes for this kata but it wasn't anything good.
The tests shouldn't log anything. The "checking item...", "
N
days passed", "comparingsell_in
/quality
" info should be a single error message.Considering how atrociously bad and broken the initial solution is, you could save everybody the trouble of thinking that it could be debugged, and remove it.
There should be fixed tests with backstage passes having a
sell_in
equal to the number of passed days.Sometimes items have an initial quality
> 50
.Ruby 3.0 should be enabled.
Hi GiacomoSorbi
I am trying this Kata in Java.
I am failling in the random test in the Backstage passes.
the input values are for example:
quality: 72 Selling: 42
Expected different value expected:<72> but was:<50>
I missing something there? I was thinking that we cannot have Qualities over 50 apart from "Sulfuras"
Thnaks in advance
I think there's still problem with this kata. In the description it's said: Just for extra clarification, an item can never have its quality increase above 50, however "Sulfuras" is a legendary item and as such its quality is 80 and it never alters.
And here's a part of log from random tests: Starting items in the store are {Very Aged Brie, 2, 60}, {Potion of Weak Love, 6, 58} and 5 days passed Checking item 1: Very Aged Brie Test Passed Not the expected quality value: 50 should equal 60
According to the description only sulfuras can have quality >50. Besides - 5 days passed condition and quality raised by 2 each day.. where it is said? Please, verify requirements vs tests.
Python
Had the same problem. But read exactly: Every item can have a quality above 50. It is only said that it won't increase further if it has reached 50 or higher.
items
is shared and used globally and this is broken due to the new runner.Language and details?
Python:
https://github.com/Codewars/codewars.com/issues/1315#issuecomment-375149160
We still don't have an idea how to deal with global state yet, so it's probably stuck as it is.
I just spent a decent amount of times trying to figure out the strange results I was getting. If this Kata doesn't currently work for Python isnt there some way you can untick python as supported, in order to prevent people from wasting time?
Any updates of this issue?
All of 43 python passes of kata was done before using the new runner?
Fixed by making
items
a parameter. Also, the tests were rewritten to use the new decorator syntax and enabled Python 3.6.Tests use
xrange
so it's Python 2 only.I would rather put it as a suggestion, but ok:
xrange
s removed once somebody suggest me how to publish changes; I cannot unpublish this kata, for some reason, so no clue on how to proceed.Also, fixed.
Contains ambiguities in the description.
Like what? Also, taking into account the vague interview-feeling I wanted to keep here...
This comment has been hidden.
Why is test for "Backstage passes to a TAFKAL80ETC concert", sellIn=11, quality=20 failed? The test expects sellIn=10, quality=22 but according to requirements should be there sellIn=10, quality=21. Am I right?
Mh, probably no.
Ok, why: test_basicCases - OK Backstage passes to a TAFKAL80ETC concert, sellIn=15, quality=20 Backstage passes to a TAFKAL80ETC concert -> quality=21
test_edgeCasesOneDay - FAILED Backstage passes to a TAFKAL80ETC concert, sellIn=11, quality=20 Backstage passes to a TAFKAL80ETC concert -> quality=21
Which condition wasn't fulfiled?
Thanks
To be more precise, can you poste in git flavored markdown, tell me the language and the specific test you are mentioning?
This comment has been hidden.
As stated in other comments, I left it ambiguous on purpose to replicate the ambiguity of the interview testing I underwent, so I think I might stick to the current translation, but thanks for your feed :)
@GiacomoSorbi here's the original link for Gilded Rose Refactoring Kata, including translations for many programming languages.
May you put it into description instead of the current one?
Done, thanks!
Can someone point out the mistake I had in my object oriented solution? It fails the random tests, while the last solution passes everything with waved flags.
I've put all the parts from the last one into the object oriented attempt and it still fails. I'm a bit confused and would be thankful for some clarification.
Not sure about how I would be supposed to see your failing solution's code, but did you try to
console.log()
the basic data and then try to debug it, seeing what's wrong compared to the expected results?As stated out earlier I tried to solve it using an object oriented approach by wrapping a special object around the item class. Inside that special object I implemented the different rules for the cases. In some cases (only when it's tested against the random test cases) it fails to modify the sellin and qualtity values.
I changed the whole code and used simple if-else statements for each case. This solutions works like a charm. Haven't figured out yet what's the problem. Maybe it's because I create new objects and inject the item class into them.
Yes, I used console.log (System.out.println, because I solve it in Java). I could not find anything suspicious inside the code.
Because I solved it anyway I don't waste much time thinking about what went wrong. Thanks again for answering.
No probs; I would suspect that your previous approach was somehow modifying the base object passed as random input, but you would know better. Cheers!
Maybe I get this wrong, but as stated in the instructions the quality of an item can't be greater than 50.
In your random tests though the following test case failed:
test_randomItems(ShopInventoryManagerTests) Testing 11 random items after 8 days. Testing: +5 Conjured Vest of Hoggie Testing: +15 Aged brie Sword of Sargaras ✘ Expected different value expected:<72> but was:<50>
I had this a couple of times and double (and triple) checked all the cases. I passed due to a lucky random test case scenario.
Can you please check my solution if I made a mistake and passed by accident?
Greets David
This comment has been hidden.
My apologies. Then I got it wrong.
I'll just leave it as it is and keep my experience boost with it. ;-)
Thanks for the fast reply! Have a nice day.
Let's say you got it right getting it "wrongish". Thank you for your kind feed :)
Amount of failed tests keeps changing, hard to know what to change if the program doesn't even know how to read.
They are called "random test cases" for a reason and nothing prevents you from printing/logging inputs and the like :)
I don't mean I'm failing different tests, I mean if I click submit over and over, the amount I get wrong change. Unless you mean the tests literally change every time I submit?
EDIT: 5mins after posting:
wow, they are literally random. Ok that helps a lot more!
Yep, usually a kata gets a bunch of fixed and then many more random tests.
I am new to programming and enjoy using these kata as practice for the concepts I am picking up.
How long does it take people to solve this kata. I realise I will speed up as I am more familiar with the material. But I would like some idea of the benchmark I should be shooting for. I can't imagine in interview/ work scenario's i'd be given the amount of time it takes me.
Consider it depends much on many factor, but being a beginner I think you could assess yourself among 30 to 60 mins for this one.
Thanks for that.
I'm going to take a crack at it when i get home and shoot for an hour. As this is whill be the first time I am using porotype declaration stuff outside codeacademy that will slow me down a bit.
Out of interest what kind of time ranges would you give this sort of thing for:
Complete Novice: Beginner (couple of months): Intermediate ( up to 1 years): Seasoned user: Master:
Look at what you can do, not at how much time passed ;)
I don't think you're wording the backstage conditions correctly or they are not very clear:
Here's what I understood from it at the beginning: Backstage should increase in quality += 1 every sell in If backstage sell ins are <=10 they should increase by 2 instead If backstage sell in are <=5 they should increase by 3 instead end
Here you have a backstage with 7sell in, 9 quality. Let's count the sell ins. 7=>6 increase by 2 quality = 11 6=>5 increase by 2 quality = 13 5=>4 increase by 3 quality = 16 4=>3 increase by 3 quality = 19!!!!!!!!!!
Thats 4 days. Where the final sell in/day is ending at 3. Going from 7>6>5>4. 2 of those days should be +2 each. The other 2 should be +3 each. I know the answer it's testing for is +quality: 2,3,3,3 But the wording is very vague and confusing.
Starting items in the store are {Conjured Goblin Axe +5, 7, 13}, {Canned Laughters, 9, 12}, {Priss and the Replicants Backstage Passes, 7, 9}, {Conjured Goblin Axe +5, 9, 38}, {Zero Zone Kevlar Vest +1, 8, 22} and 4 days passed
OUTPUT: Checking item 3: Priss and the Replicants Backstage Passes Test Passed: Value == 3 Not the expected quality value - Expected: 20, instead got: 19
Which edits would you suggest for the description?
I think your error is here: 6=>5 increase by 2 quality = 13. This update is done on
sell_in == 5
, so the increase should be 3. You start withsell_in == 7
andquality == 9
. On the first update,sell_in == 6
andquality == 11
. Next update,sell_in == 5
andquality == 14
. Etc.This had me chewing my pen up -.- . One i had the Brie increase X2 below 0 as the other items decreased x2. Dug myself a grave there :)
But in the end it seems like you solved it: bravo/a!
Nice kata I enjoyed this one. Just a suggestion on the problem description and/or order of operations:
When calculating the change in value for an item on a given day you first need to decrement the "sell in" field. So for instance to calculate whether a product will decay twice as fast, you actually need to check if the sell in field is equal to one at the start of the loop for the day. I think this should be made clear in the problem description, or personally I would change it. The way the problem description is written seems to imply that the change in daily quality values are calculated using the current "sell in" value.
I think the consecutio is pretty straightforward here:
once the sell_in days is less then zero, quality degrades twice as fast
, meaning first you check if it goes below zero, and in case the quality degrades 2X, doesn't it?Hi,
I enjoyed the Kata, but wanted to raise an issue. Since the tests are random, it is possible that an incorrect solution will be accepted and appear in the solved answers portion. I had an answer that came up with a failed test and resubmitted my answer to see if other tests would fail when it came up passing all tests. I then attempted to rerun it but all the tests passed and my answer was accepted. Rather than offering randomized tests, you should make sure your tests cover all acceptance criteria. The purpose of a kata isn't to trick the participant or show that you can be more clever. The instructions should be clear and the tests should be complete and consistent. To that end, as a native English speaker and a linguist, I agree that the use of "the quality of an item can never be negative or increase beyond 50" is ambiguous, as it doesn't address what should happen if the value is already above 50. The instructions do imply that the value cannot exceed 50 - particularly since this is supposed to be a replacement for the existing store management system, which should have also followed these rules. As it is written, it is hard to imagine anyone successfully completing this kata without receiving feedback from the test results. Thanks!
Care to give something more specific about the broken test cases, including language, input and wrong output that passes it :)?
And, as I mentioned, the goal in this kata is also to give some ambiguous direction to see how users manage to figure it out by themselves: I don't think I have done it elsewhere and I wanted to keep the interview feeling that I got getting this in an actual interview - that's all :)
I was doing this kata in JavaScript, and I believe the test that initially failed and then passed dealt with backstage passes. Unfortunately, I do not recall the input or output, as I was expecting to see that failed test a second time and didn't note it.
In reference to giving the kata an "interview feel", I have had several interviews like this and am generally told that the purpose of the question is not only to see how the candidate solves the problem but how he/she interacts with the team/individual asking the question. These tend to be "social" or "culture" type questions, rather than hammer-at-it-until-it-breaks type questions. Generally, the purpose is to work collaboratively with those asking the question - which is not possible in this format.
Precisely, excellent point. And if all I can keep is the feeling of a ominous, uncertain problem, I will try to keep it that way :)
This comment has been hidden.
I am not sure where you get a third test that requires 3 as a solution, but it seems to me that you are not using the rules right for the Brie item.
Also, when formatting code to reply here, be sure to put a triple backtick in the beginning and in the end :)
That test I mentioned is from random tests, thanks for your time:) I was able to figure it out.
I am a native English speaker.
"the quality of an item can never ... increase beyond 50;"
This states plainly that an item cannot increase from 50 to >50, but does not specify behavior when an item's quality begins above 50.
"Just for extra clarification, an item can never have its quality increase above 50"
This statement is ambiguous. It could be technically be read as intended, but the typical native English speaker is likely to read it to mean an item's quality cannot cross (in the positive direction) the threshold of 50.
This really, really, really needs to be reworded. If these were verbatim quotes from an interview, then the interview itself was flawed. (Or perhaps part of the interview was a test to see if the candidate will seek clarification in cases of an ambiguous specification.)
As I mentioned, there were test cases to see how the candidate behaved in that occurrence. Strictly adhering to the notion of never increasing a value over 50 was what was expected and part of the trial.
I can accept the idea of candidates looking for clarification, though, which is why I will leave such comments not flagged as spoilers :)
Values can't never increase beyond 50, aside Sulfuras, but from tests I found that backstage passes are already beyond 50. I think that description should be more clear.
I think that it is clear enough: "the quality of an item can never be negative or increase beyond 50", meaning that you cannot raise it over that value, but it can have a greater starting value.
I would not change it, as a clear understanding of the subtlest parts of the text was a key point of the interview it comes from.
It wasn't clear from the description that values already above 50 should stay there.
I might not be a native speaker, but they told me this part of the description should be pretty straightforward:
the quality of an item can never be negative or increase beyond 50
:)another great one :)
Glad you liked it and thanks for your timing considering my work :)
The description should be more clear w.r.t. three things:
I may not be a native speaker, but "cannot increase above 50" seems pretty clear to me: if it was already 56, it will either go down or stay 56, according to the category; just not increase.
Same for "become negative": no item can be reduced below 0.
The last point may be the trickiest, but you just have to consider the current sell_in value.
@GiacomoSorbi: Excuse me to write here but I have problems with 2 katas of which you certainly are the Python and/or Ruby translator. I marked an issue on each one but I think you won't be notified. http://www.codewars.com/kata/difference-between-biggest-2-numbers/discuss/python http://www.codewars.com/kata/new-gps-system/discuss/python
Sorry if I am too tired and don't see some evidence! I apologize to bother you in your own land:-)
Giake ! . . .
10K - 5 ! ! ! ! !? ? ? no . . . over 10 K !!!!!!!Oh my Code !!!
( Is it a bird ? Is it a plane ? Nope, it's super-Giake ! )
"Jake, what does the scouter says about my honour level?" - "It's... over 10 THOUSAAAAANDS!!!1!!"
Thank you all for your support; including some of my best sparring coders like you :)
Congrats =)
Thanks to you too, noLan :)
Now, if that only reflected me being actually close to the mastery and skill of other top rankers, that would be just perfect, but I'm working on that too :p
[I just realized that I could resemble Nappa a bit, luckily I'm not that bulky; now we only have to see how would Jake look with Vegeta's hair...]
Offtopic: Giacomo, how can I contact you for personal matter?
You certainly can: you can find me on CW gitter channels or by mail:
'moc.liamg]TA[ibros.g'.replace(/]TA\[/,"@").split("").reverse().join("")
(JS to avoid spam bots, let me know if you cannot run the code right now and I'll try to find another way).Here's the gitter link, by the way. (Tip: You can usually extract the email address of any active developer on GitHub by looking at a patch)
@GiacomoSorbi The Link :D ^_^
I expected MMMAAANNN to know about it, as he is often active on the CW issues section on github. Either that or that he would have challenged me to Mortal Kombat in order to get it.
Thanks! I wrote you a letter.
If there are any issues/questions/suggestions about the Java version, leave a comment here. :-)
Very nice kata. Had a lot of fun solving it. :-)
(And congrats on the interview and #1 too of course!)
Thanks for your appreciation and most importantly for your congrats, Darnor :)
I have to admit one the things that really makes CW a special place is the human touch that you get: I doubt I would have received so many kudo in any other place. Thanks to you all, really :)
This comment has been hidden.
Hi Christian and glad to have you interested in my work again :)
Not sure about your code, as it also mentions a +=1 for brie, but here:
It does not work fine, I guess: sell_in has become 10, so you have to raise your quality by 2.
Same for the step 6=>5, which immediately triggers the +3 raise in quality: you have to use the current (=already updated) value of sell_in, not the previous one.
I got there in the end, and my solution is only 5 times as long as yours... :)
Well, in terms of commenting and best practice, you surely beat me hands down.
I particularly liked the print/debug statement that you tend to leave in your work and the clever use of the
delta_quality
variable.This comment has been hidden.
Oh, thanks for pointing me out: I was sure I fixed it already, but maybe it/I didn't save.
As far as this kata goes, I tried to keep the original spirit: to put you down into a relatively messy code and to have you fix it as you see fit. Plus, I preferred to show users (I expect a decent number of beginner to try their hands on this and other bug-fixes kata) how you can build a very simple constructor and then deal with it accordingly; imho this also makes things a bit easier to keep in mind and deal with, but that could be just me.
As your feed is surely precious to me, I will however consider smoothing things a bit putting something into the preloaded tab if a significant number of other fellow codewarrior feel the same pain.
Thanks again for both points :)
This comment has been hidden.
This comment has been hidden.
Creative, fun kata... although as I re-read the instructions, it seems that I was supposed to fix the code that was there rather than start from scratch. Oops. I might have to redo it properly. Regardless, congrats on the interview and on reaching #1.
Thanks for your kind and really appreciated words, sayfidz :)
You may also be interested in knowing that the interview apparently went well and that a Ruby translation should be released tomorrow.
Between you and me, the original code to be fixed/updated was so messy that I ended up basically rewriting it all too in a shorter, more readable and even slightly more efficient version.
And a Ruby translation we now have too.
This comment has been hidden.
Sorry, dumb me: it works fine, it is just that I did a fix and forgot that it would now print out the already "aged" inventory; as a proof, no item was initially created with a negative
sell_in
value (but it could be an interesting twist, what do you think about it?).Fixed now, thanks a lot for the feed :)
Also, I mistyped "mighty", ops.