File size: 1,260 Bytes
9596562
 
 
 
 
 
2a9d346
9596562
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pytest
import pandas as pd
import numpy as np
import os
import sys

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../backend')))
from preprocessing import preprocess_data, resolve_model_dir

def test_resolve_model_dir():
    md = resolve_model_dir()
    assert md.endswith("model")

def test_preprocess_data_training():
    df = pd.DataFrame({
        'Heart Rate (bpm)': [80, 90, np.nan],
        'SpO2 Level (%)': [98, 97, 95],
        'Systolic Blood Pressure (mmHg)': [120, 125, 130],
        'Diastolic Blood Pressure (mmHg)': [80, 85, 90],
        'Body Temperature (°C)': [37.0, 37.2, 37.5],
        'Predicted Disease': ['Normal', 'Asthma', 'Normal']
    })
    
    X, y = preprocess_data(df, is_training=True)
    
    assert not X.isnull().values.any()
    assert len(y) == 3
    assert 'Risk_Severity' in X.columns

def test_preprocess_data_inference():
    df = pd.DataFrame({
        'Heart Rate (bpm)': [100],
        'SpO2 Level (%)': [99],
        'Systolic Blood Pressure (mmHg)': [120],
        'Diastolic Blood Pressure (mmHg)': [80],
        'Body Temperature (°C)': [37.0],
    })
    
    X, y = preprocess_data(df, is_training=False)
    
    assert y is None
    assert 'Risk_Severity' in X.columns