Retired

CIS 122 #5 Functions and Return Values (retired)

Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • slyluckett Avatar

    I got everything fixed but Unit Tests for calculate_volume Argument is Real: '523.5987666666666' should equal '523.598766667' Argument is String: '33510.321066666664' should equal '33510.3210667' Test Passed

    I'm confused on what's going on here. Why it's saying my argument is string and should equal the number that is rounded. A few more are:

    Integration Tests for input_radius_of_sphere -> calculate_volume Test Passed Return result from calculate_volume: '1436.7550157333335' should equal '1436.75501573' Test Passed Test Passed Test Passed Test Passed

    Integration Tests for calculate_volume -> output_volume Argument is Real: 'The volume of a sphere with radius 15.3 is: 15002.474399373603' should equal 'The volume of a sphere with radius 15.3 is: 15002.4743994' Test Passed Test Passed

    System Tests for calculate_volume_of_sphere Test Passed First run, output: 'The volume of a sphere with radius 3.6 is: 195.43219246080002' should equal 'The volume of a sphere with radius 3.6 is: 195.432192461' Test Passed Second run, output: 'The volume of a sphere with radius 6.9 is: 1376.0552579112002' should equal 'The volume of a sphere with radius 6.9 is: 1376.05525791' Test Passed Third run, output: 'The volume of a sphere with radius 4.2 is: 310.3390833984001' should equal 'The volume of a sphere with radius 4.2 is: 310.339083398'

    I'm confused

    • CIS 122 Avatar

      The radius parameter in calculate_volume is a float. So, be sure to use float(radius) in your calculation.

  • temo Avatar

    The following section of code is not correct:

    x_print(output_volume(5.0, calculate_volume(5.0)))

    x_print(output_volume("10.0", calculate_volume("10.0")))

    x_print(output_volume(15, calculate_volume(15)))

    In order to pass the tests the section should read as follows:

    output_volume(15.3, calculate_volume(15.3))

    output_volume("30.0", calculate_volume("30.0"))

    output_volume(15, calculate_volume(15))

  • Voile Avatar

    There are absolutely no checks on function invocation.

    What, you say you don't know how to do that? Learn some basic Python metaprogramming first. It's perfectly doable.

  • ryanaspooner Avatar

    There are mistakes in the CALCULATE VOLUME OF A SPHERE integration test drivers.

    x_print(output_volume(15.3, calculate_volume(15.3))) x_print(output_volume("10.0", calculate_volume("10.0"))) x_print(output_volume(15, calculate_volume(15)))

    should be

    output_volume(15.3, calculate_volume(15.3)) output_volume("30.0", calculate_volume("30.0")) output_volume(15, calculate_volume(15))

    • btripp1990 Avatar

      Thank you! I was really beating my head against the wall on this one. Before changing these test statements, the program kept printing a value of "None". When I changed it to what you suggested though it worked.

    • Len512 Avatar

      Thanks!

  • glc Avatar

    I'm having a weird error on the last test. My error message is that the system test call on interactive_add_numbers() is invalid syntax. I copied and pasted my code from here to an IDE and it seemed to work fine in there, so I don't know what the problem here would be. I rechecked the name of my function definition and it seems to be correct.

  • pccheng Avatar

    There is an issue on "Integration Tests for calculate_volume -> output_volume"

    expectation: test.it("Integration Tests for calculate_volume -> output_volume") test.assert_equals(print_output[25], "The volume of a sphere with radius 15.3 is: 15002.4743994", "Argument is Real") test.assert_equals(print_output[26], "The volume of a sphere with radius 30.0 is: 113097.3336", "Argument is String") test.assert_equals(print_output[27], "The volume of a sphere with radius 15.0 is: 14137.1667", "Argument is Integer")

    tests in code:

    Then, we'll "integration test" that the units work together:

    ...

    x_print(output_volume(5.0, calculate_volume(5.0))) x_print(output_volume("10.0", calculate_volume("10.0"))) x_print(output_volume(15, calculate_volume(15)))

    Are we expected to change the values of the tests or to change the expected value in the testcases?

  • smile67 Avatar

    I think there is a mistake in testcases, passes 70 tests, everything is ok but throws "You didn't use all the inputs!"? So i took you expected output (instead of my code), inserted it into the editor and same result... So in my opinion something is wrong?! But don't know why i can see "3 Solutions and 4 Upvotes"?

    • CIS 122 Avatar

      The test cases check not only that you have the correct output, but that you've called input the correct number of times to match the pseudocode. Are you actually using the input function everywhere that the pseudocode says Input ?

    • smile67 Avatar

      Yes... did it as described and requested... But at least i changed it and tested with your output results (converted to "x_print" commands)... so now my real solution is deleted (closed this kata/editor)... I think generally it's a very nice series of katas for learning, but each kata is a little bit too long (in my opinion;-)), too much text (for easy circumstances) and thereby too many possibilities to loose view and "concentration" and the overview of testcases (somtimes around 200 lines)...

    • mark.curran Avatar

      I don't under stand the kata at Line 289: output_volume(5.0, 10.0) # Not really the correct answer, just testing output output_volume("10.0", "30.0") # Not really the correct answer, just testing output

      Changed 10.0 to 20.0 in the line above to get it to work. Don't think that is right.

      output_volume(15, 50) # Not really the correct answer, just testing output

      If I change the second line as described, it passes this and then the next set is messed up. Are we supposed to be changing these? I don't think the errors are supposed to be correct. Not sure what is expected here.

      I can't get to the rest of the kata without getting passed this part. Any input would be greatly appreciated.

    • CIS 122 Avatar

      The initial solution didn't match the test case, so I fixed it. This works, if everything else is correct:

      def output_volume(r, v): 
          x_print("The volume of a sphere with radius", float(r), "is:", float(v))
          
      def calculate_volume_of_sphere():
          r = float(input_radius_of_sphere())
          output_volume(r, float(calculate_volume(r)))
      
      x_print(input_radius_of_sphere())
      x_print(input_radius_of_sphere())
      x_print(input_radius_of_sphere())
      
      x_print(calculate_volume(5.0))
      x_print(calculate_volume("20.0"))
      x_print(calculate_volume(30))
      
      output_volume(5.0, 10.0) # Not really the correct answer, just testing output
      output_volume("20.0", "30.0") # Not really the correct answer, just testing output
      output_volume(15, 50) # Not really the correct answer, just testing output