Skip to content

Instantly share code, notes, and snippets.

@StevenMeiklejohn
StevenMeiklejohn / tdd_ruby_loop_hash_lab.md
Created November 2, 2016 14:27
Instructions for Week 1 day 3 Ruby/array/loop/hash lab.

Arrays and Hashes TDD Lab

Working in pairs, create and test-drive the following functions:

  1. Given two arrays:

    prices = [ 1.23, 6.98, 8.43, 2.45 ]
    costs = [ 4.23, 1.12, 0.52, 8.67 ]
    
##Weekend Homework
###Card Game
This weekend's homework is to model a basic card game and implement the rules.
We aren't looking for a running game, just good TDD to demonstrate that the game works as it should.
####Part A - Highest Card
Build a simple card game that deals one card to every player and the player with the highest card wins.

Homework Create your own class with an internal collection of a different class. It should have methods for count, add, isFull etc. Remember to write tests for your classes!

Some examples:

A Bus class with an array, passengers of Persons. A Classroom class with an array, students of Persons. A Library class with an array, stock, of Books. Extensions:

Homework

Create your own class with an internal collection of a different class. It should have methods for count, add, isFull etc. Remember to write tests for your classes!

Some examples:

  • A Bus class with an array, passengers of Persons.
  • A Classroom class with an array, students of Persons.
  • A Library class with an array, stock, of Books.

Extensions:

Task

Go and write tests for the rest of the methods in the Robot class, and them implement them:

  • double checkBattery()
    • returns percentage of battery life left
  • String makeDrink (String drink)
    • passes in the name of the drink being made e.g. tea
    • uses up 10% of the battery life
    • returns the string "I am making" + drink
  • String washDishes()

Card Game Lab

This lab is to model a basic card game and implement the rules.

We aren't looking for a running game, just good TDD to demonstrate that the game works as it should.

Highest Card

Build a simple card game that deals one card to every player and the player with the highest card wins.

Extension

Friends Lab

We have a bunch of information about a set of friends. We're going to find out some interesting information about them using TDD.

We need to to complete the tasks in the comments of the friends_spec.rb file. Write your tests in that file first, then write the function to pass the test in friends.rb. There is one example test and function already.

Classes Lab / Homework

In this lab, we'd like you to make some classes of your own. Below we've outlined a few scenarios to be modelled as Classes. Throughout each part stick to using our Test Driven Development process of writing our tests first then writing our methods and refactoring until they pass.

Learning Objectives

  1. Create your own class
  2. Create multiple objects
  3. Add some properties
  4. Use accessors
# SQL Homework
The Dominion Cinema are having a Marvel Movie Marathon! They have asked you to help maintain their database of movies with times and attendees.
## To access the database:
First, create a database called 'marvel'
```
# terminal

SQL Homework

The Dominion Cinema are having a Marvel Movie Marathon! They have asked you to help maintain their database of movies with times and attendees.

To access the database:

First, create a database called 'marvel'

# terminal