mirror of
https://github.com/MLSysBook/TinyTorch.git
synced 2026-05-01 02:17:33 -05:00
✅ Fix 01_setup: Add test code between testing section and summary
Module 01_setup now follows correct pattern: 1. ## 🧪 Module Testing (explanation) 2. Standardized testing cell with run_module_tests_auto 3. Actual test functions (test_unit_personal_info_basic, test_unit_system_info_basic) 4. ## 🎯 Module Summary This ensures students see actual test implementations before the summary.
This commit is contained in:
@@ -554,6 +554,75 @@ if __name__ == "__main__":
|
||||
# Automatically discover and run all tests in this module
|
||||
success = run_module_tests_auto("Setup")
|
||||
|
||||
# %%
|
||||
def test_unit_personal_info_basic():
|
||||
"""Test personal_info function implementation."""
|
||||
print("🔬 Unit Test: Personal Information...")
|
||||
|
||||
# Test personal_info function
|
||||
personal = personal_info()
|
||||
|
||||
# Test return type
|
||||
assert isinstance(personal, dict), "personal_info should return a dictionary"
|
||||
|
||||
# Test required keys
|
||||
required_keys = ['developer', 'email', 'institution', 'system_name', 'version']
|
||||
for key in required_keys:
|
||||
assert key in personal, f"Dictionary should have '{key}' key"
|
||||
|
||||
# Test non-empty values
|
||||
for key, value in personal.items():
|
||||
assert isinstance(value, str), f"Value for '{key}' should be a string"
|
||||
assert len(value) > 0, f"Value for '{key}' cannot be empty"
|
||||
|
||||
# Test email format
|
||||
assert '@' in personal['email'], "Email should contain @ symbol"
|
||||
assert '.' in personal['email'], "Email should contain domain"
|
||||
|
||||
# Test version format
|
||||
assert personal['version'] == '1.0.0', "Version should be '1.0.0'"
|
||||
|
||||
# Test system name (should be unique/personalized)
|
||||
assert len(personal['system_name']) > 5, "System name should be descriptive"
|
||||
|
||||
print("✅ Personal info function tests passed!")
|
||||
print(f"✅ TinyTorch configured for: {personal['developer']}")
|
||||
|
||||
# %%
|
||||
def test_unit_system_info_basic():
|
||||
"""Test system_info function implementation."""
|
||||
print("🔬 Unit Test: System Information...")
|
||||
|
||||
# Test system_info function
|
||||
sys_info = system_info()
|
||||
|
||||
# Test return type
|
||||
assert isinstance(sys_info, dict), "system_info should return a dictionary"
|
||||
|
||||
# Test required keys
|
||||
required_keys = ['python_version', 'platform', 'architecture', 'cpu_count', 'memory_gb']
|
||||
for key in required_keys:
|
||||
assert key in sys_info, f"Dictionary should have '{key}' key"
|
||||
|
||||
# Test data types
|
||||
assert isinstance(sys_info['python_version'], str), "python_version should be string"
|
||||
assert isinstance(sys_info['platform'], str), "platform should be string"
|
||||
assert isinstance(sys_info['architecture'], str), "architecture should be string"
|
||||
assert isinstance(sys_info['cpu_count'], int), "cpu_count should be integer"
|
||||
assert isinstance(sys_info['memory_gb'], (int, float)), "memory_gb should be number"
|
||||
|
||||
# Test reasonable values
|
||||
assert sys_info['cpu_count'] > 0, "CPU count should be positive"
|
||||
assert sys_info['memory_gb'] > 0, "Memory should be positive"
|
||||
assert len(sys_info['python_version']) > 0, "Python version should not be empty"
|
||||
|
||||
# Test that values are actually queried (not hardcoded)
|
||||
actual_version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
|
||||
assert sys_info['python_version'] == actual_version, "Python version should match actual system"
|
||||
|
||||
print("✅ System info function tests passed!")
|
||||
print(f"✅ Python: {sys_info['python_version']} on {sys_info['platform']}")
|
||||
|
||||
# %% [markdown]
|
||||
"""
|
||||
## 🎯 Professional ML Engineering Skills
|
||||
|
||||
Reference in New Issue
Block a user