5 kyu
Rotations and reflections I
168 of 232geoffp
Loading description...
Object-oriented Programming
Design Patterns
Geometry
Mathematics
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.
For Java I'm pretty sure JUnit 5 allows to put assertion messages into assert methods. With that, you can properly output the assert notes without workarounds or so (consult with JUnit 5 example on docs.
About C++, Snowhouse actually allows to implement assertions as well, although in a more tricky way.
Finally, these messages are crucial for true/false checking, because otherwise you can get obscure output about expected true and actual false without any sign on where was that message invoked or smth :/
Language: C++
Initial solution are completely empty and in turn generates errors.
That's intentional. For this kata, you have to write an entire class from scratch.
It is unclear what the inverse of a reflection is.
With rotation, reverse can be defined as an operation to undo the operation, or an operation which of the opposite direction.
I am however having problems in inversions of a reflection. If it is to bring back the operation to origin, then its the inverse of itself (which is mathematicaly correct but feels "too easy"); If it is the lexicon opposite, then it would be a flip of 90 degrees (eg. vertical -> horizontal). Neither currently works in my code, and until the ambiguity is cleaned up, it will be hard to bugfix.
Part of the problem is that there are no inversions of a reflection in the visible tests. One additional test will fix this issue.
A reflection is its own inverse. Performing the reflection twice returns every point to its original position.
Apologies. Like any other "unresolvable" bug, it turned out to be a typo. I was unknowingly recalculating my return value using bugged out code, and did not notice. The disambiguity finally helped me narrow down the location of the bug.
So please consider adding that one test line to the code. It's pathetic, I know, but it would have saved me over an hour of my time, by being certain the problem was in the code, not in my logic.
A sample test has been added.
It's not clear which of the 45-degree diagonals correspond to
forward diagonal
andreverse diagonal
respectively.The description has pictures of all the transformations, and then lists their names, noting that the names are given in the same order as the pictures. I think that makes it clear which name goes with which picture. There is also an example test-case to further clarify which diagonal is the reverse one.
Can't seem to pass
Is_Rotation_and_Is_Reflection_Tests
in c++. I checked the return value of both member functions and that looks correct, but the test still fails. Is there a third part of this test?Is_Rotation_and_Is_Reflection_Tests
just checks the return values ofis_rotation()
andis_reflection()
for each of the 8 possible values; that's all.If you're still stuck, post your code here (with a Spoiler flag) and I'll try to figure out what the problem is.
This comment has been hidden.
This comment has been hidden.
Approved
Very interesting one. But I think the description lacks something to make it a bit less cryptic (especially in Java ; I do not know C++)): that could explain the satisfaction rate which is abnormally low.
Saddly, I can't really find suggestions to add... In Java, a first drawback is that your test class extends Dih4. That's quite unusual (at least on CW) and that conditiones a part of the tasks to complete with the constructors. Maybe you could add that the constants will be Dih4 instances too.
I have a Problem while declaring the constants: It seems like the constants have to be in a
namespace Dih4
since they are called asDih4::IDENTITY
in the example code. On the other hand the example code expects aclass Dih4
. But I cannot have aclass
andnamespace
of the same name in the same scope. I also cannot declare the constants asstatic const
members since theclass
is not completed at that point. What am I missing?Edit: Solved it. I just had to define the static members outside of the class.
Yes, the constants are meant to be static members of the class. But (this trips me up a lot too) declaring a static constant in a C++ class is like declaring a function signature: it doesn't actually generate any binary code, it just tells the compiler that this thing ought to exist.
The following transformation test expected result seems wrong (Java). All the clockwise/anticlockwise seem around the wrong way
And this one..
And...
And...
And this..
And...
And..
And...
~~~
If I make hacks to match all those transformation tests then everything else is OK and I am able to pass
The (expected) results are correct as they stand.
For example:
REFLECT_VERTICAL
takes the top left corner of the square to the top right corner; if we then applyREFLECT_FORWARD_DIAGONAL
the top right corner stays put. So the overall effect is that of a 90-degree clockwise rotation.Remember that
REFLECT_VERTICAL
means the mirror line is a vertical line (so the actual displacement of each point transformed is horizontal); the other 3 reflections are named analogously. I realize that these names are slightly ambiguous; happy to take any suggestions on better ones.Oops. The names and everything else are fine as-is. The error was enitirely mine by doing this kata while sleepy and thinking the "then" transformation I needed was the one to get back to the IDENTITY instead of from the IDENTIY - which meant everything was right except all my 90 rotations were backwards :-(
Sorry for your trouble.
Nice kata by the way - It was a welcome change to code a class from scratch instead of just how to write some algorithm.