|
| 1 | +# tests/test_ai.py |
| 2 | + |
| 3 | +import unittest |
| 4 | +from ai.predictive_model import PredictiveModel |
| 5 | +from ai.fraud_detection import FraudDetection |
| 6 | + |
| 7 | +class TestPredictiveModel(unittest.TestCase): |
| 8 | + def setUp(self): |
| 9 | + self.model = PredictiveModel(model_path='./models/predictive_model.pkl') |
| 10 | + |
| 11 | + def test_train_and_predict(self): |
| 12 | + # Mock input data |
| 13 | + data = { |
| 14 | + 'feature1': [1, 2, 3, 4], |
| 15 | + 'feature2': [4, 5, 6, 7], |
| 16 | + 'target': [0, 1, 0, 1] |
| 17 | + } |
| 18 | + self.model.train(data) |
| 19 | + prediction = self.model.predict_outcome({'feature1': 3, 'feature2': 6}) |
| 20 | + self.assertIn('predicted_value', prediction) |
| 21 | + |
| 22 | +class TestFraudDetection(unittest.TestCase): |
| 23 | + def setUp(self): |
| 24 | + self.fraud_detector = FraudDetection(model_path='./models/fraud_detection_model.pkl') |
| 25 | + |
| 26 | + def test_train_and_detect_fraud(self): |
| 27 | + # Mock input data |
| 28 | + data = { |
| 29 | + 'feature1': [1, 2, 3, 4], |
| 30 | + 'feature2': [4, 5, 6, 7], |
| 31 | + 'is_fraud': [0, 1, 0, 1] |
| 32 | + } |
| 33 | + self.fraud_detector.train(data) |
| 34 | + result = self.fraud_detector.detect_fraud({'feature1': 2, 'feature2': 5}) |
| 35 | + self.assertIn('is_fraud', result) |
| 36 | + |
| 37 | +if __name__ == '__main__': |
| 38 | + unittest.main() |
0 commit comments