Coder Social home page Coder Social logo

tdd_workshop's Introduction

Disclaimer

Sharing is caring! This is part of a learning journey. We are much more curious individuals than experts. The objective is to share our learnings so far while enabling us to collaborate, learn and connect around an important topic. We assume that independently of your experience, you are curious to learn, courageous to ask and share and, finally, respectful about the stage each one is in right now.

The workshop is based on our own work together. You will find imperfections or questionable things, let's discuss them.

Commit early and often! Good practices for a commit, by Chris Beams

Purpose

Dive into tests and Test-Driven-Development (TDD) by sharing experience and practicing together

  • Practical workshop, mainly with examples
  • Think programming as communicating
    • Simple, clear, robust code
    • Maintainable, scalable, understandable
    • Effective, resilient to change

Community

In Slack: #tdd-test-driven-development.

Why tests?

  • Make sure the code works as expected
  • Detect edge cases
  • Feel confident to refactor without being afraid of breaking the entire pipeline
  • Your teammates can understand your functions by looking at your tests
  • Prevent unexpected output
  • Simplifies updating code
  • Increases overall efficiency of developing code
  • And most importantly prevents you from pushing any broken code into production!

Requirements

Please check the dedicated page for this workshop.

One way to go

  1. Make a list of tests we know we need to have working
  2. Add a little test: write just enough of a test to fail
  3. Run all tests and fail
  4. Make a little change: write just enough code to make it pass
  5. Run the tests and succeed
  6. Refactor to remove duplication: clean up the mess made getting the test to pass

Discussions:

  • Being able to take teeny-tiny steps, not necessarily doing it
  • Add items to our to-do list rather than addressing them all at once
  • Commit early and often!
  • Let's try: Test pipeline, continuous integration
  • Remember to save changes :-)
  • DRY: Don't Repeat Yourself!
  • @pytest.mark.parametrize to run multiple test cases
  • Debugging with test (tools?)

tdd_workshop's People

Contributors

andreas-el avatar eivindjahren avatar hnformentin avatar lars-petter-hauge avatar oyvindeide avatar

Stargazers

 avatar

Watchers

 avatar  avatar

tdd_workshop's Issues

Exercise 1: Convert input from str -> float

In:

def read_coordinates(file_name: Union[str, Path]) -> List[Tuple[str, str]]:
we are reading a file and turning it into a list of coordinates. However that function returns a list of tuples of strings. As we are doing calculations on the results, we would like it to return float values instead of strings.

  1. Run the test
  2. Modify the tests to be red, and confirm that you get the desired result by running the tests
  3. Refactor the code until you are back to green.

Check individual requirements

  • VSC: terminal type "code" and VSC should open (you can use other tools like Pycharm, but demos are planned in VSC)
  • python --version or python3 --version
  • git --version
  • a virtual environment (recommended)
    python -m venv tdd_venv or python3 -m venv tdd_venv
    .\tdd_venv\Scripts\activate (Windows) or source tdd_venv/bin/activate (unix)
    Tip: create a folder for virtual environments outside the project folders
  • check that the formatting tool black is installed black --version
  • ssh-key connected: Check if you have it connected or Connecting to Github with ssh
  • github: fork repository
  • git clone repository locally
    git clone [email protected]:equinor/tdd_workshop.git
  • install development requirements pip install -r dev-requirements.txt
  • install tdd_workshop package pip install -e .
  • VSC configured to tests: Configure test with VSC (TDD_workshop folder, ctrl+shift+P, Python: Configure tests)
  • type pytest in the terminal and you should be able to run and debug some tests simple locally
  • check if debug mode works:
    image

Handle new lines in the input

Allow the Add method to handle new lines between numbers (instead of commas):

  • The following input is ok: “1\n2,3” (will equal 6)
  • The following input is NOT ok: “1,\n” (not need to prove it - just clarifying)

Exercise 2: Treasure hunt

You are an intrepid explorer, navigating a scenery of rolling hills at night. It is completely dark, and your only source of information is your handheld computer which will give you the next point on your journey. You have heard that there exists a treasure here, and your only clue is that the treasure is located in an incline where the slope between your current position and the next coordinate is above X. Your task is to navigate this landscape and locate the coordinates of the treasure. Example:

Given a list of coordinates (your test input) (x, y):

 [(1, 1), (2.0, 1.8), (2.5, 2.1), (3, 2), (4.3, 7.2), (5.3, 6.2)]

we can calculate the slope along the coordinates:

[0.8, 0.6, -0.2, 4.0, -1.0]  # be wary of rounding of these numbers

given a threshold of 1, the coordinate we are looking for is: (4.3, 7.2)

Your task in image form:

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.