Just realized bug in the problem. If there are 2 negative lengths and 1 positive lengths, it will still return a positive integer. Thus, we test if the cube is valid in the first place.
def kube(l,w,h): if l < 0 or w < 0 or h < 0: return "Invalid Cube" else: return l * w * h
kube = lambda l, w, h: max(l * w * h, 0)- def kube(l,w,h):
- if l < 0 or w < 0 or h < 0:
- return "Invalid Cube"
- else:
- return l * w * h
import codewars_test as test # TODO Write tests from solution import kube # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(kube(7, 9, 4), 252) test.assert_equals(kube(5, 12, 7), 420) test.assert_equals(kube(3, 7, 49), 1029) test.assert_equals(kube(-1,1,4), "Invalid Cube")
- import codewars_test as test
- # TODO Write tests
- from solution import kube
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(kube(7, 9, 4), 252)
- test.assert_equals(kube(5, 12, 7), 420)
- test.assert_equals(kube(3, 7, 49), 1029)
test.assert_equals(kube(-1,1,4), 0)- test.assert_equals(kube(-1,1,4), "Invalid Cube")
Testing for negative numbers
def kube(x, y, z): if x * y * z > 0: return x*y*z if x * y * z < 0: return 0
- def kube(x, y, z):
#your code herereturn x*y*z#return 0- if x * y * z > 0:
- return x*y*z
- if x * y * z < 0:
- return 0
import codewars_test as test # TODO Write tests from solution import kube # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(kube(7, 9, 4), 252) test.assert_equals(kube(5, 12, 7), 420) test.assert_equals(kube(3, 7, 49), 1029) test.assert_equals(kube(-1,1,4), 0)
- import codewars_test as test
- # TODO Write tests
- from solution import kube
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(kube(7, 9, 4), 252)
- test.assert_equals(kube(5, 12, 7), 420)
- test.assert_equals(kube(3, 7, 49), 1029)
- test.assert_equals(kube(-1,1,4), 0)