Skip to content

Thor011/Wargaming_Task

Repository files navigation

Wargaming Home Task - SQLite Database Testing

This project creates and tests an SQLite database for managing ships and their components (weapons, hulls, and engines).

Project Structure

wargaming_task/
├── create_and_fill_db.py  # Database creation and population script
├── conftest.py            # pytest configuration and fixtures
├── test_ships.py          # Test suite for ship components
├── wargaming.db           # Generated SQLite database (created when script runs)
└── README.md              # This file

Database Schema

The database consists of four tables:

ships

  • ship (TEXT, PRIMARY KEY) - Ship identifier
  • weapon (TEXT) - Foreign reference to weapons table
  • hull (TEXT) - Foreign reference to hulls table
  • engine (TEXT) - Foreign reference to engines table

weapons

  • weapon (TEXT, PRIMARY KEY) - Weapon identifier
  • reload_speed (INTEGER) - Weapon reload speed (1-20)
  • rotational_speed (INTEGER) - Weapon rotation speed (1-20)
  • diameter (INTEGER) - Weapon diameter (1-20)
  • power_volley (INTEGER) - Weapon power volley (1-20)
  • count (INTEGER) - Weapon count (1-20)

hulls

  • hull (TEXT, PRIMARY KEY) - Hull identifier
  • armor (INTEGER) - Hull armor value (1-20)
  • type (INTEGER) - Hull type (1-20)
  • capacity (INTEGER) - Hull capacity (1-20)

engines

  • engine (TEXT, PRIMARY KEY) - Engine identifier
  • power (INTEGER) - Engine power (1-20)
  • type (INTEGER) - Engine type (1-20)

Requirements

  • Python 3.8+
  • pytest (for running tests)

Setup

  1. Create and activate a virtual environment (optional but recommended):
python -m venv venv
.\venv\Scripts\Activate.ps1
  1. Install dependencies:
pip install pytest

Usage

Creating the Database

Run the database creation script:

python create_and_fill_db.py

This creates wargaming.db with default settings:

  • 200 ships
  • 20 weapons
  • 5 hulls
  • 6 engines

To specify a custom database path:

python create_and_fill_db.py path\to\custom.db

Running Tests

The test suite validates ship components and verifies that randomization occurred between the original and randomized databases.

Activate virtual environment first:

.\venv\Scripts\Activate.ps1

Run all tests:

pytest test_ships.py -v

Run tests with output showing which components changed:

pytest test_ships.py -s

Run tests for a specific ship:

pytest test_ships.py::test_component[Ship-99-engine] -v -s

Expected result: All 601 tests should pass (600 component tests + 1 overall randomization test).

Test Details

  • Total tests: 601 tests
    • 600 component tests (200 ships × 3 components per ship)
    • 1 overall randomization verification test
  • Components tested: weapon, hull, engine
  • Test mechanism: Compares original database with a randomized copy
  • Current configuration: Randomization is enabled
  • Test output: Use -s flag to see which components were randomized with before/after values

Implementation Details

Random Data Generation

  • Uses fixed seed (RANDOM_SEED = 1337) for reproducibility
  • All numeric parameters are randomly generated between 1-20
  • Ships are assigned random combinations of weapons, hulls, and engines

Test Framework

  • Uses pytest with parametrization to generate tests dynamically
  • Session-level fixtures create databases once for all tests
  • Each test validates one ship component against the original

Randomization Feature

The conftest.py includes a _randomize_db() function that modifies the database in two modes:

  • Mode A: Changes one component (weapon/hull/engine) per ship to a different random component
  • Mode B: Modifies one random parameter in each component type (weapon, hull, engine) used by a ship

The randomization is active by default. For each ship, the system randomly chooses between Mode A or B.

To see which components were randomized:

pytest test_ships.py::test_component -s

This will display output like:

[CHANGED] Ship Ship-99 component 'engine':
  Before: ('Engine-3', 14, 18)
  After:  ('Engine-3', 7, 3)

Notes

  • Database uses INSERT OR REPLACE for idempotent operations
  • All tables use TEXT primary keys for component identifiers
  • The script can be run multiple times - it will recreate the database each time

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages