Skip to content

Commit 17ea68a

Browse files
authored
Create test_utils.py
1 parent 1954ec7 commit 17ea68a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# tests/test_utils.py
2+
3+
import unittest
4+
import pandas as pd
5+
import numpy as np
6+
from utils.helpers import preprocess_data, validate_data, split_data
7+
8+
class TestUtils(unittest.TestCase):
9+
def test_preprocess_data(self):
10+
raw_data = {
11+
'feature1': [1, 2, np.nan],
12+
'feature2': [4, 5, 6],
13+
'target': [0, 1, 0]
14+
}
15+
processed_data = preprocess_data(pd.DataFrame(raw_data))
16+
self.assertFalse(processed_data['feature1'].isnull().any()) # Ensure no NaN values
17+
18+
def test_validate_data(self):
19+
valid_data = {
20+
'feature1': [1, 2, 3],
21+
'feature2': [4, 5, 6],
22+
'target': [0, 1, 0]
23+
}
24+
self.assertTrue(validate_data(pd.DataFrame(valid_data))) # Should return True for valid data
25+
26+
def test_split_data(self):
27+
data = {
28+
'feature1': [1, 2, 3, 4],
29+
'feature2': [5, 6, 7, 8],
30+
'target': [0, 1, 0, 1]
31+
}
32+
train_data, test_data = split_data(pd.DataFrame(data), test_size=0.25)
33+
self.assertEqual(len(train_data), 3) # 75% of 4 is 3
34+
self.assertEqual(len(test_data), 1) # 25% of 4 is 1
35+
36+
if __name__ == '__main__':
37+
unittest.main()

0 commit comments

Comments
 (0)