7 kyu

Area of a Circle

3,850 of 12,307austinc
Description
Loading description...
Fundamentals
Algorithms
Geometry
Mathematics
  • Please sign in or sign up to leave a comment.
  • ejini战神 Avatar

    Sample and fixed tests such as 0.23 and 0.785 should be added across all languages to invalidate such solutions

  • ejini战神 Avatar

    Description should be language-agnostic

  • Chrono79 Avatar

    Error messages are confusing, at least in javascript:

    expected [Function] to throw 'Error' but 'Error' was thrown
    
  • sergey-samoylov Avatar

    Was really confused by "raise ValueError" part. Tried to do it as usual in try: except: blocks. The code worked fine locally, but not here in Codewars. This kata tests should either include tests for another methods of raising ValueError or change description. For codders to come: do not use try/except here. You'll find the right way quicker to get through this kata.

  • kristofer11 Avatar

    Should this maybe be 8 kyu?

  • hobovsky Avatar

    Ruby: strict equality assertions should be changed to fuzzy equality.

  • HartlIKS Avatar

    TypeScript translation (literal translation of JavaScript; author inactive)

  • StariP Avatar

    It is not described what value should "pi". "should test for something" error, isn't that testmakers job? Overall badly made kata.

  • akar-0 Avatar

    Kata is underspecified for C#:

    • One must throw ArgumentException when argument is invalid, and not return a boolean;
    • the input is considered invalid when containing the character ",", which is not obvious since the native float parser interprets it like a dot when needed.
  • ejini战神 Avatar

    Floating point comparison should be enforced in all languages

  • Thirdkoopa Avatar

    Test is broken since there's no actual test - someone may want to fix that?

  • user6552504 Avatar
  • Chrono79 Avatar

    Some tests in Python have a wrong error message, if you need to calculate the area, and you calculate it wrong, why would you get "Incorrect radius" instead of "Incorrect area"?

  • VanoKi Avatar

    pleaze help, i got the result: "Incorrect radius: 28010755666909.71 should equal 452.39", but why?

  • pietroDelaSirup Avatar

    I forgot to rounded and my solution passed succesfully...

  • falek-marcin Avatar

    For Python 3.6 the test option is buggy, only the attemp option can be used.

    Traceback (most recent call last):
      File "main.py", line 3, in <module>
        import codewars_test as test
    ModuleNotFoundError: No module named 'codewars_test'
    
  • geezen Avatar

    Description is not correct for Java when comparing to test cases.

    1. Asks to return 'false' for illegal input, but tests for 'IllegalArgumentException'
    2. Asks to round to two decimals but no rounding at all is also accepted.
  • Haksell Avatar

    Python version should use snake_case.

  • VitaliiChekalenko Avatar

    In Java you need to throw new IllegalArgumentException if radius <=0 .

    Good luck :)

  • hobovsky Avatar

    Issues with Java version:

    • Requirement for the case when radius is not a number is not tested (NaN, and maybe +/-Inf?).
    • Description is not good for radius <= 0, it says "return false " while tests expect an IllegalArgumentException
    • Rounding requirement (oh God, WHY?!) is ineffective, because assert tolerance is large enough to make any rounding superfluous.
  • louis012345678 Avatar

    it says return 'false' if the radius is not a number but c# wants a double being returned and 'false' isnt a double so gives an error

  • sogr Avatar

    some thing about round() in Kata?? Noooo

  • hezhenxing Avatar

    This comment has been hidden.

  • Kaiyou Avatar

    C#:

    If the string has a , throw that argumentException

    This should really be part of the description and not come as a surprise last minute test case.

  • secondID Avatar

    ✘ Returned string - Expected: 23440.86, instead got: 23440.86...LOL what is this question :D

  • saroff Avatar

    How i must return false in Java?

  • Javatlacati Avatar

    CoffeeScript translation kumited! Please accept :D

  • stnmonroe Avatar

    This comment has been hidden.

  • eyp Avatar

    The description is completely wrong for languages as Java or C#. It doesn't work for numbers between 0 and 1, also doesn't say anything about throwing exceptions.

  • massimocode Avatar

    We should definitely update the instructions to say that the C# exercise requires you to throw an exception. This has caused lots of confusion.

  • HelloWorlder1907 Avatar

    This comment has been hidden.

  • HelloWorlder1907 Avatar

    what value for pi should we use?

  • mfossel Avatar

    How do I get it to throw an Argument Exception? Seems like everything works with my code but I'm not getting the proper error codes that the kata wants. I'm using try, catch, and throw but I can't seem to get the ArgumentException that it stupidly needs. Pretty annoying actually, this is not a helpful problem.

  • vietthaotran Avatar

    The description says "fuction circleArea" while the test case uses "area".

  • lennyparisi Avatar

    You can't return a boolean in a function that is supposed to return a double...?

  • Madiba Avatar

    Hey, I see that the results for this kata was as expected but the test results indicate as failed. What am I missing here ?

    Returned string - Expected: 13592.24, instead got: 13592.24 0 Passed 1 Failed 0 Errors Process took 56ms to complete

  • Seigu Avatar

    Would recommend updating discription to say throw IllegalArgumentException instead of return false.

  • Luasandros Avatar

    Maybe it's a silly question but how can i return a double when the output type of the method "area" is a boolean?

  • Delacroix23 Avatar

    There should be test case for max number of long range ...

  • Uhaba Avatar

    Incorrect! For input string: "14,604.049492"

    Are you bloody kidding me?????? Where is my error message, what is the expected value? What is going wrong at all. This kata is a TERRIBLE fit for java. Improve!

  • klausklapper Avatar

    Shouldn't the provided solution check for "radius <= 0" instead of "radius < 1"? Somebody might go ahead and offer a radius of "0.223" which is per se not a negative number?

  • OlafTheSnowMan Avatar

    nice.....thanks....awesome.....yes....nicee..

  • super_ars Avatar

    I would also add some test with "r" being Fraction and Decimal.

  • nexus44 Avatar

    This comment has been hidden.

  • k4kush Avatar

    getting this error, /CircleTest.java:19: error: no suitable method found for assertEquals(String,double,String,double) assertEquals("Wrong area for radius: " + x, (new BigDecimal(Math.PI * x * x)).setScale(2, RoundingMode.HALF_UP).doubleValue(), Circle.area(x), 0.01); ^ i have only the default test.

  • Azuaron Avatar

    If the string has a ',' throw that argumentException ;)

    Taking away default functionality doesn't make you clever.

  • ponytaylor Avatar

    My tests pass, but I get "Unknown Error" when I try to Submit.

    The requirement to not support thousands commas should be in the description.

  • noiseyCoder Avatar

    Is it just me, or is anyone else getting "submission time-outs" when trying to test the code? It won't let me test this code for the life of me....

  • bstenzel Avatar

    This kata made my skin crawl. Check your basic math: zero is a perfectly valid positive number. So the description should be "non-zero positive number". If comma notation shouldn't be supported (which is kinda silly, really), that should be in the description too. The "two decimal places" thing is where the skin crawl really begins. Floating point numbers simply don't work like that. Would have made more sense to expect a string result.

    I would expect the katas here to promote good coding behavior instead of enforcing that kind of behavior that will come back to bite you at some point. Sad face.

  • Azcion Avatar

    [Python] The tests field was empty. How about you put this there?

    import unittest
    
    class Tests(unittest.TestCase):
        def testInt(self):
            self.assertEqual(circleArea(68), 14526.72)
        def testFloat(self):
            self.assertEqual(circleArea(43.2673), 5881.25)
        def testZero(self):
            self.assertEqual(circleArea(0), False)
        def testNeg(self):
            self.assertEqual(circleArea(-1485.86), False)
        def testStr(self):
            self.assertEqual(circleArea("number"), False)
            
    
    def main():
        unittest.main()
    
    if __name__ == '__main__':
        main()
    
  • tansaku Avatar

    The description for this kata talks about returning false when the haskell version should return Nothing - that is obvious from the test, but the description should be updated.

  • Bruteforce Avatar

    If you only support "Dotted Notation Format" then please say that before the test that also gives the annoying smiley.

  • emporio Avatar

    Another poorly written kata.

    "Returned string - Expected: 4258.15, instead got: 4258.15" ??

    Please improve the description so we know exactly what's expected.

  • tansaku Avatar

    So I'm a bit confused by this error:

        Couldn't match expected type `Maybe Double'
                    with actual type `Double'
    

    like, shouldn't these match. I'm returning a double (or not) with an if statement. Shouldn't the circleArea :: Double -> Maybe Double allow a double or a non-double to be returned?

  • james64 Avatar

    There is a requirement to round the result yet it is not tested by final test cases. I forgot for a while and submited solution without formating which was accepted. Solutions of other warriors are how we learn stuff here. Therefore we should try not to let "wrong" solutions pass the tests here ... I think :)

  • ramya-n Avatar

    Hi,

    Is there any explanation why the below error is occuring although my code is working fine in other interpreter & browser JS console:

    Returned string - Expected: 1089.46, instead got: 1089.00

    I understand it returned string value rather than actual number value; I would appreciate if it can be resolved;

  • stranac Avatar

    Mentioning the wanted precision in the problem description would be nice.
    Or, even better, having tests that check if the answer is close enough, rather than expecting absolute precision in calculations with floats.

  • lihyen Avatar

    Returned string - Expected: 3440.29, instead got: 3440.29

    :(

  • Excludos Avatar

    Java version desperately needs clarification in descripton. It asks to return a number or false. I didn't realise before after implementing object returning that its actually asking for IllegalArgumentException.

  • JotaB Avatar

    This comment has been hidden.

  • Fadeiar Avatar

    This comment has been hidden.

  • myamotomusashi Avatar

    This comment has been hidden.

  • computerguy103 Avatar

    The description doesn't say whether it should return false if the radius is a string containing a number. Should circleArea("5") === circleArea(5), or should circleArea("5") === false?

    It says that if the radius isn't a number, it should return false, but due to Javascript's loose typing, it's not clear whether "5" should be treated as a valid radius or not since it's actually a string. Many of the Javascript solutions will treat it like it's a number.

    The description needs to be updated to add examples showing whether a string should be treated as if it's a number or not, and some test cases should also be added to test that.

  • Steelcrow14 Avatar

    Returned string - Expected: 2253.18, instead got: 2253.18

    So broken.

    P.S.: JS.

  • Tgc Avatar

    Test cases really suck for this Kata (at least in Java version). There are plenty wrong solutions accepted that don't round up the result.

  • mchaperc Avatar

    This comment has been hidden.

  • Bonsanto Avatar

    I didn't round the numbers and it accepted my solution, please fix it :)

  • nickie Avatar

    The task description for Java should mention that an IllegalArgumentException is expected to be thrown in case the radius is not valid. Instead, it suggests that false be returned, which is clearly not an option here...

  • mythcyrax Avatar

    Returned string - Expected: 6389.24, instead got: 6389.24 ???

  • wxl Avatar

    This comment has been hidden.

  • ohwowle0js Avatar

    Can anyone explain how type checking works here? Top solutions don't check for number's type. They just check for " > 0". Does it cover every possible case? So whatever input we give, if it's value is > 0, then it's a number?

  • Amehc Avatar

    I got "Test didn't pass: Unknown error". But i'm doing well using repl.it and my local node server ... Need help!

  • desmondw Avatar

    You might want to revise the description to specify that the radius must be positive. Currently it says it must be non-negative but then fails if a radius of 0 is calculated and returned.

  • regfox Avatar

    This comment has been hidden.

  • hksong Avatar

    This comment has been hidden.

  • beefchip Avatar

    This comment has been hidden.

  • Distort3d Avatar

    My solution returns the expected value properly, however still receives an incorrect response. Here are two examples: Returned string - Expected: 7248.43, instead got: 7248.43 Returned string - Expected: 11905.95, instead got: 11905.95

    It seems that all my tests also pass when using Test.assertSimilar while Test.assertEquals will mark my two place decimal responses as receiving what is not expected. I believe it may have something to do with the way I have truncated the return to two decimal places. Is it part of the challenge to return the expected number in a particular way or is this a bug?

  • austinc Avatar

    I've randomized the radii, provided better examples and improved the error messages. They should now tell you if you are submitting a string, NaN, etc.

  • FesterBesterTester Avatar

    Maybe add some random test cases, so a hardcoded solution isn't possible.

  • SagePtr Avatar

    This comment has been hidden.

  • wthit56 Avatar

    Could you add some edge-case examples in your examples? If someone (like me) skim-reads the instructions (finding the area of a circle isn't usually that involved), the examples should give them pause and push them to investigate further. Also, if we are already handling some edge-cases, you could add value validation (type, non-NaN, non-Infinity, etc.).