File: test_exercise_1.py

package info (click to toggle)
python-memray 1.17.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 24,396 kB
  • sloc: python: 28,451; ansic: 16,507; sh: 10,586; cpp: 8,494; javascript: 1,474; makefile: 822; awk: 12
file content (56 lines) | stat: -rw-r--r-- 1,346 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pytest
from exercise_1.fibonacci import generate_fibonacci_hash

# Memory tests


@pytest.mark.limit_memory("100 KB")
def test_fibonacci():
    LENGTH_OF_SEQUENCE_1 = 33333  # pylint: disable=invalid-name
    LENGTH_OF_SEQUENCE_2 = 30000  # pylint: disable=invalid-name
    LENGTH_OF_SEQUENCE_3 = 34567  # pylint: disable=invalid-name

    generate_fibonacci_hash(
        LENGTH_OF_SEQUENCE_1, LENGTH_OF_SEQUENCE_2, LENGTH_OF_SEQUENCE_3
    )


# Correctness tests


def test_fibonacci_empty():
    h = generate_fibonacci_hash(0, 0, 0)
    assert h == 0


@pytest.mark.parametrize(
    ("length", "expected"),
    [
        (1, 1),
        (2, 2),  # 1 + 1
        (6, 20),  # 1 + 1 + 2 + 3 + 5 + 8
    ],
)
def test_fibonacci_short(length, expected):
    h = generate_fibonacci_hash(0, 0, length)
    assert h == expected


@pytest.mark.parametrize(
    ("length", "expected"),
    [
        (1, 1),
        (2, 2),  # 1 + 1
        (6, 20),  # 1 + 1 + 2 + 3 + 5 + 8
    ],
)
def test_fibonacci_multiple(length, expected):
    h = generate_fibonacci_hash(length, length, length)
    assert h == expected * 3


def test_hash_modulo_10000():
    # 1 + 1 + 2 +3 + 5 + 8 + 13 + 21 + 34 + 55 + 89 + 144 + 233 + 377 + 610
    # + 987 + 1597 + 2584 + 4181 == 10945
    h = generate_fibonacci_hash(0, 0, 19)
    assert h == 945  # 10945 % 10000