Git Product home page Git Product logo

pizza_parlor's Introduction

Pizza Parlor

This exercise is designed to help us discuss designing programs for testability, especially when working with external dependencies such as a required data import task.

Structure

.
├── Gemfile
├── Gemfile.lock
├── README.md
├── data
│   └── toppings.csv
├── lib
│   ├── topping.rb
│   └── toppings_menu.rb
└── test
    ├── topping_test.rb
    └── toppings_menu_test.rb

Assignment

Complete this exercise by building out the following 2 classes:

  • A Topping class that can be created with three arguments: name, price, and is_vegetarian. The Topping should allow users to access these values, and is_vegetarian should return a boolean.
  • A ToppingsMenu class which can hold a collection of Toppings. ToppingsMenu should also have the following methods:
    • load_menu: which accepts a path to a CSV and creates appropriate Topping objects for each row in the file.
    • find_by_name: accepts a topping name as a string and returns the Topping instance which matches that name.

Use TDD to build out these objects so that they can be used according to the following spec:

topping = Topping.new({name: "Anchovies", price: "2", is_vegetarian: "no"})
topping.name
=> "Anchovies"
topping.price
=> 2
topping.is_vegetarian
=> false


tm = ToppingMenu.new
tm.find_by_name("anchovies")
=> nil
tm.load_menu("./data/toppings.csv")
tm.find_by_name("anchovies")
=> <#Topping>
t = tm.find_by_name("anchovies")
t..name
=> "anchovies"

Questions

  • What was easy to test?
  • What was difficult to test?
  • How might you refactor?
  • Could you continue to refactor to include another class that completely encapsulates the reading of the CSV?

pizza_parlor's People

Contributors

worace avatar s-espinosa avatar

Watchers

James Cloos avatar

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.