5 kyu

Precise fractions pt. 1 - basics

78 of 231user6626213
Description
Loading description...
Algorithms
Mathematics
Puzzles
  • Please sign in or sign up to leave a comment.
  • dfhwze Avatar

    This kata is not Python 3 compliant.

  • KataSideKick Avatar

    No random test of JS/Python/Java.

  • exodusgilhagen Avatar

    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?

  • ThomasJazz Avatar

    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));

  • JohanWiltink Avatar

    JavaScript: Could do with test cases for the type of the return values of the arithmetic methods.

    I glimpsed a solution that returned Strings instead of Fractions. This passed because return values are only tested toString()ed, and String.toString() returns the same String.

  • haferjir Avatar

    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.

  • ChristianECooper Avatar

    Hi, I've added a Python translation, if you want to approve it, instructions for the approval process are here.

  • ChristianECooper Avatar

    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 be subtract

    Other than that all good! :)

  • muesli4 Avatar

    This just reminded me of how annoying programming is in languages like Java.

  • OverZealous Avatar

    Under JavaScript: Shouldn't the method be subtract, not substract (notice the extra s)?

    If you don't want to invalidate everyone's solution, you can do something like this at the top of your test code:

    if(!Fraction.prototype.subtract) Fraction.prototype.subtract = Fraction.prototype.substract;
    
  • wthit56 Avatar

    I like this kata. Not too taxing, but makes you brush up on your fraction arithmetic ;P