7 kyu

Convert To Scientific Notation

Description
Loading description...
  • Please sign in or sign up to leave a comment.
  • rowcased Avatar
        test.assert_equals(to_scientific(56789), "5.678e4")
        test.assert_equals(to_scientific(50789), "5.078e4")
        test.assert_equals(to_scientific(50089), "5.008e4")
        test.assert_equals(to_scientific(50009), "5.0e4")
        test.assert_equals(to_scientific(56709), "5.67e4")
        test.assert_equals(to_scientific(56009), "5.6e4")
        
        test.assert_equals(to_scientific(456789), "4.567e5")
        test.assert_equals(to_scientific(406789), "4.067e5")
        test.assert_equals(to_scientific(400789), "4.007e5")
        test.assert_equals(to_scientific(400089), "4.0e5")
        test.assert_equals(to_scientific(400009), "4.0e5")
        test.assert_equals(to_scientific(456709), "4.567e5")
        test.assert_equals(to_scientific(456009), "4.56e5")
        test.assert_equals(to_scientific(450009), "4.5e5")
    
  • saudiGuy Avatar

    The input number will always be in the range of 0 < num < 1,000,000,000,000

    This statement is incorrect as random tests can go beyond this range.

  • hobovsky Avatar
        for i in range(100):
            rand_num = randint(1,100000000000)
    

    This is generally a very bad way of doing random tests, because probability of testing interesting inputs is close to 0. For example, there is ultra small chance of having a test for numbers < 1000, and very small chance of having a test for trailing zeros. You need to have better random generators to ensure good coverage of tested scenarios. You can take a look at example kata, especially the "Leap years" one, to see how to ensure good distribution of tested scenarios.

  • hobovsky Avatar

    Example in description: 1000000 -> "1.000e6"

    Tests:

    '6.290e10' should equal '6.29e10'
    '9.400e10' should equal '9.4e10'
    '9.360e10' should equal '9.36e10'
    

    It should be explained how trailing zeros should be handled, and there should be explicit fixed tests, and guaranteed random tests, for inputs with trailing zeros like 1000000 and 1000001.

  • hobovsky Avatar

    The description needs to specify how to handle rounding of the last digit. For example, what is the expected answer for 2345678, or 999999?

  • rowcased Avatar

    This comment has been hidden.