Beispiel #1
0
def test_two_sums():
    """Test of the example given in the description"""
    numbers = [3, 10, 14, 8, 15, 5, 16, 13, 9, 2]
    expected = (2, 6)
    target = 30
    result = two_sums(numbers, target)
    assert result == expected
Beispiel #2
0
def test_two_sums_random():
    seed(1)
    numbers = sample(range(1, 1_000_000), 1_000)
    picked = sample(numbers, 2)
    index1 = numbers.index(picked[0])
    index2 = numbers.index(picked[1])
    ordered = sorted([index1, index2])
    expected = ordered[0], ordered[1]
    target = sum(picked)
    result = two_sums(numbers, target)
    assert result == expected
Beispiel #3
0
def test_two_sums_none():
    result = two_sums(NUMBERS, 7000)
    assert result is None
Beispiel #4
0
def test_two_sums_param(target, expected):
    result = two_sums(NUMBERS, target)
    assert result == expected