File size: 11,000 Bytes
b7a5bab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
import csv
import math
from pathlib import Path


DATA_DIR = Path(__file__).resolve().parents[1] / "data"
PLAN_PATH = Path(__file__).resolve().parents[2] / "plan2.md"
EXPECTED_PRODUCTS = [
    "Rice",
    "Wheat Flour",
    "Other Flours",
    "Dals",
    "Pulses",
    "Salt",
    "Sugar",
    "Jaggery",
    "Cooking Oil",
    "Ghee",
    "Spices",
    "Masalas",
    "Dry Fruits",
    "Nuts",
    "Seeds",
    "Poha",
    "Suji / Rava",
    "Besan",
    "Maida",
    "Breakfast Cereals",
    "Oats",
    "Pasta",
    "Noodles",
    "Vermicelli",
    "Ready-to-Cook Mixes",
    "Ready-to-Eat Foods",
    "Biscuits",
    "Cookies",
    "Rusk",
    "Snacks",
    "Namkeen",
    "Chips",
    "Sweets",
    "Chocolates",
    "Candies",
    "Bakery Products",
    "Bread",
    "Cakes",
    "Jams & Spreads",
    "Peanut Butter",
    "Honey",
    "Pickles",
    "Sauces",
    "Ketchup",
    "Chutneys",
    "Vinegar",
    "Tea",
    "Coffee",
    "Health Drinks",
    "Soft Drinks",
    "Packaged Juices",
    "Energy Drinks",
    "Bottled Water",
    "Dairy Products",
    "Milk",
    "Curd",
    "Butter",
    "Paneer",
    "Cheese",
    "Eggs",
    "Frozen Foods",
    "Frozen Snacks",
    "Frozen Vegetables",
    "Fruits",
    "Vegetables",
    "Leafy Vegetables",
    "Exotic Fruits",
    "Exotic Vegetables",
    "Cut Fruits & Vegetables",
    "Sprouts",
    "Detergents",
    "Fabric Care",
    "Dishwash Products",
    "Floor Cleaners",
    "Toilet Cleaners",
    "Bathroom Cleaners",
    "Disinfectants",
    "Utensil Cleaners",
    "Garbage Bags",
    "Tissues & Napkins",
    "Air Fresheners",
    "Bath Soap",
    "Handwash",
    "Shampoo",
    "Hair Oil",
    "Toothpaste",
    "Toothbrushes",
    "Oral Care Products",
    "Skincare Products",
    "Personal Hygiene Products",
    "Sanitary Products",
    "Baby Care Products",
    "Diapers & Wipes",
    "Stationery",
    "Notebooks",
    "Pens & Pencils",
    "Kitchen Tools",
    "Storage Containers",
    "Kitchen Appliances",
    "Household Utility Items",
]


def read_csv(name: str) -> list[dict[str, str]]:
    with (DATA_DIR / name).open(newline="", encoding="utf-8") as handle:
        return list(csv.DictReader(handle))


def header(name: str) -> list[str]:
    with (DATA_DIR / name).open(newline="", encoding="utf-8") as handle:
        return next(csv.reader(handle))


def test_required_files_exist() -> None:
    expected_files = {
        "store_state.csv",
        "stock.csv",
        "pending_orders.csv",
        "seller_profiles.csv",
        "market_offers.csv",
        "marketing_actions.csv",
    }
    assert expected_files == {path.name for path in DATA_DIR.glob("*.csv")}


def test_headers_match_contract() -> None:
    assert header("store_state.csv") == [
        "day",
        "current_daily_expense_inr",
        "bank_balance_inr",
        "customer_satisfaction",
        "order_processing_capacity",
        "cumulative_profit_inr",
    ]
    assert header("stock.csv") == [
        "product_name",
        "unit",
        "buying_price_inr",
        "selling_price_inr",
        "demand_score",
        "quantity_on_hand",
        "stock_value_inr",
    ]
    assert header("pending_orders.csv") == [
        "order_id",
        "product_name",
        "quantity",
        "seller_name",
        "buy_price_inr",
        "days_remaining",
        "status",
        "created_day",
    ]
    assert header("seller_profiles.csv") == [
        "seller_name",
        "timeline_behavior",
        "reliability_note",
        "default_etd_days",
    ]
    assert header("market_offers.csv") == [
        "product_name",
        "category",
        "unit",
        "demand_score",
        "seller_a_price_inr",
        "seller_a_etd_days",
        "seller_b_price_inr",
        "seller_b_etd_days",
        "seller_c_price_inr",
        "seller_c_etd_days",
        "seller_d_price_inr",
        "seller_d_etd_days",
    ]
    assert header("marketing_actions.csv") == [
        "action_id",
        "description",
        "customer_satisfaction_delta",
        "cost_inr",
        "recurring_cost_inr",
        "order_processing_capacity_delta",
    ]


def test_stock_has_30_rows_and_consistent_values() -> None:
    stock_rows = read_csv("stock.csv")
    assert len(stock_rows) == 30

    for row in stock_rows:
        buying_price = int(row["buying_price_inr"])
        quantity = int(row["quantity_on_hand"])
        stock_value = int(row["stock_value_inr"])
        assert stock_value == buying_price * quantity

    total_value = sum(int(r["stock_value_inr"]) for r in stock_rows)
    assert 220_000 <= total_value <= 260_000


def test_store_state_matches_realistic_opening_values() -> None:
    rows = read_csv("store_state.csv")
    assert rows == [
        {
            "day": "1",
            "current_daily_expense_inr": "3000",
            "bank_balance_inr": "120000",
            "customer_satisfaction": "70",
            "order_processing_capacity": "500",
            "cumulative_profit_inr": "0",
        }
    ]


def test_perishable_stock_levels_fit_kirana_scale() -> None:
    stock = {row["product_name"]: row for row in read_csv("stock.csv")}

    assert int(stock["Milk"]["quantity_on_hand"]) <= 120
    assert int(stock["Bread"]["quantity_on_hand"]) <= 50
    assert int(stock["Eggs"]["quantity_on_hand"]) <= 40
    assert int(stock["Vegetables"]["quantity_on_hand"]) <= 80
    assert int(stock["Fruits"]["quantity_on_hand"]) <= 60
    assert int(stock["Bottled Water"]["quantity_on_hand"]) <= 96
    assert int(stock["Biscuits"]["quantity_on_hand"]) <= 80


def test_stocked_products_exist_in_market_offers() -> None:
    market_products = {row["product_name"] for row in read_csv("market_offers.csv")}
    for row in read_csv("stock.csv"):
        assert row["product_name"] in market_products


def test_pending_orders_starts_empty() -> None:
    assert read_csv("pending_orders.csv") == []


def test_market_offers_contain_all_expected_products() -> None:
    market_rows = read_csv("market_offers.csv")
    product_names = [row["product_name"] for row in market_rows]

    assert product_names == EXPECTED_PRODUCTS
    assert len(set(product_names)) == len(EXPECTED_PRODUCTS)

    for row in market_rows:
        assert row["category"] != ""
        assert row["unit"] != ""
        for column in (
            "seller_a_price_inr",
            "seller_a_etd_days",
            "seller_b_price_inr",
            "seller_b_etd_days",
            "seller_c_price_inr",
            "seller_c_etd_days",
            "seller_d_price_inr",
            "seller_d_etd_days",
        ):
            assert row[column] != ""


def test_market_offers_have_varied_seller_patterns() -> None:
    market_rows = read_csv("market_offers.csv")

    etd_patterns = {
        (
            row["seller_a_etd_days"],
            row["seller_b_etd_days"],
            row["seller_c_etd_days"],
            row["seller_d_etd_days"],
        )
        for row in market_rows
    }
    assert len(etd_patterns) >= 8

    c_beats_b = sum(
        int(row["seller_c_price_inr"]) < int(row["seller_b_price_inr"])
        for row in market_rows
    )
    d_beats_b = sum(
        int(row["seller_d_price_inr"]) < int(row["seller_b_price_inr"])
        for row in market_rows
    )
    a_not_cheapest = sum(
        int(row["seller_a_price_inr"])
        > min(
            int(row["seller_a_price_inr"]),
            int(row["seller_b_price_inr"]),
            int(row["seller_c_price_inr"]),
            int(row["seller_d_price_inr"]),
        )
        for row in market_rows
    )

    assert c_beats_b >= 25
    assert d_beats_b >= 25
    assert a_not_cheapest >= 10

    bc_deltas = {int(row["seller_c_price_inr"]) - int(row["seller_b_price_inr"]) for row in market_rows}
    bd_deltas = {int(row["seller_d_price_inr"]) - int(row["seller_b_price_inr"]) for row in market_rows}
    assert len(bc_deltas) >= 12
    assert len(bd_deltas) >= 12


def test_marketing_actions_have_15_unique_ids() -> None:
    rows = read_csv("marketing_actions.csv")
    action_ids = [row["action_id"] for row in rows]
    assert len(rows) == 15
    assert len(set(action_ids)) == 15


def test_marketing_actions_match_realistic_catalog() -> None:
    rows = {row["action_id"]: row for row in read_csv("marketing_actions.csv")}

    assert rows["7"] == {
        "action_id": "7",
        "description": "Local delivery partner tie-up",
        "customer_satisfaction_delta": "5",
        "cost_inr": "5000",
        "recurring_cost_inr": "600",
        "order_processing_capacity_delta": "40",
    }
    assert rows["11"] == {
        "action_id": "11",
        "description": "Open second branch (deposit + fit-out)",
        "customer_satisfaction_delta": "12",
        "cost_inr": "750000",
        "recurring_cost_inr": "3000",
        "order_processing_capacity_delta": "350",
    }
    assert rows["15"] == {
        "action_id": "15",
        "description": "Always-on targeted social ads",
        "customer_satisfaction_delta": "3",
        "cost_inr": "4000",
        "recurring_cost_inr": "1200",
        "order_processing_capacity_delta": "0",
    }


def test_doc_scenarios_match_seed_data() -> None:
    plan_text = PLAN_PATH.read_text(encoding="utf-8")
    stock = {row["product_name"]: row for row in read_csv("stock.csv")}
    market = {row["product_name"]: row for row in read_csv("market_offers.csv")}

    for phrase in (
        "Rice at `138` vs Seller B at `160`",
        "Cooking Oil at `156` vs Seller B at `180`",
        "Spices at `345` vs Seller B at `400`",
        "Bread at `31` vs Seller B at `35`",
        "Eggs at `64` vs Seller B at `72`",
        "Curd at `33` vs Seller B at `35`",
        "Vegetables at `38` vs Seller B at `40`",
        "Always-on targeted social ads",
        "Kitchen Appliances",
        "Biscuits | 40",
        "Bottled Water | 48",
    ):
        assert phrase in plan_text

    assert int(stock["Milk"]["selling_price_inr"]) <= math.ceil(int(stock["Milk"]["buying_price_inr"]) * 1.05)
    assert int(stock["Bread"]["selling_price_inr"]) <= math.ceil(int(stock["Bread"]["buying_price_inr"]) * 1.05)
    assert int(stock["Eggs"]["selling_price_inr"]) <= math.ceil(int(stock["Eggs"]["buying_price_inr"]) * 1.05)
    assert int(stock["Sugar"]["selling_price_inr"]) <= math.ceil(int(stock["Sugar"]["buying_price_inr"]) * 1.06)
    assert int(stock["Biscuits"]["quantity_on_hand"]) == 40
    assert int(stock["Bottled Water"]["quantity_on_hand"]) == 48
    assert int(stock["Kitchen Appliances"]["quantity_on_hand"]) == 4

    assert int(market["Rice"]["seller_a_price_inr"]) == 138
    assert int(market["Cooking Oil"]["seller_a_price_inr"]) == 156
    assert int(market["Spices"]["seller_a_price_inr"]) == 345
    assert int(market["Bread"]["seller_c_price_inr"]) == 31
    assert int(market["Eggs"]["seller_c_price_inr"]) == 64
    assert int(market["Curd"]["seller_c_price_inr"]) == 33
    assert int(market["Vegetables"]["seller_c_price_inr"]) == 38