-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_data.py
More file actions
120 lines (99 loc) · 5.95 KB
/
test_data.py
File metadata and controls
120 lines (99 loc) · 5.95 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import unittest
# Test data extracted from app.py
labels = {0: 'apple', 1: 'banana', 2: 'beetroot', 3: 'bell pepper', 4: 'cabbage', 5: 'capsicum', 6: 'carrot', 7: 'cauliflower', 8: 'chilli pepper', 9: 'corn', 10: 'cucumber', 11: 'eggplant', 12: 'garlic', 13: 'ginger', 14: 'grapes', 15: 'jalepeno', 16: 'kiwi', 17: 'lemon', 18: 'lettuce',
19: 'mango', 20: 'onion', 21: 'orange', 22: 'paprika', 23: 'pear', 24: 'peas', 25: 'pineapple', 26: 'pomegranate', 27: 'potato', 28: 'raddish', 29: 'soy beans', 30: 'spinach', 31: 'sweetcorn', 32: 'sweetpotato', 33: 'tomato', 34: 'turnip', 35: 'watermelon'}
fruits = ['Apple','Banana','Grapes','Kiwi','Lemon','Mango','Orange','Pear','Pineapple','Pomegranate','Watermelon']
vegetables = ['Beetroot','Bell Pepper','Chilli Pepper','Jalepeno','Cabbage','Paprika','Capsicum','Carrot','Cauliflower','Corn','Cucumber','Eggplant','Ginger','Lettuce','Onion','Peas','Potato','Raddish','Soy Beans','Spinach','Sweetcorn','Sweetpotato','Tomato','Turnip']
calNum = {'Apple': 52, 'Banana': 89, 'Beetroot': 43, 'Bell pepper': 26, 'Cabbage': 24, 'Capsicum': 26, 'Carrot': 41, 'Cauliflower': 25, 'Chilli pepper': 40, 'Corn': 86, 'Cucumber': 12, 'Eggplant': 24, 'Garlic': 149, 'Ginger': 80, 'Grapes': 69, 'Jalepeno': 30, 'Kiwi': 61, 'Lemon': 29, 'Lettuce': 14,
'Mango': 65, 'Onion': 42, 'Orange': 47, 'Paprika': 289, 'Pear': 58, 'Peas': 81, 'Pineapple': 48, 'Pomegranate': 68, 'Potato': 104, 'Raddish': 16, 'Soy beans': 81, 'Spinach': 23, 'Sweetcorn': 86, 'Sweetpotato': 114, 'Tomato': 18, 'Turnip': 28, 'Watermelon': 30}
class TestFruitVegetableData(unittest.TestCase):
def test_labels_structure(self):
"""Test that labels dictionary has expected structure."""
self.assertIsInstance(labels, dict)
self.assertEqual(len(labels), 36)
self.assertIn(0, labels)
self.assertIn(35, labels)
self.assertEqual(labels[0], 'apple')
self.assertEqual(labels[1], 'banana')
def test_fruits_list(self):
"""Test that fruits list contains expected items."""
self.assertIsInstance(fruits, list)
self.assertIn('Apple', fruits)
self.assertIn('Banana', fruits)
self.assertIn('Watermelon', fruits)
def test_vegetables_list(self):
"""Test that vegetables list contains expected items."""
self.assertIsInstance(vegetables, list)
self.assertIn('Carrot', vegetables)
self.assertIn('Tomato', vegetables)
self.assertIn('Potato', vegetables)
def test_calorie_dictionary(self):
"""Test that calorie dictionary has expected structure."""
self.assertIsInstance(calNum, dict)
self.assertIn('Apple', calNum)
self.assertIn('Banana', calNum)
self.assertIn('Carrot', calNum)
self.assertEqual(calNum['Apple'], 52)
self.assertEqual(calNum['Banana'], 89)
def test_categorization_logic(self):
"""Test that items are correctly categorized as fruits or vegetables."""
# Test some fruits
for fruit in ['Apple', 'Banana', 'Grapes']:
self.assertIn(fruit, fruits, f"{fruit} should be in fruits list")
self.assertNotIn(fruit, vegetables, f"{fruit} should not be in vegetables list")
# Test some vegetables
for vegetable in ['Carrot', 'Tomato', 'Potato']:
self.assertIn(vegetable, vegetables, f"{vegetable} should be in vegetables list")
self.assertNotIn(vegetable, fruits, f"{vegetable} should not be in fruits list")
def test_calorie_values(self):
"""Test that calorie values are reasonable."""
for item, calories in calNum.items():
self.assertIsInstance(calories, int)
self.assertGreater(calories, 0, f"Calories for {item} should be positive")
self.assertLess(calories, 1000, f"Calories for {item} should be reasonable")
class TestDataConsistency(unittest.TestCase):
"""Test data consistency across different data structures."""
def test_labels_fruits_consistency(self):
"""Test that all fruits in the fruits list have corresponding labels."""
for fruit in fruits:
# Find the label index for this fruit
found = False
for idx, label in labels.items():
if label.lower() == fruit.lower():
found = True
break
self.assertTrue(found, f"Fruit '{fruit}' should have a corresponding label")
def test_labels_vegetables_consistency(self):
"""Test that all vegetables in the vegetables list have corresponding labels."""
for vegetable in vegetables:
# Find the label index for this vegetable
found = False
for idx, label in labels.items():
if label.lower() == vegetable.lower():
found = True
break
self.assertTrue(found, f"Vegetable '{vegetable}' should have a corresponding label")
def test_calorie_data_consistency(self):
"""Test that calorie data exists for all fruits and vegetables."""
all_items = fruits + vegetables
for item in all_items:
# Check for case-insensitive match
found = False
for cal_key in calNum.keys():
if item.lower() == cal_key.lower():
found = True
break
self.assertTrue(found, f"Calorie data should exist for '{item}' (case-insensitive)")
if __name__ == '__main__':
# Create a test suite
loader = unittest.TestLoader()
suite = unittest.TestSuite()
# Add test cases
suite.addTests(loader.loadTestsFromTestCase(TestFruitVegetableData))
suite.addTests(loader.loadTestsFromTestCase(TestDataConsistency))
# Run the tests
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
# Exit with appropriate code
import sys
sys.exit(0 if result.wasSuccessful() else 1)