File size: 3,356 Bytes
75482e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""
Example test file used to demonstrate HissCheck.
Contains a deliberate mix of shallow, partial, and solid tests.
"""
import math


# ── The code under test (inline for demo simplicity) ──────────────────────

def divide(a: float, b: float) -> float:
    if b == 0:
        raise ValueError("Cannot divide by zero")
    return a / b


def celsius_to_fahrenheit(c: float) -> float:
    return c * 9 / 5 + 32


class Stack:
    def __init__(self):
        self._data = []

    def push(self, item):
        self._data.append(item)

    def pop(self):
        if not self._data:
            raise IndexError("pop from empty stack")
        return self._data.pop()

    def peek(self):
        return self._data[-1] if self._data else None

    def is_empty(self):
        return len(self._data) == 0


# ── Tests ──────────────────────────────────────────────────────────────────

class TestDivide:

    # SHALLOW: only checks the function exists and is callable
    def test_divide_exists(self):
        assert callable(divide)

    # SHALLOW: only checks the return is not None
    def test_divide_returns_something(self):
        result = divide(10, 2)
        assert result is not None

    # SOLID: verifies correct arithmetic
    def test_divide_basic(self):
        assert divide(10, 2) == 5.0
        assert divide(9, 3) == 3.0
        assert divide(-6, 2) == -3.0

    # SOLID: verifies the documented error case
    def test_divide_by_zero_raises(self):
        import pytest
        with pytest.raises(ValueError, match="Cannot divide by zero"):
            divide(1, 0)

    # PARTIAL: tests a happy path but misses edge cases like negative temps
    def test_celsius_happy_path(self):
        assert celsius_to_fahrenheit(0) == 32
        assert celsius_to_fahrenheit(100) == 212


class TestStack:

    # SHALLOW: only checks the type
    def test_stack_is_instance(self):
        s = Stack()
        assert isinstance(s, Stack)

    # SHALLOW: checks is_empty exists via hasattr
    def test_stack_has_is_empty(self):
        s = Stack()
        assert hasattr(s, "is_empty")

    # SOLID: verifies LIFO order with multiple elements
    def test_stack_lifo_order(self):
        s = Stack()
        for item in [1, 2, 3]:
            s.push(item)
        assert s.pop() == 3
        assert s.pop() == 2
        assert s.pop() == 1

    # SOLID: verifies the edge case of popping from an empty stack
    def test_stack_pop_empty_raises(self):
        import pytest
        s = Stack()
        with pytest.raises(IndexError):
            s.pop()

    # PARTIAL: tests peek returns something but doesn't verify the value
    def test_stack_peek_not_none(self):
        s = Stack()
        s.push(42)
        assert s.peek() is not None

    # SOLID: full peek behaviour including empty-stack case
    def test_stack_peek_correct_value(self):
        s = Stack()
        assert s.peek() is None          # empty stack
        s.push(7)
        assert s.peek() == 7             # peek sees top
        s.push(99)
        assert s.peek() == 99            # peek updates after push
        s.pop()
        assert s.peek() == 7             # peek restores after pop