"""
Exercise 3: sliding-window queue with deque

Implement RecentAverage, a class tracking a sliding window of the last
`window_size` numbers added, using collections.deque with `maxlen` so
old values fall off automatically.

  RecentAverage(window_size)
  .add(value) -> adds a value, evicting the oldest if over window_size
  .average()   -> returns the average of values currently in the window
                  (0.0 if empty)

Use collections.deque(maxlen=window_size) — do NOT implement eviction
manually with a list.
"""

from collections import deque


class RecentAverage:
    def __init__(self, window_size):
        # TODO: store a deque with the given maxlen.
        pass

    def add(self, value):
        # TODO: append value; deque handles eviction automatically.
        pass

    def average(self):
        # TODO: return average of current window, 0.0 if empty.
        pass


# --- self-check: do not modify below this line ---
ra = RecentAverage(3)
checks = []

checks.append((ra.average(), 0.0))
ra.add(10)
checks.append((ra.average(), 10.0))
ra.add(20)
checks.append((ra.average(), 15.0))
ra.add(30)
checks.append((ra.average(), 20.0))
ra.add(100)  # evicts 10
checks.append((ra.average(), 50.0))  # (20 + 30 + 100) / 3

is_deque = isinstance(ra._window if hasattr(ra, "_window") else None, deque) or \
           any(isinstance(v, deque) for v in vars(ra).values())
checks.append((is_deque, True))

all_passed = all(actual == expected for actual, expected in checks)
for actual, expected in checks:
    print(f"got {actual!r}, expected {expected!r} -> {'PASS' if actual == expected else 'FAIL'}")

print("ALL PASS" if all_passed else "SOME FAILED")
