Skip to content

hychan48/google-foobar-2023-q4

Repository files navigation

@hychan48/google-foobar-2023-q4

Production

Replit - Try Me

Pip / Pipx

Installation

# https://replit.com/@jasonchan51/hychan48-google-foobar-2023-q4
pipx install hychan48-google-foobar-2023-q4

hychan48-cake-is-not-a-lie --help
hychan48-cake-is-not-a-lie abab
hychan48-dont-get-volunteered 0 1

Level 1

hychan48-cake-is-not-a-lie abab

# GitHub action runs the PyTests:
pytest levels/q1/tests/solutions_test.py

asciicast asciicast

JavaScript Solution

# JavaScript solution - only for q1
pnpm run test:q1

asciicast

level 2

Question 1

hychan48-dont-get-volunteered 0 1 # Returns 3
pytest ./levels/q2/tests/solutions_bfs_test.py

asciicast asciicast

Background

Assumptions

  • So far it looks like it's either Python 2.7 or Java 8
  • I'm going to use Python 3.11.6, using basic syntax it should be backwards compatible with 2.7
    • Also, I have PyCharm installed already
  • TDD with PyTest

Quick Checklist

  • Documentation
    • Save Original Question
      • /api/v1/files/ (.json)
      • convert to .yaml and .html
    • Reword Question and Keywords
      • readme_q.template.md
    • Principles
      • TDD / BDD
      • Quick and dirty
        • Unless the question piques my research interest
        • 7 days per question seems like a lot of time
    • Priorities
    • JSDoc @typedef but for Python
    • Metadata
      • Author
      • GitHub Repo
      • Environment
      • Time / Space Complexity (if applicable)
  • Validation / Error handling
  • Test cases / Unit Tests
    • Workflow with GitHub actions
      • Lint - Flake8
      • Unit Tests - PyTest

Quick Dev Setup

Non-Dev Container

# install micromamba (aliased as conda) / miniforge3
conda env create -f environment.yml
conda deactivate
conda activate hychan48-google-foobar
# Using micromamba aliased as conda
poetry install

BATS-core

# add this to path:
command -v bats # Check if bats

mkdir -p $HOME/.local/bin
export PATH=$PATH:$HOME/.local/bin
ln -s $PWD/test/bats/bin/bats $HOME/.local/bin/bats # check
which -a bats # check again
whence bats
ls -l $HOME/.local/bin/bats
tree $HOME/.local/bin
pipx ensurepath # will add $HOME/.local/bin to path

Dev Container

# smoke test
pytest levels/q1/tests/solutions_test.py # cake is not a lie
poetry --quiet run hychan48-cake-is-not-a-lie abab
# output: 2

PyTest in Poetry

  • BDD/TDD (Behavior Driven Development / Test Driven Development)
pytest levels/q1/tests/solutions_test.py
pytest levels/q2/tests/solutions_bfs_test.py
# or
poetry install && poetry --quiet run pytest-cake
poetry install && poetry --quiet run pytest-bfs

Backup Conda Environment

# Backup
conda env export --from-history > environment.yml
conda env export > environment.full.yml

# window caveats...
# https://stackoverflow.com/questions/49638329/how-to-create-conda-env-with-both-name-and-path-specified

GitHub Actions Workflows

  1. Build Wheel
  • Add PyTest after adding new features
  1. Publish to PyPi

Requirements.txt

# Manually updated for now. Add to CI/CD later
poetry export -f requirements.txt --output requirements.txt