def sum(arr): var = 0 for i in arr: var += i return var
- def sum(arr):
- var = 0
for i in range(len(arr)):var += arr[i]- for i in arr:
- var += i
- return var
import codewars_test as test # TODO Write tests from solution import sum import random # test.assert_equals(actual, expected, [optional] message) @test.describe("Example tests") def test_group(): @test.it("Basic tests") def basic_test_case(): test.assert_equals(sum([1]), 1) test.assert_equals(sum([1,2,3]), 6) test.assert_equals(sum([]), 0) @test.it("Random tests") def random_test_case(): for i in range(5): test_array = [] test_array_length = random.randint(10, 100) test_array_sum = 0 for j in range(test_array_length): random_number = random.randint(0, 100) test_array.append(random_number) test_array_sum += random_number test.assert_equals(sum(test_array), test_array_sum)
- import codewars_test as test
- # TODO Write tests
- from solution import sum
- import random
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example tests")
- def test_group():
- @test.it("Basic tests")
def test_case():- def basic_test_case():
- test.assert_equals(sum([1]), 1)
- test.assert_equals(sum([1,2,3]), 6)
- test.assert_equals(sum([]), 0)
- @test.it("Random tests")
- def random_test_case():
- for i in range(5):
- test_array = []
- test_array_length = random.randint(10, 100)
- test_array_sum = 0
- for j in range(test_array_length):
- random_number = random.randint(0, 100)
- test_array.append(random_number)
- test_array_sum += random_number
- test.assert_equals(sum(test_array), test_array_sum)