-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_transformation.py
57 lines (43 loc) · 1.95 KB
/
test_transformation.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pandas as pd
import numpy as np
import pytest
from pandas.testing import assert_frame_equal
from pandas.testing import assert_series_equal
from scripts.transformation import is_greater_than_average
#@pytest.mark.skip(reason="comment out when we get here")
# EXERCISE 2
def test_is_greater_than_average():
input_series = pd.Series([1, 2, 3, 2.5, 4])
expected_series = pd.Series([0, 0, 1, 0, 1])
output_series = is_greater_than_average(series=input_series)
assert_series_equal(output_series, expected_series)
def test_is_greater_than_average_empty():
input_series = pd.Series([])
expected_series = pd.Series([])
output_series = is_greater_than_average(series=input_series)
assert_series_equal(output_series, expected_series)
@pytest.mark.skip(reason="it fails")
def test_is_greater_than_average_with_nan():
input_series = pd.Series([1,2,np.nan])
expected_series = pd.Series([0,1,np.nan]) # or exception
output_series = is_greater_than_average(series=input_series)
assert_series_equal(output_series, expected_series)
def test_is_greater_than_average_all_the_same():
input_series = pd.Series([10, 10, 10, 10])
expected_series = pd.Series([0, 0, 0, 0])
output_series = is_greater_than_average(series=input_series)
assert_series_equal(output_series, expected_series)
#test for type
def test_is_greater_than_average_returns_series():
input_series = pd.Series([1, 2, 3, 2.5, 4])
output_series = is_greater_than_average(series=input_series)
assert type(output_series) is pd.core.series.Series
def test_series_type():
input_series = pd.Series([1, 2, 3, 2.5, 4])
output_series = is_greater_than_average(series=input_series)
assert type(output_series) is pd.Series
def test_is_returning_series():
input_series = pd.Series([1, 2, 3, 2.5, 4])
output_series = is_greater_than_average(series=input_series)
type_as_string = type(output_series).__name__
assert type_as_string == "Series"