Beispiel #1
0
    def test_rand(self):
        def randarr(l):
            return [randint(-100, 100) for _ in range(l)]

        def solution(arr):
            return sum(x for x in arr if x > 0)

        for _ in range(40):
            arr = randarr(randint(5, 120))
            self.assertEqual(positive_sum(arr[:]), solution(arr[:]),
                             "Failed with arr = {}".format(arr))
def test_two():
    solution = positive_sum([1,2,3,4])

    assert solution == 10
def test_five():
    solution = positive_sum([-1,-2,-3,-4,-5])

    assert solution == 0 
def test_one():
    solution = positive_sum([1,2,3,4,5])

    assert solution == 15
def test_four():
    solution = positive_sum([])

    assert solution == 0
def test_three():
    solution = positive_sum([1,-2,3,4,5])

    assert solution == 13
 def test_to_matrix_eq(self):
     self.assertEqual(positive_sum.positive_sum([1, 60, -100, 500.5]),
                      positive_sum_ans([1, 60, -100, 500.5]))
     self.assertEqual(positive_sum.positive_sum([0]), 0)
Beispiel #8
0
def test_positive_sum_two():
    solution2 = positive_sum([1, 2, 3, 4, 5])
    assert solution2 == 15
Beispiel #9
0
def test_positive_sum_one():
    solution = positive_sum([1, -4, 7, 12])
    assert solution == 20
Beispiel #10
0
def test_positive_sum_four():
    solution4 = positive_sum([-1, -2, -3, -4, -5])
    assert solution4 == 0
Beispiel #11
0
def test_positive_sum_three():
    solution3 = positive_sum([])
    assert solution3 == 0
def test_positive_sum():
    assert positive_sum([1, 2, 3, 4, 5]) == 15
    assert positive_sum([1, -2, 3, 4, 5]) == 13
    assert positive_sum([-1, 2, 3, 4, -5]) == 9
    assert positive_sum([]) == 0
    assert positive_sum([-1, -2, -3, -4, -5]) == 0
Beispiel #13
0
 def test(self):
     self.assertEqual(positive_sum([1, 2, 3, 4, 5]), 15)
     self.assertEqual(positive_sum([1, -2, 3, 4, 5]), 13)
     self.assertEqual(positive_sum([-1, 2, 3, 4, -5]), 9)
Beispiel #14
0
 def test_negative(self):
     self.assertEqual(positive_sum([-1, -2, -3, -4, -5]), 0)
Beispiel #15
0
 def test_empty(self):
     self.assertEqual(positive_sum([]), 0)