Skip to content

Dafloresdiaz/Capital_Gains

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Capital Gains

Calculate the tax the user needs to pay based on the profit or losses of a stock market investment

Technical and architectural decisions

  • Why Python: Because is the programming lenguage that I used daily and I have more experience, is easy to mantain and for the purpose of the app it can be undestood very easly.
  • I used the Singleton Design Pattern: The clases ReadJson and CapitalGains classes to ensure that only one instance of each is created during execution
    • ReadJson is responsible for parsing the input string into JSON object, and having a single instance avoids redundant parsing logic across modules.
    • CapitalGains centralizes the tax calculation logic, ensuring consistency.
  • I didn't use a database: The app does not require a database connection, as it doesn’t need to persist any information.
  • Architecture: This is a script-style app designed to be used from the console. The user can run the script, provide a JSON string, and receive tax calculations as output.

Requirements

  • Python 3.13.0 (local development)
  • All the libraries used by the app are in "requirements.txt"

Libries used in the project

Pytest: library used for creating tests for the app.

How to run it locally

  • Install the dependecies:
 pip install -r requirements.txt  
  • Run the following command:
python main.py -j '[{"operation":"buy","unit-cost":10.0,"quantity":100},{"operation":"sell","unit-cost":15.0,"quantity":50},{"operation":"sell","unit-cost":15.0,"quantity":50}]'

How to run it using Docker

  1. Create the build
docker build -t capital-gains .
  1. Run the container, this will create a new instance of the container
docker run -it capital-gains  
  1. It will enter to the console, you will see:
root@cb8dbed4c114:/app# 
  1. To run the app, use the command:
python main.py -j '[{"operation":"buy","unit-cost":10.0,"quantity":100},{"operation":"sell","unit-cost":15.0,"quantity":50},{"operation":"sell","unit-cost":15.0,"quantity":50}]'

How to run the unit and integration tests

  • These commands can be used locally or inside the docker container
  • Run the following command for running unit and integration tests:
pytest tests/
  • Run the following command for integration tests:
pytest tests/integration/
  • Run the following command for running unit tests:
pytest tests/unit/

Examples

  • Console command: alt text
  • Tests: alt text
  • Tests Coverage: alt text

About

Calculate the tax the user needs to pay based on the profit or losses of a stock market investment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published