or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-8/

Product Inventory Manager

A system for managing product inventory that supports serialization and deserialization of complex collection-based data structures.

Capabilities

Serializes product lists

  • Converts a list of product objects to JSON-compatible format @test

Deserializes product lists

  • Reconstructs a list of product objects from JSON-compatible dictionaries @test

Manages category mappings

  • Serializes a dictionary mapping category names to lists of products @test
  • Deserializes category mappings back to typed dictionaries @test

Tracks unique product tags

  • Serializes a set of unique tags to JSON format @test
  • Deserializes JSON arrays back to sets of strings @test

Implementation

Create a Product class with the following attributes:

  • id: integer product identifier
  • name: string product name
  • price: float price value
  • tags: set of string tags

Create an Inventory class that manages:

  • A list of products
  • A dictionary mapping category names (strings) to lists of products
  • A set of all unique tags across all products

The Inventory class should provide methods to:

  1. Add products to the inventory
  2. Serialize the entire inventory to a dictionary
  3. Deserialize from a dictionary back to an Inventory object with proper types

@generates

API

from typing import List, Dict, Set
from dataclasses import dataclass

@dataclass
class Product:
    """Represents a product with id, name, price, and tags."""
    id: int
    name: str
    price: float
    tags: Set[str]

class Inventory:
    """Manages a collection of products organized by categories."""

    def __init__(self):
        """Initialize an empty inventory."""
        pass

    def add_product(self, product: Product, category: str) -> None:
        """Add a product to the inventory under a specific category."""
        pass

    def to_dict(self) -> dict:
        """Serialize the inventory to a dictionary."""
        pass

    @staticmethod
    def from_dict(data: dict) -> 'Inventory':
        """Deserialize an inventory from a dictionary."""
        pass

    def get_products(self) -> List[Product]:
        """Return all products in the inventory."""
        pass

    def get_categories(self) -> Dict[str, List[Product]]:
        """Return the category mappings."""
        pass

    def get_all_tags(self) -> Set[str]:
        """Return all unique tags across all products."""
        pass

Test Cases

Test: Serialize and deserialize product list

# Create products
p1 = Product(id=1, name="Laptop", price=999.99, tags={"electronics", "computers"})
p2 = Product(id=2, name="Mouse", price=25.50, tags={"electronics", "accessories"})

# Create inventory
inv = Inventory()
inv.add_product(p1, "Electronics")
inv.add_product(p2, "Electronics")

# Serialize
data = inv.to_dict()

# Deserialize
restored_inv = Inventory.from_dict(data)

# Verify products are restored correctly
products = restored_inv.get_products()
assert len(products) == 2
assert products[0].id == 1
assert products[0].name == "Laptop"
assert products[0].price == 999.99
assert products[0].tags == {"electronics", "computers"}

@test

Test: Category mappings preserved

# Create inventory with multiple categories
inv = Inventory()
inv.add_product(Product(1, "Laptop", 999.99, {"electronics"}), "Electronics")
inv.add_product(Product(2, "Desk", 299.99, {"furniture"}), "Furniture")

# Serialize and deserialize
data = inv.to_dict()
restored_inv = Inventory.from_dict(data)

# Verify categories
categories = restored_inv.get_categories()
assert "Electronics" in categories
assert "Furniture" in categories
assert len(categories["Electronics"]) == 1
assert categories["Electronics"][0].name == "Laptop"

@test

Test: Tag sets maintained correctly

# Create inventory
inv = Inventory()
inv.add_product(Product(1, "Laptop", 999.99, {"electronics", "computers"}), "Electronics")
inv.add_product(Product(2, "Phone", 599.99, {"electronics", "mobile"}), "Electronics")

# Serialize and deserialize
data = inv.to_dict()
restored_inv = Inventory.from_dict(data)

# Verify all unique tags are present
all_tags = restored_inv.get_all_tags()
assert all_tags == {"electronics", "computers", "mobile"}

@test

Dependencies { .dependencies }

jsons { .dependency }

Provides serialization and deserialization support for Python collections and custom objects.