5 kyu
Precise fractions pt. 1 - basics
78 of 231user6626213
Loading description...
Algorithms
Mathematics
Puzzles
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.
duplicate
https://www.codewars.com/kata/5260074c9a0022f83e0009da
This kata is not Python 3 compliant.
This comment has been hidden.
No random test of JS/Python/Java.
Good chance I am getting confused here, but this test doesn't appear to be correct to me.
"Test.assertEquals(new Fraction(5, 3).add(new Fraction(1, 3)).toString(), '2/3', 'Proper addition was expected');"
I am reading that as 5 thirds (5/3) + 1 third (1/3). To me the answer should be 6 thirds (6/3) OR 2 wholes (2).
Am I getting this wrong?
I'm getting confused here as well - I don't see a test case you mentioned :) maybe you have edited it yourself in your test suite by accident?
Must be as you say - I copied what I had and reset and was able to move on. Thanks for getting back to me.
Getting an error saying that numerator or denominator cannot be 0 but I already have an if-statement that throws an exception if either of them are 0's in the constructor. Why doesn't this work? What are you looking for to happen in this case??
// The test I wrote just to see if the program throws an exception, and it does. Still won't let me submit though assertEquals("Numerator or Denominator cannot be zero", null, new Fraction(0,1));
(Java) current OP code passes the kata --> issue not reproducible
JavaScript: Could do with test cases for the type of the return values of the arithmetic methods.
I glimpsed a solution that returned
String
s instead ofFraction
s. This passed because return values are only testedtoString()
ed, andString.toString()
returns the sameString
.I would like to see more specific test cases. Sometimes I was sitting there trying to analyze a failing test just to notice that it was actually some other test that failed. I think it's best practice to have one assertion per test. Thus I would like to see methods like:
@Test public void testWithNegativeNumbers() { assertEquals("-1/2", Fraction.new(1, -2)); }
and so on. Also I think a fraction class like this would benefit of methods to compare two fractions. Maybe that's too annoyingly borring but I already thought that after the add() method.
Hi, I've added a Python translation, if you want to approve it, instructions for the approval process are here.
There were a couple of minor issues with the kata:
It explicitly says this "(however there will never be two negative values at the same time)" and yet there is a test that does pass in two negative values.
You have a typo in your code -
substract
should besubtract
Other than that all good! :)
This just reminded me of how annoying programming is in languages like Java.
[troll] the only reason to (try to) solve java-katas is to be able then to translate them in other languages [/troll]
:)
Yup, I'll deliver a Python translation in a moment! :D
And... done! :D
Under JavaScript: Shouldn't the method be
subtract
, notsubstract
(notice the extras
)?If you don't want to invalidate everyone's solution, you can do something like this at the top of your test code:
You're right - well, English is not my native language, and it seems I was always wrong about this word :) Thanks for JS solution, however I suppose I will have to invalidate others' solutions in Java to correct this missspeling :(
I've been trying to fix this spelling for 5 days now, and while I had no problems with JS, re-publishing Java version does not work for me. It just hangs forever and only telling me to wait.
Glad I saw this, was confused as to why I was getting "could not find symbol" errors in Java
I like this kata. Not too taxing, but makes you brush up on your fraction arithmetic ;P