Beta
Draw a Clock
11jimmyhay
Loading description...
Date Time
Fundamentals
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.
This comment has been hidden.
Yes I realised this is a problem. I have not factored in that the hour hand with move to the location of the minutes. I'll fix this asap. Thanks!
The hour hand should now move in increments of a minute and then minute hand should just move in increments of a minute as it should have been doing so before.
There are still occasionally cases in random tests like this:
It happens when the coordinates are exactly an integer but get floating point errors, e.g
y: 14.000000000000004
.Suggestion: If you're using
AssertApproxEquals
anyways, you don't need to round/floor/truncate the results anymore, so might as well return the numbers directly?Okay, I think I've fixed this now. I have floor'ed the final answer given by the solution so it should match up with the requested answer. Could you give me your solution so I can test it again and see if it works with yours?
If you test with
assertApproxEquals
, you should not do any rounding. It defeats the purpose.Okay, I removed the floor's. Could you tell me how assertApproxEquals works, because it seems to cause some issues with my Example Test Cases now. What is the accuracy that it expects from the answer?
See below.
.toString
works onassertApproxEquals
.You did not remove the
floor
s.I think I have fixed this now, could you give it a test and see what happens?
Flooring is out. Now you have reversed expected values of
x
andy
forminutes
andseconds
, but nothours
. Also, there's a-
too much in there somewhere.Could you please check your stuff before you publish it? Just solve the kata yourself like a normal user, and check your answers for plausibility? Add a couple of easy, fixed tests for this, 1200, 0300, 0730, and check the bloody signs of the expected values. I'm getting a bit tired of this incremental stuff.
Thanks for editing the actual Test Cases accordingly but I think you forgot to edit the Sample Test Cases as well ;)
As for whether the actual Test Cases work, they are buggy when the expected value is extremely close to zero (somewhere around
1e-15
) but that is not your fault (in fact it is mine, I implemented this particular method for the Codewars JS testing framework but I proposed a fix here a while ago) so you may leave it as is :)Obviously I have already done what you suggested. I have put in easy solutions and tested them against the results and on my side they seem to be all correct. Sorry to trouble you.
What I see is you're testing the reference solution against itself and you don't have any fixed Submit Tests. You won't find (existing or newly-introduced) bugs in your reference solution that way.
Either add some fixed Submit Tests, or have (very!) different example and reference solutions (or both. and then fixed-test your reference solution as well. you can take that out before publishing).
Oh, you have
(actual,expected)
switched in the arguments ofassertApproxEquals
. That makes for wrong messages on failure. Both Example and Submit tests.But my solution just passed!
It would seem the tests are now correct. Let's hear from some other people as well, but this looks hopeful.
Phew! Yeh it seems to be working now! I think some of my maths was wrong in the original solution. Sorry it was so drawn out, I was about to give up!
For me it seems correct now (haven't tested/submitted before);-)... So well done:-)...
I think this is all working now.
Tests are not equipped to handle
-0
values. These occur. If-0
is not accepted as0
, I feel this should at least be mentioned. But I really feel they should be accepted as0
.I have put in a statement now that will ignore all negative 0 values and just return them as 0, so -0 should be ignored.
Yep, seems to work.
With
Test.approxEquals
, this is no longer an issue. You could take out the code handling this.With
Test.approxEquals
, this is no longer an issue. You could take out the code handling this.On analog clocks, the hands move continuously, not instantaneously. You are expecting wrong values because you do not account for this.
(Even then, there are rounding errors.)
I'm sure there are some analog clocks that have a ticking mechanism, in which case they should move in an instantaneous manner wouldn't you say? I know what you mean, there are some clocks that do work with a continuous motion, but I think my problem is still a valid task.
Having the hours hand only move to the next full hour on the whole hour is a valid task, but it's not what people expect when they read "analog clock". Would you expect the hours hand to be at twelve at 00:30?
It's worth an explicit mention in the description.
Ah yes I see what you mean. I will try and code it so that the hour hand has to be in the correct position depending on the number of minutes to the nearest minute and the minute hand with just click to the nearest minute. Do you think that would be a good solution?
I initially had all three hands moving once per second, but you can have the hour hand moving once per minute, no problem. Just specify it.
The hour hand should now move once per minute.
Aside from the inaccuracy mistakes below,
y
seems to increase down ??? which is a legal choice, but definitely one to mention in the description.The example in the description is not a valid output of the requested function and is missing
y:
in the hours part.Also, you may want to use
assertDeepEquals
instead ofassertSimilar
. The output is prettier.I had stated in the description that it is set to cartestian co-ordinates but the code didn't represent this. This should be fixed now. Y should be positive when heading north and negative when heading south from (0,0). I also switched it from assertSimilar to assertDeepEquals, thanks.
OK, that seems all fixed.
Please explain how the values are turned into integers. As far as I can observe from the example tests none of the
floor, ceil, round, trunc
works.So the values are turned into integers with Math.floor when you calculate the position using the trigonometric function. There was an issue in there with the Y values being the wrong way around (positive when they should be negative and vice versa), but this should be fixed now. Perhaps try again and see if you can get solve it.
Still some rounding differences. Values are never off by more than one. Seems to happen on all hands; if the difference is in
x
expected value is one more than my actual value, if iny
it's one less.Tried to submit until I got lucky.
Seeing the reference solution, I'm not surprised there are rounding errors.
The best way to do this kind of thing is not rounding any values, and comparing them with a margin for error.
Test.assertApproxEquals
was invented for this situation. If you specifyfloor
, and have final values very close to integers, it is little surprising it sometimes comes out plus or minus one. With all the calculating you do, you introduce a lot of inaccuracies, small ones, but they accumulate, and then they get amplified by thefloor
ing.Can't be done.
At least not better than is already in there.
Could you give me an example of how to use Test.assertApproxEquals with object properties, so that I can compare all the seperate values for each hand?
You have to compare each and every property, which is a bit of writing repetitive code, but you just can't
approxEquals
composite data types. You could put it in a nestedfor
loop andassert( actual[hand][coord], expected[same][same], `smart failure message` )
, but that's probably as much work as just writing it out.Okay I've put the new test cases in so it should test for an approximate answer. Do you know what level of approximation it tests for, like what are the limits?
from the
Test.assertApproxEquals
source: