Hamburger Icon
  • Labs icon Lab
  • Core Tech
Labs

Guided: Test Driven Development While Building a Set Class - Python 3

This hands-on lab is designed to help you practice test driven development while building a version of the Set data type in C#. A series of guided steps will walk you through the process of Test Driven Development which include writing a test, implementing functionality, and refactoring to maintain green to green test coverage. By the end of the lab, you will have demonstrated a strong understanding of the Test Driven Development process in Python.

Labs

Path Info

Duration
Clock icon 1h 12m
Published
Clock icon Aug 14, 2023

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Implement Set Contains Following TDD

    In this section, you will implement the contains method for a MySet class. This will require making minimal changes to the add method. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).

    For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.

    The files you will be working on throughout this lab is my_set.py and my_set_test.py. The objective is to create a functioning MySet class that can be used like one would expect a Set object would be. However, we will not be focused on performance like a traditional set.

    The solution file for a task that is implementing functionality can be found in soln/step1/{corresponding task}/my_set.py.

    The solution file for a task that is implementing a test can be found in soln/step5/my_set_test.py.

    It is important to note that if the task you are working on asks you to implement a test, you will be working in the my_set.py file. Otherwise, you will be implementing functionality in the my_set_test.py.

    To run tests, use the command python3 my_set_test.py.

  2. Challenge

    Implement Set Add Following TDD

    In this section, you will implement the add method for a MySet class. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).

    For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.

    The solution file for a task that is implementing functionality can be found in soln/step2/{corresponding task}/my_set.py.

    The solution file for a task that is implementing a test can be found in soln/step5/my_set_test.py.

    It is important to note that if the task you are working on asks you to implement a test, you will be working in the my_set.py file. Otherwise, you will be implementing functionality in the my_set_test.py.

  3. Challenge

    Implement Set Remove Following TDD

    In this section, you will implement the remove method for a MySet class. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).

    For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.

    The solution file for a task that is implementing functionality can be found in soln/step3/{corresponding task}/my_set.py.

    The solution file for a task that is implementing a test can be found in soln/step5/my_set_test.py.

    It is important to note that if the task you are working on asks you to implement a test, you will be working in the my_set.py file. Otherwise, you will be implementing functionality in the my_set_test.py.

  4. Challenge

    Implement Set Size Following TDD

    In this section, you will implement the size method for a MySet class. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).

    For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.

    The solution file for a task that is implementing functionality can be found in soln/step4/{corresponding task}/my_set.py.

    The solution file for a task that is implementing a test can be found in soln/step5/my_set_test.py.

    It is important to note that if the task you are working on asks you to implement a test, you will be working in the my_set.py file. Otherwise, you will be implementing functionality in the my_set_test.py.

  5. Challenge

    Implement Set Clear Following TDD

    In this section, you will implement the clear method for a MySet class. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).

    For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.

    The solution file for a task that is implementing functionality can be found in soln/step5/{corresponding task}/my_set.py.

    The solution file for a task that is implementing a test can be found in soln/step5/my_set_test.py.

    It is important to note that if the task you are working on asks you to implement a test, you will be working in the my_set.py file. Otherwise, you will be implementing functionality in the my_set_test.py.

Jaecee is an associate author at Pluralsight helping to develop Hands-On content. Jaecee's background in Software Development and Data Management and Analysis. Jaecee holds a graduate degree from the University of Utah in Computer Science. She works on new content here at Pluralsight and is constantly learning.

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.