|
10 | 10 | "import pytest\n",
|
11 | 11 | "from unittest.mock import patch\n",
|
12 | 12 | "\n",
|
| 13 | + "# Mocking an example of input function for testing purposes\n", |
| 14 | + "def test_number_literals():\n", |
| 15 | + " a = 0b1010\n", |
| 16 | + " b = 100\n", |
| 17 | + " c = 0o310\n", |
| 18 | + " d = 0x12c\n", |
| 19 | + " float_1 = 10.5\n", |
| 20 | + " float_2 = 1.5e2\n", |
| 21 | + " float_3 = 1.5e-3\n", |
| 22 | + " x = 3.14j\n", |
| 23 | + "\n", |
| 24 | + " assert a == 10\n", |
| 25 | + " assert b == 100\n", |
| 26 | + " assert c == 200\n", |
| 27 | + " assert d == 300\n", |
| 28 | + " assert float_1 == 10.5\n", |
| 29 | + " assert float_2 == pytest.approx(150.0, rel=1e-9)\n", |
| 30 | + " assert float_3 == pytest.approx(0.0015, rel=1e-9)\n", |
| 31 | + " assert x == 3.14j\n", |
| 32 | + " assert x.imag == 3.14\n", |
| 33 | + " assert x.real == 0.0\n", |
| 34 | + "\n", |
| 35 | + "\n", |
| 36 | + "def test_string_literals():\n", |
| 37 | + " string_1 = 'Hello, world!'\n", |
| 38 | + " string_2 = \"Python programming\"\n", |
| 39 | + " string_3 = '''This is a\n", |
| 40 | + "multi-line string.''' # Adjusted indentation for consistency\n", |
| 41 | + " string_4 = \"\"\"This is another\n", |
| 42 | + "multi-line string.\"\"\" # Adjusted indentation for consistency\n", |
| 43 | + " string_5 = \"This is a newline:\\nAnd this is a tab:\\tHello\"\n", |
| 44 | + " string_6 = r\"C:\\Users\\Name\\Folder\"\n", |
| 45 | + " name = \"Alice\"\n", |
| 46 | + " string_7 = f\"Hello, {name}!\"\n", |
| 47 | + " string_8 = u\"\\U0001F604\"\n", |
| 48 | + " string_9 = b\"Hello, bytes!\"\n", |
| 49 | + "\n", |
| 50 | + " assert string_1 == 'Hello, world!'\n", |
| 51 | + " assert string_2 == \"Python programming\"\n", |
| 52 | + " assert string_3.strip() == '''This is a\n", |
| 53 | + "multi-line string.''' # Ensure no leading/trailing whitespace mismatch\n", |
| 54 | + " assert string_4.strip() == \"\"\"This is another\n", |
| 55 | + "multi-line string.\"\"\" # Ensure no leading/trailing whitespace mismatch\n", |
| 56 | + " assert string_5 == \"This is a newline:\\nAnd this is a tab:\\tHello\"\n", |
| 57 | + " assert string_6 == r\"C:\\Users\\Name\\Folder\"\n", |
| 58 | + " assert string_7 == \"Hello, Alice!\"\n", |
| 59 | + " assert string_8 == '😄'\n", |
| 60 | + " assert string_9 == b\"Hello, bytes!\"\n", |
| 61 | + "\n", |
| 62 | + " expected_bytes = [72, 101, 108, 108, 111, 44, 32, 98, 121, 116, 101, 115, 33]\n", |
| 63 | + " byte_values = [byte for byte in string_9]\n", |
| 64 | + " assert byte_values == expected_bytes\n", |
| 65 | + "\n", |
| 66 | + "\n", |
| 67 | + "def test_boolean_literals():\n", |
| 68 | + " a = True + 4\n", |
| 69 | + " b = False + 10\n", |
| 70 | + "\n", |
| 71 | + " assert a == 5\n", |
| 72 | + " assert b == 10\n", |
| 73 | + "\n", |
| 74 | + "\n", |
| 75 | + "def test_special_literal():\n", |
| 76 | + " a = None\n", |
| 77 | + " assert a is None\n", |
| 78 | + "\n", |
| 79 | + "\n", |
13 | 80 | "# Mocking user input to test the input function\n",
|
14 | 81 | "@patch('builtins.input', return_value='5') # Mocking input to return '5' when called\n",
|
15 | 82 | "def test_input_function(mock_input):\n",
|
|
0 commit comments