{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a43d6da8",
   "metadata": {},
   "source": [
    "# 19-30 · Тестируем правила игры\n",
    "\n",
    "Практика к разделу [«Тестируем правила игры»](../../site/chapters/glava-19/19-30-testiruem-pravila.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ee42f61",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Написать тест, который ловит намеренно сломанную версию функции."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "53449dd9",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "be406e65",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:54:32.601273Z",
     "iopub.status.busy": "2026-09-03T00:54:32.601149Z",
     "iopub.status.idle": "2026-09-03T00:54:32.626824Z",
     "shell.execute_reply": "2026-09-03T00:54:32.626382Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "def is_wall_collision(head, half=280):\n",
    "    x, y = head\n",
    "    return abs(x) > half or abs(y) > half\n",
    "\n",
    "def is_wall_collision_BROKEN(head, half=280):\n",
    "    x, y = head\n",
    "    return abs(x) >= half or abs(y) >= half   # >=, не > — раздел 19.31, Debug Lab 11\n",
    "\n",
    "def test_boundary_is_safe(fn):\n",
    "    return fn((280, 0)) is False\n",
    "\n",
    "print(test_boundary_is_safe(is_wall_collision))\n",
    "print(test_boundary_is_safe(is_wall_collision_BROKEN))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3545628",
   "metadata": {},
   "source": [
    "## Задание ★★ Найдите, какая версия ломает тест"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6b391d3a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:54:32.628388Z",
     "iopub.status.busy": "2026-09-03T00:54:32.628185Z",
     "iopub.status.idle": "2026-09-03T00:54:32.631344Z",
     "shell.execute_reply": "2026-09-03T00:54:32.630764Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Тест на границе ловит ошибку >= там, где нужно строгое >.\n"
     ]
    }
   ],
   "source": [
    "assert test_boundary_is_safe(is_wall_collision) is True\n",
    "assert test_boundary_is_safe(is_wall_collision_BROKEN) is False\n",
    "print(\"Тест на границе ловит ошибку >= там, где нужно строгое >.\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
