-
Notifications
You must be signed in to change notification settings - Fork 0
/
SalesDataTest.py
70 lines (60 loc) · 2.81 KB
/
SalesDataTest.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
58
59
60
61
62
63
64
65
66
67
68
69
70
import unittest
import pandas as pd
from SalesData import SalesData
class TestSalesData(unittest.TestCase):
def test_eliminate_duplicates(self):
data = {
'Product': ['A', 'A', 'B', 'C', 'B'],
'Date': ['2023-01-01', '2023-01-01', '2023-01-02', '2023-01-03', '2023-01-02'],
'Quantity': [10, 5, 15, 8, 20],
'Price': [100, 100, 120, 90, 120]
}
df = pd.DataFrame(data)
sales_data = SalesData(df)
sales_data.eliminate_duplicates()
expected_df = df.drop_duplicates().dropna()
self.assertTrue(sales_data.data.equals(expected_df))
def test_calculate_total_sales(self):
data = {
'Product': ['A', 'A', 'B', 'C'],
'Quantity': [10, 5, 15, 8],
'Price': [100, 100, 120, 90]
}
df = pd.DataFrame(data)
sales_data = SalesData(df)
sales_data.calculate_total_sales()
expected_df = df.assign(Total_Sales=df['Quantity'] * df['Price'])
self.assertTrue(sales_data.data.equals(expected_df))
with self.assertRaises(NotImplementedError):
sales_data.calculate_total_sales() # Simulate plotting error
def test_analyze_sales_data(self):
data = {
'Product': ['A', 'A', 'B', 'C'],
'Quantity': [10, 5, 15, 8],
'Price': [100, 100, 120, 90]
}
df = pd.DataFrame(data)
sales_data = SalesData(df)
analysis_results = sales_data.analyze_sales_data()
expected_best_selling_product = 'A' # Modify as needed based on your data
expected_month_with_highest_sales = 1 # Modify as needed based on your data
self.assertEqual(analysis_results['best_selling_product'], expected_best_selling_product)
self.assertEqual(analysis_results['month_with_highest_sales'], expected_month_with_highest_sales)
with self.assertRaises(NotImplementedError):
sales_data.analyze_sales_data() # Simulate analysis or plot error
def test_add_additional_values(self):
data = {
'Product': ['A', 'A', 'B', 'C'],
'Quantity': [10, 5, 15, 8],
'Price': [100, 100, 120, 90]
}
df = pd.DataFrame(data)
sales_data = SalesData(df)
analysis_results = sales_data.add_additional_values()
# Assert expected results
expected_minimest_selling_product = 'C' # Modify as needed based on your data
expected_average_sales = 95 # Modify as needed based on your data
self.assertEqual(analysis_results['minimest_selling_product'], expected_minimest_selling_product)
self.assertEqual(analysis_results['average_sales'], expected_average_sales)
with self.assertRaises(NotImplementedError):
sales_data.add_additional_values() # Simulate analysis or plot error