testgenie-py 0.2.8__py3-none-any.whl → 0.2.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- testgen/controller/docker_controller.py +12 -11
- testgen/service/service.py +2 -2
- testgen/testgen.db +0 -0
- {testgenie_py-0.2.8.dist-info → testgenie_py-0.2.9.dist-info}/METADATA +1 -1
- {testgenie_py-0.2.8.dist-info → testgenie_py-0.2.9.dist-info}/RECORD +7 -47
- testgen/.coverage +0 -0
- testgen/code_to_test/__init__.py +0 -0
- testgen/code_to_test/boolean.py +0 -146
- testgen/code_to_test/calculator.py +0 -29
- testgen/code_to_test/code_to_fuzz.py +0 -234
- testgen/code_to_test/code_to_fuzz_lite.py +0 -397
- testgen/code_to_test/decisions.py +0 -57
- testgen/code_to_test/math_utils.py +0 -47
- testgen/code_to_test/sample_code_bin.py +0 -141
- testgen/tests/__init__.py +0 -0
- testgen/tests/test_boolean.py +0 -81
- testgen/tests/test_code_to_fuzz_lite.py +0 -251
- testgen/tests/test_generated_boolean.py +0 -83
- testgen/visualize/boolean_bin_and_coverage.png +0 -0
- testgen/visualize/boolean_bin_and_coverage_v1.png +0 -0
- testgen/visualize/boolean_bin_and_coverage_v2.png +0 -0
- testgen/visualize/boolean_bin_and_coverage_v3.png +0 -0
- testgen/visualize/boolean_bin_and_coverage_v4.png +0 -0
- testgen/visualize/boolean_bin_and_coverage_v5.png +0 -0
- testgen/visualize/boolean_bin_and_coverage_v6.png +0 -0
- testgen/visualize/boolean_bin_and_coverage_v7.png +0 -0
- testgen/visualize/boolean_bin_and_coverage_v8.png +0 -0
- testgen/visualize/boolean_bin_xor_coverage.png +0 -0
- testgen/visualize/boolean_bin_xor_coverage_v1.png +0 -0
- testgen/visualize/boolean_bin_xor_coverage_v2.png +0 -0
- testgen/visualize/boolean_bin_xor_coverage_v3.png +0 -0
- testgen/visualize/boolean_bin_xor_coverage_v4.png +0 -0
- testgen/visualize/boolean_bin_xor_coverage_v5.png +0 -0
- testgen/visualize/boolean_bin_xor_coverage_v6.png +0 -0
- testgen/visualize/boolean_bin_xor_coverage_v7.png +0 -0
- testgen/visualize/boolean_bin_xor_coverage_v8.png +0 -0
- testgen/visualize/boolean_status_flags_coverage.png +0 -0
- testgen/visualize/boolean_status_flags_coverage_v1.png +0 -0
- testgen/visualize/boolean_status_flags_coverage_v2.png +0 -0
- testgen/visualize/boolean_status_flags_coverage_v3.png +0 -0
- testgen/visualize/boolean_status_flags_coverage_v4.png +0 -0
- testgen/visualize/boolean_status_flags_coverage_v5.png +0 -0
- testgen/visualize/boolean_status_flags_coverage_v6.png +0 -0
- testgen/visualize/boolean_status_flags_coverage_v7.png +0 -0
- testgen/visualize/boolean_status_flags_coverage_v8.png +0 -0
- {testgenie_py-0.2.8.dist-info → testgenie_py-0.2.9.dist-info}/WHEEL +0 -0
- {testgenie_py-0.2.8.dist-info → testgenie_py-0.2.9.dist-info}/entry_points.txt +0 -0
@@ -1,4 +1,3 @@
|
|
1
|
-
import importlib
|
2
1
|
import os
|
3
2
|
import sys
|
4
3
|
from argparse import Namespace
|
@@ -6,7 +5,10 @@ import docker
|
|
6
5
|
from docker import DockerClient, client
|
7
6
|
from docker import errors
|
8
7
|
from docker.models.containers import Container
|
9
|
-
import importlib.resources
|
8
|
+
import importlib.resources as pkg_resources
|
9
|
+
import tempfile
|
10
|
+
import shutil
|
11
|
+
|
10
12
|
from testgen.service.logging_service import get_logger
|
11
13
|
from testgen.service.service import Service
|
12
14
|
|
@@ -134,7 +136,6 @@ class DockerController:
|
|
134
136
|
print(f"Docker args: {docker_args}")
|
135
137
|
print(f"Project root: {project_root}")
|
136
138
|
|
137
|
-
|
138
139
|
return docker_client.containers.run(
|
139
140
|
image=image_name,
|
140
141
|
command=["testgenie"] + docker_args,
|
@@ -192,23 +193,23 @@ class DockerController:
|
|
192
193
|
return False
|
193
194
|
|
194
195
|
def get_dockerfile_path(self) -> str:
|
195
|
-
|
196
|
+
# First, try local development path
|
196
197
|
local_dockerfile = os.path.join(os.path.dirname(__file__), "docker", "Dockerfile")
|
197
|
-
print(f"Checking local path: {local_dockerfile}")
|
198
198
|
if os.path.exists(local_dockerfile):
|
199
|
+
self.debug(f"Found local Dockerfile at: {local_dockerfile}")
|
199
200
|
return local_dockerfile
|
200
201
|
|
201
202
|
# If not found locally, try inside installed package
|
202
203
|
try:
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
return str(dockerfile_path)
|
204
|
+
dockerfile_resource = pkg_resources.files('testgen').joinpath('docker/Dockerfile')
|
205
|
+
if dockerfile_resource.is_file():
|
206
|
+
self.debug(f"Found package-installed Dockerfile at: {dockerfile_resource}")
|
207
|
+
return str(dockerfile_resource)
|
208
208
|
except Exception as e:
|
209
209
|
print(f"Error locating Dockerfile in package resources: {e}")
|
210
210
|
|
211
|
-
|
211
|
+
print("Dockerfile not found in local project or package.")
|
212
|
+
sys.exit(1)
|
212
213
|
|
213
214
|
@staticmethod
|
214
215
|
def is_inside_docker() -> bool:
|
testgen/service/service.py
CHANGED
@@ -457,8 +457,8 @@ class Service:
|
|
457
457
|
loader = unittest.TestLoader()
|
458
458
|
self.logger.debug(f"Discovering tests in: {os.path.dirname(file_path_to_use)} with pattern: {os.path.basename(test_file)}")
|
459
459
|
test_module = os.path.relpath(test_file,
|
460
|
-
start=os.getcwd())
|
461
|
-
test_module = test_module.replace("/", ".").replace("\\", ".").rstrip(".py")
|
460
|
+
start=os.getcwd()) # Get relative path from the current working directory
|
461
|
+
test_module = test_module.replace("/", ".").replace("\\", ".").rstrip(".py") # Convert to module name
|
462
462
|
if test_module.startswith("."):
|
463
463
|
test_module = test_module[1:] # Remove leading dot if present
|
464
464
|
self.logger.debug(f"Test module: {test_module}")
|
testgen/testgen.db
CHANGED
Binary file
|
@@ -1,4 +1,3 @@
|
|
1
|
-
testgen/.coverage,sha256=NYSARpg1eBFSMEuoMcK98U5uK0xbwwS3s2V5TPGI7fw,69632
|
2
1
|
testgen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
2
|
testgen/analyzer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
3
|
testgen/analyzer/ast_analyzer.py,sha256=fUtrJQsgnKeSKqKaXSO_ZsY_uQr2aPeyTQP9ToyFEg4,6886
|
@@ -11,17 +10,9 @@ testgen/analyzer/random_feedback_analyzer.py,sha256=hDcNIWE4BFtsoyXHWyxcC1qeq7y9
|
|
11
10
|
testgen/analyzer/reinforcement_analyzer.py,sha256=U6W7g-xDFS_P0aqxjPRnaXjGp2gOC9TMdfWaetFV7eE,3568
|
12
11
|
testgen/analyzer/test_case_analyzer.py,sha256=0qLcRKOrQ4Uyh1ZMecVTkY9bWjNnx7OridigNyjfUk4,1620
|
13
12
|
testgen/analyzer/test_case_analyzer_context.py,sha256=7umDPHBjoTaCRvZOdNynpnWsr14Gy0E2hpMBPK8mz3Q,2128
|
14
|
-
testgen/code_to_test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
|
-
testgen/code_to_test/boolean.py,sha256=RM2byJDKFTx1FFrxnPG_uZWb24OcOH20Uh-D1Z-yPcE,3373
|
16
|
-
testgen/code_to_test/calculator.py,sha256=j7lw21BYg_vxaQVCrjOlhQOpObjSe5gu9xzthmdGphk,830
|
17
|
-
testgen/code_to_test/code_to_fuzz.py,sha256=cwgRpUdXjTlrUHSHMtA2TAj8Y-ddAn6CaUdXPM4MRmo,4826
|
18
|
-
testgen/code_to_test/code_to_fuzz_lite.py,sha256=EjS4GB5klnJrvZIDDpS9iIt0iZETVJI0ez9DmihMiYc,10429
|
19
|
-
testgen/code_to_test/decisions.py,sha256=ZiW-EF1yTOWeQVZ7Xh0oIPHK2NSNPUzVxCY0E2GbYvQ,1376
|
20
|
-
testgen/code_to_test/math_utils.py,sha256=FqPQz5-e1oklzGyTVYNO8JMKDg5ob8z05VOlpKfKvvw,853
|
21
|
-
testgen/code_to_test/sample_code_bin.py,sha256=kMvV_-oFeAkxUmDx41Pw0iTTmMG1pvX31TezXPWMOkE,4225
|
22
13
|
testgen/controller/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
23
14
|
testgen/controller/cli_controller.py,sha256=A3TsJQT20UI2TlBqC7SyI8TG0n1vP_Itd1K8TRoD3ps,8735
|
24
|
-
testgen/controller/docker_controller.py,sha256=
|
15
|
+
testgen/controller/docker_controller.py,sha256=M6Q_tiAGX8j4lH1NLUFMTCreKXmoKTEpgo60z-KWVRg,8343
|
25
16
|
testgen/docker/Dockerfile,sha256=6mutzP0ZkVueuvMLCOy2bsyGxWjLHU-cq7RFkuC8r5Y,781
|
26
17
|
testgen/generated_boolean.py,sha256=i5at_BZ7YHtveTMYB0JKMFIkBe7cwhCeF5AViLhNoWA,1146
|
27
18
|
testgen/generated_samplecodebin.py,sha256=pf_aYtcfpjZzgiZ_FiBOxfug_ii3dRX0jnozBgQm7Xw,17030
|
@@ -52,15 +43,11 @@ testgen/service/analysis_service.py,sha256=uPoPJFLh4Imf5y_Zd8pX9zxRijr-D0K0WV22Y
|
|
52
43
|
testgen/service/cfg_service.py,sha256=Czr91D5AHVq38yPKyhZDjM5jMObGPvY0yPE-PxNVBYM,2326
|
53
44
|
testgen/service/generator_service.py,sha256=3JCWRlg5UKNhKRG9VXIycDFmuYKsRTzEmhmtlxroWAc,8088
|
54
45
|
testgen/service/logging_service.py,sha256=tCv9LHL1gUScQQp34_iYoUxfCFzLRtFG_DXRsJ73SjA,3189
|
55
|
-
testgen/service/service.py,sha256=
|
46
|
+
testgen/service/service.py,sha256=j_tbvale6rIHfBFtJKWT1CYzSRT5tN6muU2RxaQRRRA,20875
|
56
47
|
testgen/sqlite/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
57
48
|
testgen/sqlite/db.py,sha256=RUt88ndT4CQRo9aZzLGXPHRK1iw0LyDEGnoWlOLzKGM,2390
|
58
49
|
testgen/sqlite/db_service.py,sha256=F2ug_FBrYOQtJwM2cMkvQrTS54_VhWGDAHXndnTi-c8,9768
|
59
|
-
testgen/testgen.db,sha256=
|
60
|
-
testgen/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
61
|
-
testgen/tests/test_boolean.py,sha256=eS0raGCrPtVZbZqyU7InW3Pzy5HAgiGIYt6UmPUxkMk,1924
|
62
|
-
testgen/tests/test_code_to_fuzz_lite.py,sha256=B66_FNIULxkMIL48oSGx1fsxCo3tF4cp7VyhlrZAfZI,8574
|
63
|
-
testgen/tests/test_generated_boolean.py,sha256=QOmfu8sgWanrpY-OKY8u09l0q2Q7m4oJST6Llg64ka0,2493
|
50
|
+
testgen/testgen.db,sha256=EQVBRtHL8KcjzXni8Hrg2XwSyXWWt6GXY82NGHklfgE,45056
|
64
51
|
testgen/tree/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
65
52
|
testgen/tree/node.py,sha256=ONJtbACShN4yNj1X-UslFRgLyBP6mrbg7qZr3c6dWyA,165
|
66
53
|
testgen/tree/tree_utils.py,sha256=gT7jucky6_GWVOlDI6jpv6RMeWCkntGOHIYLvHxD85k,2122
|
@@ -76,34 +63,7 @@ testgen/util/z3_utils/branch_condition.py,sha256=N9FNR-iJmxIC62NpDQNVZ1OP14rXXqY
|
|
76
63
|
testgen/util/z3_utils/constraint_extractor.py,sha256=RXJLpmk6dAvHZ27839VXKXNtdy9St1F-17-pSEFu4bM,1285
|
77
64
|
testgen/util/z3_utils/variable_finder.py,sha256=dUh3F9_L_BDMz1ybiGss09LLcM_egbitgj0FT5Nh9u4,245
|
78
65
|
testgen/util/z3_utils/z3_test_case.py,sha256=yF4oJOrXMLzOwDUqXdoeg83MOTl3pvc_lYaZcS01CuQ,4983
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
testgen/visualize/boolean_bin_and_coverage_v4.png,sha256=W91WI9xvu8-uxUcS6wAekWtVMV8G_JEq-_rCqt8vSas,38291
|
84
|
-
testgen/visualize/boolean_bin_and_coverage_v5.png,sha256=W91WI9xvu8-uxUcS6wAekWtVMV8G_JEq-_rCqt8vSas,38291
|
85
|
-
testgen/visualize/boolean_bin_and_coverage_v6.png,sha256=W91WI9xvu8-uxUcS6wAekWtVMV8G_JEq-_rCqt8vSas,38291
|
86
|
-
testgen/visualize/boolean_bin_and_coverage_v7.png,sha256=W91WI9xvu8-uxUcS6wAekWtVMV8G_JEq-_rCqt8vSas,38291
|
87
|
-
testgen/visualize/boolean_bin_and_coverage_v8.png,sha256=W91WI9xvu8-uxUcS6wAekWtVMV8G_JEq-_rCqt8vSas,38291
|
88
|
-
testgen/visualize/boolean_bin_xor_coverage.png,sha256=nmzDr4Qc2Hd3pdxrgAVWdXe7fks9c4UAyvp2PsTYPgM,45945
|
89
|
-
testgen/visualize/boolean_bin_xor_coverage_v1.png,sha256=nmzDr4Qc2Hd3pdxrgAVWdXe7fks9c4UAyvp2PsTYPgM,45945
|
90
|
-
testgen/visualize/boolean_bin_xor_coverage_v2.png,sha256=nmzDr4Qc2Hd3pdxrgAVWdXe7fks9c4UAyvp2PsTYPgM,45945
|
91
|
-
testgen/visualize/boolean_bin_xor_coverage_v3.png,sha256=hJ6CRK1iBpbD5EQ0Zhv4iD3QIq6wHJeAFb4VpkPDWDI,44454
|
92
|
-
testgen/visualize/boolean_bin_xor_coverage_v4.png,sha256=hJ6CRK1iBpbD5EQ0Zhv4iD3QIq6wHJeAFb4VpkPDWDI,44454
|
93
|
-
testgen/visualize/boolean_bin_xor_coverage_v5.png,sha256=hJ6CRK1iBpbD5EQ0Zhv4iD3QIq6wHJeAFb4VpkPDWDI,44454
|
94
|
-
testgen/visualize/boolean_bin_xor_coverage_v6.png,sha256=hJ6CRK1iBpbD5EQ0Zhv4iD3QIq6wHJeAFb4VpkPDWDI,44454
|
95
|
-
testgen/visualize/boolean_bin_xor_coverage_v7.png,sha256=hJ6CRK1iBpbD5EQ0Zhv4iD3QIq6wHJeAFb4VpkPDWDI,44454
|
96
|
-
testgen/visualize/boolean_bin_xor_coverage_v8.png,sha256=hJ6CRK1iBpbD5EQ0Zhv4iD3QIq6wHJeAFb4VpkPDWDI,44454
|
97
|
-
testgen/visualize/boolean_status_flags_coverage.png,sha256=KmfPse_7gt71JdfkKFY7Pcja90yNmSEvh7LQK1I0sMg,69661
|
98
|
-
testgen/visualize/boolean_status_flags_coverage_v1.png,sha256=KmfPse_7gt71JdfkKFY7Pcja90yNmSEvh7LQK1I0sMg,69661
|
99
|
-
testgen/visualize/boolean_status_flags_coverage_v2.png,sha256=KmfPse_7gt71JdfkKFY7Pcja90yNmSEvh7LQK1I0sMg,69661
|
100
|
-
testgen/visualize/boolean_status_flags_coverage_v3.png,sha256=SCMgwC8Oes_0J7P2oJasx0psC_7pnjJTvpioZilmrUE,71519
|
101
|
-
testgen/visualize/boolean_status_flags_coverage_v4.png,sha256=sI5T39fTA0ou11myDZCw8kvJmRmWkMUxXwzmPdz_GJ0,71538
|
102
|
-
testgen/visualize/boolean_status_flags_coverage_v5.png,sha256=SCMgwC8Oes_0J7P2oJasx0psC_7pnjJTvpioZilmrUE,71519
|
103
|
-
testgen/visualize/boolean_status_flags_coverage_v6.png,sha256=KmfPse_7gt71JdfkKFY7Pcja90yNmSEvh7LQK1I0sMg,69661
|
104
|
-
testgen/visualize/boolean_status_flags_coverage_v7.png,sha256=KmfPse_7gt71JdfkKFY7Pcja90yNmSEvh7LQK1I0sMg,69661
|
105
|
-
testgen/visualize/boolean_status_flags_coverage_v8.png,sha256=KmfPse_7gt71JdfkKFY7Pcja90yNmSEvh7LQK1I0sMg,69661
|
106
|
-
testgenie_py-0.2.8.dist-info/METADATA,sha256=614Q86G6T2Ftu0SiXLT7tuunxj51g5ndtLjN0kz4f1Q,4350
|
107
|
-
testgenie_py-0.2.8.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
108
|
-
testgenie_py-0.2.8.dist-info/entry_points.txt,sha256=OUN4GqB4zHlHWwWGjwIPbur4E_ZqQgkeeqaCLhzRZgg,47
|
109
|
-
testgenie_py-0.2.8.dist-info/RECORD,,
|
66
|
+
testgenie_py-0.2.9.dist-info/METADATA,sha256=x8FM6FoDZMDEwwrMGBT3JN_FXGA2edB4sNl2SQkWjcs,4350
|
67
|
+
testgenie_py-0.2.9.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
68
|
+
testgenie_py-0.2.9.dist-info/entry_points.txt,sha256=OUN4GqB4zHlHWwWGjwIPbur4E_ZqQgkeeqaCLhzRZgg,47
|
69
|
+
testgenie_py-0.2.9.dist-info/RECORD,,
|
testgen/.coverage
DELETED
Binary file
|
testgen/code_to_test/__init__.py
DELETED
File without changes
|
testgen/code_to_test/boolean.py
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
from typing import List
|
2
|
-
|
3
|
-
|
4
|
-
def bin_and(a: bool, b: bool) ->bool:
|
5
|
-
"""
|
6
|
-
>>> bin_and(True, False)
|
7
|
-
False
|
8
|
-
|
9
|
-
>>> bin_and(False, True)
|
10
|
-
False
|
11
|
-
|
12
|
-
>>> bin_and(False, False)
|
13
|
-
False
|
14
|
-
|
15
|
-
>>> bin_and(True, True)
|
16
|
-
True
|
17
|
-
"""
|
18
|
-
if a == True:
|
19
|
-
if b == True:
|
20
|
-
return True
|
21
|
-
else:
|
22
|
-
return False
|
23
|
-
else:
|
24
|
-
return False
|
25
|
-
|
26
|
-
|
27
|
-
def bin_xor(a: bool, b: bool) ->bool:
|
28
|
-
"""
|
29
|
-
>>> bin_xor(True, True)
|
30
|
-
False
|
31
|
-
|
32
|
-
>>> bin_xor(True, False)
|
33
|
-
True
|
34
|
-
|
35
|
-
>>> bin_xor(False, False)
|
36
|
-
False
|
37
|
-
|
38
|
-
>>> bin_xor(False, True)
|
39
|
-
True
|
40
|
-
"""
|
41
|
-
if a == True:
|
42
|
-
if b == True:
|
43
|
-
return False
|
44
|
-
else:
|
45
|
-
return True
|
46
|
-
elif b == True:
|
47
|
-
return True
|
48
|
-
else:
|
49
|
-
return False
|
50
|
-
|
51
|
-
|
52
|
-
def status_flags(active: bool, verified: bool, admin: bool) ->str:
|
53
|
-
"""
|
54
|
-
>>> status_flags(False, False, False)
|
55
|
-
'inactive'
|
56
|
-
|
57
|
-
>>> status_flags(False, False, True)
|
58
|
-
'admin-unverified'
|
59
|
-
|
60
|
-
>>> status_flags(True, True, False)
|
61
|
-
'user-verified'
|
62
|
-
|
63
|
-
>>> status_flags(True, True, True)
|
64
|
-
'admin-verified'
|
65
|
-
|
66
|
-
>>> status_flags(True, False, False)
|
67
|
-
'user-unverified'
|
68
|
-
|
69
|
-
>>> status_flags(False, True, True)
|
70
|
-
'admin-verified'
|
71
|
-
|
72
|
-
>>> status_flags(False, True, False)
|
73
|
-
'inactive'
|
74
|
-
|
75
|
-
>>> status_flags(True, False, True)
|
76
|
-
'admin-unverified'
|
77
|
-
"""
|
78
|
-
if admin:
|
79
|
-
if verified:
|
80
|
-
return 'admin-verified'
|
81
|
-
else:
|
82
|
-
return 'admin-unverified'
|
83
|
-
elif active:
|
84
|
-
if verified:
|
85
|
-
return 'user-verified'
|
86
|
-
else:
|
87
|
-
return 'user-unverified'
|
88
|
-
else:
|
89
|
-
return 'inactive'
|
90
|
-
|
91
|
-
|
92
|
-
"""def half_adder(a: bool, b: bool) ->tuple:
|
93
|
-
sum: bool = bin_xor(a, b)
|
94
|
-
carry: bool = bin_and(a, b)
|
95
|
-
return sum, carry
|
96
|
-
|
97
|
-
|
98
|
-
def full_adder(a: bool, b: bool, carry_in: bool) ->tuple:
|
99
|
-
sum1, carry = half_adder(a, b)
|
100
|
-
sum2, carry_out = half_adder(sum1, carry_in)
|
101
|
-
return sum2, carry or carry_out
|
102
|
-
|
103
|
-
|
104
|
-
def thirty_two_bit_adder_excep(x: int, y: int) ->List[int]:
|
105
|
-
x_bits: List[int] = bit_converter(x)
|
106
|
-
y_bits: List[int] = bit_converter(y)
|
107
|
-
result: List[int] = [0] * 32
|
108
|
-
carry: bool = False
|
109
|
-
for i in range(32):
|
110
|
-
try:
|
111
|
-
sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
|
112
|
-
result[i] = sum_bit
|
113
|
-
except IndexError as e:
|
114
|
-
print(f'Index Out of Bounds Error In ThirtyTwoBitAdder: {e}')
|
115
|
-
result = [1] * 32
|
116
|
-
if carry:
|
117
|
-
return OverflowError('Sum exceeds 32 bits')
|
118
|
-
return result
|
119
|
-
|
120
|
-
|
121
|
-
def thirty_two_bit_adder(x: int, y: int) ->List[int]:
|
122
|
-
print(x.bit_length() - 1)
|
123
|
-
print(y.bit_length() - 1)
|
124
|
-
x_bits: List[int] = bit_converter(x)
|
125
|
-
y_bits: List[int] = bit_converter(y)
|
126
|
-
result: List[int] = [0] * 32
|
127
|
-
carry: bool = False
|
128
|
-
for i in range(32):
|
129
|
-
sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
|
130
|
-
result[i] = sum_bit
|
131
|
-
return result
|
132
|
-
|
133
|
-
def bit_converter(num: int) ->List[int]:
|
134
|
-
binary_str: str = bin(num)[2:]
|
135
|
-
print(bin(num)[2:])
|
136
|
-
return [int(digit) for digit in binary_str]
|
137
|
-
|
138
|
-
def thirty_two_bit_adder_excep(x: int, y: int) ->List[int]:
|
139
|
-
x_bits: List[int] = bit_converter(x)
|
140
|
-
y_bits: List[int] = bit_converter(y)
|
141
|
-
result: List[int] = [0] * 32
|
142
|
-
carry: bool = False
|
143
|
-
for i in range(32):
|
144
|
-
sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
|
145
|
-
result[i] = sum_bit
|
146
|
-
return result"""
|
@@ -1,29 +0,0 @@
|
|
1
|
-
class AdvancedCalculator:
|
2
|
-
|
3
|
-
def evaluate(self, a: int, b: int, op: str) ->(int | float | str):
|
4
|
-
""">>> AdvancedCalculator().evaluate(16, 56, 'abc')
|
5
|
-
'invalid'"""
|
6
|
-
if op == 'add':
|
7
|
-
return a + b
|
8
|
-
elif op == 'sub':
|
9
|
-
return a - b
|
10
|
-
elif op == 'mul':
|
11
|
-
return a * b
|
12
|
-
elif op == 'div':
|
13
|
-
if b == 0:
|
14
|
-
return 'undefined'
|
15
|
-
return a / b
|
16
|
-
else:
|
17
|
-
return 'invalid'
|
18
|
-
|
19
|
-
def is_in_range(self, val: float) ->str:
|
20
|
-
""">>> AdvancedCalculator().is_in_range(0.4023417704905361)
|
21
|
-
'fractional'"""
|
22
|
-
if val < 0.0:
|
23
|
-
return 'below zero'
|
24
|
-
elif 0.0 <= val < 1.0:
|
25
|
-
return 'fractional'
|
26
|
-
elif 1.0 <= val <= 100.0:
|
27
|
-
return 'valid'
|
28
|
-
else:
|
29
|
-
return 'out of range'
|
@@ -1,234 +0,0 @@
|
|
1
|
-
from typing import List
|
2
|
-
|
3
|
-
|
4
|
-
def bin_and(a: bool, b: bool) ->bool:
|
5
|
-
""""
|
6
|
-
>>> bin_and(True, True)
|
7
|
-
True
|
8
|
-
>>> bin_and(True, False)
|
9
|
-
False
|
10
|
-
>>> bin_and(False, True)
|
11
|
-
False
|
12
|
-
>>> bin_and(False, False)
|
13
|
-
False
|
14
|
-
|
15
|
-
Examples:
|
16
|
-
>>> bin_and(True, False)
|
17
|
-
False"""
|
18
|
-
if a == True:
|
19
|
-
if b == True:
|
20
|
-
return True
|
21
|
-
else:
|
22
|
-
return False
|
23
|
-
else:
|
24
|
-
return False
|
25
|
-
|
26
|
-
|
27
|
-
def bin_or(a: bool, b: bool) ->bool:
|
28
|
-
""""
|
29
|
-
>>> bin_or(True, True)
|
30
|
-
True
|
31
|
-
>>> bin_or(True, False)
|
32
|
-
True
|
33
|
-
>>> bin_or(False, True)
|
34
|
-
True
|
35
|
-
>>> bin_or(False, False)
|
36
|
-
False
|
37
|
-
|
38
|
-
Examples:
|
39
|
-
>>> bin_or(False, True)
|
40
|
-
True"""
|
41
|
-
return a | b
|
42
|
-
|
43
|
-
|
44
|
-
def bin_xor(a: bool, b: bool) ->bool:
|
45
|
-
""">>> bin_xor(True, True)
|
46
|
-
False
|
47
|
-
>>> bin_xor(True, False)
|
48
|
-
True
|
49
|
-
>>> bin_xor(False, True)
|
50
|
-
True
|
51
|
-
>>> bin_xor(False, False)
|
52
|
-
False
|
53
|
-
|
54
|
-
Examples:
|
55
|
-
>>> bin_xor(True, True)
|
56
|
-
False"""
|
57
|
-
return a ^ b
|
58
|
-
|
59
|
-
|
60
|
-
def bin_nand(a: bool, b: bool) ->bool:
|
61
|
-
""">>> bin_nand(True, True)
|
62
|
-
False
|
63
|
-
>>> bin_nand(True, False)
|
64
|
-
True
|
65
|
-
>>> bin_nand(False, True)
|
66
|
-
True
|
67
|
-
>>> bin_nand(False, False)
|
68
|
-
True
|
69
|
-
|
70
|
-
Examples:
|
71
|
-
>>> bin_nand(True, False)
|
72
|
-
True"""
|
73
|
-
return not (a and b)
|
74
|
-
|
75
|
-
|
76
|
-
def bin_nor(a: bool, b: bool) ->bool:
|
77
|
-
""">>> bin_nor(True, True)
|
78
|
-
False
|
79
|
-
>>> bin_nor(True, False)
|
80
|
-
False
|
81
|
-
>>> bin_nor(False, True)
|
82
|
-
False
|
83
|
-
>>> bin_nor(False, False)
|
84
|
-
True
|
85
|
-
|
86
|
-
Examples:
|
87
|
-
>>> bin_nor(False, True)
|
88
|
-
False"""
|
89
|
-
return not a | b
|
90
|
-
|
91
|
-
|
92
|
-
def mux(c1: bool, c2: bool, x0: bool, x1: bool, x2: bool, x3: bool) ->bool:
|
93
|
-
""""
|
94
|
-
>>> mux(1, 1, True, False, False, False)
|
95
|
-
True
|
96
|
-
>>> mux(1, 0, False, True, False, False)
|
97
|
-
True
|
98
|
-
>>> mux(0, 1, False, False, True, False)
|
99
|
-
True
|
100
|
-
>>> mux(0, 0, False, False, False, True)
|
101
|
-
True
|
102
|
-
>>> mux(0, 0, False, False, False, False)
|
103
|
-
False
|
104
|
-
|
105
|
-
Examples:
|
106
|
-
>>> mux(False, False, False, False, False, True)
|
107
|
-
True"""
|
108
|
-
return (c1 and c2 and x0) | (c1 and not c2 and x1) | (not c1 and c2 and x2
|
109
|
-
) | (not c1 and not c2 and x3)
|
110
|
-
|
111
|
-
|
112
|
-
def bin_and_bad(a: bool, b: bool) ->bool:
|
113
|
-
""""
|
114
|
-
>>> bin_and(True, True)
|
115
|
-
True
|
116
|
-
>>> bin_and(True, False)
|
117
|
-
False
|
118
|
-
>>> bin_and(False, True)
|
119
|
-
False
|
120
|
-
>>> bin_and(False, False)
|
121
|
-
False
|
122
|
-
|
123
|
-
Examples:
|
124
|
-
>>> bin_and_bad(False, True)
|
125
|
-
True"""
|
126
|
-
if a == True and b == True:
|
127
|
-
return a and b
|
128
|
-
return a or b
|
129
|
-
|
130
|
-
|
131
|
-
def bin_or_bad(a: bool, b: bool) ->bool:
|
132
|
-
""""
|
133
|
-
>>> bin_or(True, True)
|
134
|
-
True
|
135
|
-
>>> bin_or(True, False)
|
136
|
-
True
|
137
|
-
>>> bin_or(False, True)
|
138
|
-
True
|
139
|
-
>>> bin_or(False, False)
|
140
|
-
False
|
141
|
-
|
142
|
-
Examples:
|
143
|
-
>>> bin_or_bad(True, True)
|
144
|
-
False"""
|
145
|
-
return not a | b
|
146
|
-
|
147
|
-
|
148
|
-
def bit_converter_excep(num: int) ->List[int]:
|
149
|
-
""">>> bit_converter_excep(30)
|
150
|
-
[1, 1, 1, 1, 0]"""
|
151
|
-
bs = bin(num)
|
152
|
-
binary_str = bs[2:]
|
153
|
-
try:
|
154
|
-
return [int(digit) for digit in binary_str]
|
155
|
-
except Exception as e:
|
156
|
-
print(binary_str)
|
157
|
-
print(bs)
|
158
|
-
print(f'Invalid Literal Exception in Bit Converter: {e}')
|
159
|
-
return
|
160
|
-
|
161
|
-
|
162
|
-
def bit_converter(num: int) ->List[int]:
|
163
|
-
"""
|
164
|
-
>>> bit_converter(25)
|
165
|
-
[1, 1, 0, 0, 1]
|
166
|
-
"""
|
167
|
-
binary_str: str = bin(num)[2:]
|
168
|
-
print(bin(num)[2:])
|
169
|
-
return [int(digit) for digit in binary_str]
|
170
|
-
|
171
|
-
|
172
|
-
def half_adder(a: bool, b: bool) ->tuple:
|
173
|
-
""">>> half_adder(True, True)
|
174
|
-
(False, True)"""
|
175
|
-
sum: bool = bin_xor(a, b)
|
176
|
-
carry: bool = bin_and(a, b)
|
177
|
-
return sum, carry
|
178
|
-
|
179
|
-
|
180
|
-
def full_adder(a: bool, b: bool, carry_in: bool) ->tuple:
|
181
|
-
""">>> full_adder(True, False, False)
|
182
|
-
(True, False)"""
|
183
|
-
sum1, carry = half_adder(a, b)
|
184
|
-
sum2, carry_out = half_adder(sum1, carry_in)
|
185
|
-
return sum2, carry or carry_out
|
186
|
-
|
187
|
-
|
188
|
-
def thirty_two_bit_adder_excep(x: int, y: int) ->List[int]:
|
189
|
-
""">>> thirty_two_bit_adder_excep(9, 3)
|
190
|
-
None
|
191
|
-
|
192
|
-
Examples:
|
193
|
-
>>> thirty_two_bit_adder_excep(34, 1)
|
194
|
-
None"""
|
195
|
-
x_bits: List[int] = bit_converter(x)
|
196
|
-
y_bits: List[int] = bit_converter(y)
|
197
|
-
result: List[int] = [0] * 32
|
198
|
-
carry: bool = False
|
199
|
-
for i in range(32):
|
200
|
-
try:
|
201
|
-
sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
|
202
|
-
result[i] = sum_bit
|
203
|
-
except IndexError as e:
|
204
|
-
print(f'Index Out of Bounds Error In ThirtyTwoBitAdder: {e}')
|
205
|
-
result = [1] * 32
|
206
|
-
if carry:
|
207
|
-
return OverflowError('Sum exceeds 32 bits')
|
208
|
-
return result
|
209
|
-
|
210
|
-
|
211
|
-
def thirty_two_bit_adder(x: int, y: int) ->List[int]:
|
212
|
-
""">>> thirty_two_bit_adder(8, 45)
|
213
|
-
None"""
|
214
|
-
print(x.bit_length() - 1)
|
215
|
-
print(y.bit_length() - 1)
|
216
|
-
x_bits: List[int] = bit_converter(x)
|
217
|
-
y_bits: List[int] = bit_converter(y)
|
218
|
-
result: List[int] = [0] * 32
|
219
|
-
carry: bool = False
|
220
|
-
for i in range(32):
|
221
|
-
sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
|
222
|
-
result[i] = sum_bit
|
223
|
-
return result
|
224
|
-
|
225
|
-
|
226
|
-
def thirty_two_bit_adder_excep(x: int, y: int) ->List[int]:
|
227
|
-
x_bits: List[int] = bit_converter(x)
|
228
|
-
y_bits: List[int] = bit_converter(y)
|
229
|
-
result: List[int] = [0] * 32
|
230
|
-
carry: bool = False
|
231
|
-
for i in range(32):
|
232
|
-
sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
|
233
|
-
result[i] = sum_bit
|
234
|
-
return result
|