File size: 2,496 Bytes
b11d193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "daef9871-0fa5-4913-add2-bf82a6f3fa1a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: nbimporter in /opt/conda/lib/python3.11/site-packages (0.3.4)\n"
     ]
    }
   ],
   "source": [
    "!pip install nbimporter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e112e54c-6619-46b4-8681-c6315c05edf1",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      ".\n",
      "----------------------------------------------------------------------\n",
      "Ran 1 test in 0.351s\n",
      "\n",
      "OK\n"
     ]
    }
   ],
   "source": [
    "import unittest\n",
    "import numpy as np\n",
    "import nbimporter\n",
    "from main import preprocess_data\n",
    "\n",
    "class TestMainNotebook(unittest.TestCase):\n",
    "\n",
    "    def setUp(self):\n",
    "        \"\"\"Set up mock data for testing.\"\"\"\n",
    "        # Sample data resembling MNIST\n",
    "        self.train_images = np.random.rand(100, 28, 28)  # Shape: (100, 28, 28)\n",
    "        self.test_images = np.random.rand(20, 28, 28)  # Shape: (20, 28, 28)\n",
    "\n",
    "    def test_preprocess_data(self):\n",
    "        \"\"\"Test the data preprocessing function.\"\"\"\n",
    "        preprocessed_train, preprocessed_test = preprocess_data(self.train_images, self.test_images)\n",
    "\n",
    "        # Verify shapes after preprocessing\n",
    "        self.assertEqual(preprocessed_train.shape, (100, 28, 28, 1))\n",
    "        self.assertEqual(preprocessed_test.shape, (20, 28, 28, 1))\n",
    "\n",
    "        # Verify data normalization\n",
    "        self.assertTrue(np.all(preprocessed_train <= 1.0))\n",
    "        self.assertTrue(np.all(preprocessed_test <= 1.0))\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    unittest.main(argv=[''], exit=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel) *",
   "language": "python",
   "name": "conda-base-py"
  },
  "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.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}