mirror of
https://github.com/JamesTheGiblet/BuddAI.git
synced 2026-01-08 21:58:40 +00:00
- Implemented comprehensive unit tests for the BuddAI Analytics module, covering fallback statistics calculations. - Created tests for the FallbackClient to ensure proper escalation to various AI models and handling of missing API keys. - Developed unit tests for the refactored validator system, validating various hardware and coding standards. - Established a base validator interface and implemented specific validators for ESP32, Arduino, motor control, memory safety, and more. - Enhanced the validator registry to auto-discover and manage validators effectively. - Included detailed validation logic for common issues in embedded systems programming, such as unused variables, safety timeouts, and coding style violations.
67 lines
No EOL
2.4 KiB
Python
67 lines
No EOL
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Unit tests for the refactored Validator system.
|
|
"""
|
|
import unittest
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Setup path
|
|
REPO_ROOT = Path(__file__).parent.parent
|
|
if str(REPO_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(REPO_ROOT))
|
|
|
|
from validators import (
|
|
ESP32Validator, MotorValidator, ServoValidator, MemoryValidator,
|
|
ForgeTheoryValidator, TimingValidator, ArduinoValidator, StyleValidator
|
|
)
|
|
|
|
class TestRefactoredValidators(unittest.TestCase):
|
|
def test_esp32_validator(self):
|
|
val = ESP32Validator()
|
|
code = "analogWrite(PIN, 100);"
|
|
issues = val.validate(code, "ESP32", "")
|
|
self.assertTrue(any("analogWrite" in i['message'] for i in issues))
|
|
|
|
def test_motor_validator(self):
|
|
val = MotorValidator()
|
|
# Test missing pins for L298N
|
|
issues = val.validate("void loop() {}", "ESP32", "I need L298N code")
|
|
self.assertTrue(any("Missing L298N" in i['message'] for i in issues))
|
|
|
|
def test_servo_validator(self):
|
|
val = ServoValidator()
|
|
issues = val.validate("void setup() {}", "ESP32", "weapon system")
|
|
self.assertTrue(any("State Machine" in i['message'] for i in issues))
|
|
|
|
def test_memory_validator(self):
|
|
val = MemoryValidator()
|
|
code = "void setup() { int x = 10; }"
|
|
issues = val.validate(code, "ESP32", "")
|
|
self.assertTrue(any("Unused variable 'x'" in i['message'] for i in issues))
|
|
|
|
def test_arduino_validator(self):
|
|
val = ArduinoValidator()
|
|
code = "#include <Wire.h>\nvoid setup() {}"
|
|
issues = val.validate(code, "ESP32", "")
|
|
self.assertTrue(any("Unnecessary #include <Wire.h>" in i['message'] for i in issues))
|
|
|
|
def test_style_validator(self):
|
|
val = StyleValidator()
|
|
code = "void MyFunction() {}"
|
|
issues = val.validate(code, "ESP32", "")
|
|
self.assertTrue(any("camelCase" in i['message'] for i in issues))
|
|
|
|
def test_timing_validator(self):
|
|
val = TimingValidator()
|
|
code = "void loop() { // motor logic\n delay(1000); }"
|
|
issues = val.validate(code, "ESP32", "motor control")
|
|
self.assertTrue(any("delay()" in i['message'] for i in issues))
|
|
|
|
def test_forge_theory_validator(self):
|
|
val = ForgeTheoryValidator()
|
|
issues = val.validate("code", "ESP32", "")
|
|
self.assertEqual(issues, [])
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main() |