Skip to content

Combatd/first_tdd_projects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test Driven Development

Ruby and Rspec Test-Driven Development Projects from App Academy Open

Learning Goals

  • Be able to explain what functionality your testing will cover
  • Know the hierarchy / syntax of RSpec methods (describe, before, let, it, expect, etc.)
  • Be comfortable writing RSpec tests
  • Know when to use let and subject

Expected time: 2hrs

Workflow

  1. Read the entire problem statement.
  2. Talk with your partner to identify test cases and key functionality to expect from your code.
  3. Write RSpec tests.
  4. Write the method you now have tests for. Follow the red-green-refactor approach until all specs pass.

Remove dups

Array has a uniq method that removes duplicates from an array. It returns the unique elements in the order in which they first appeared:

[1, 2, 1, 3, 3].uniq # => [1, 2, 3]

Write your own version of this method called my_uniq; it should take in an Array and return a new array.

Two sum

Write a new Array#two_sum method that finds all pairs of positions where the elements at those positions sum to zero.

NB: ordering matters. We want each of the pairs to be sorted smaller index before bigger index. We want the array of pairs to be sorted "dictionary-wise":

[-1, 0, 2, -2, 1].two_sum # => [[0, 4], [2, 3]]
  • [0, 2] before [2, 1] (smaller first elements come first)
  • [0, 1] before [0, 2] (then smaller second elements come first)

My Transpose

To represent a matrix, or two-dimensional grid of numbers, we can write an array containing arrays which represent rows:

rows = [
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8]
  ]

row1 = rows[0]
row2 = rows[1]
row3 = rows[2]

We could equivalently have stored the matrix as an array of columns:

cols = [
    [0, 3, 6],
    [1, 4, 7],
    [2, 5, 8]
  ]

Write a method, my_transpose, which will convert between the row-oriented and column-oriented representations. You may assume square matrices for simplicity's sake. Usage will look like the following:

my_transpose([
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8]
  ])
 # => [[0, 3, 6],
 #    [1, 4, 7],
 #    [2, 5, 8]]

Stock Picker

Write a method that takes an array of stock prices (prices on days 0, 1, ...), and outputs the most profitable pair of days on which to first buy the stock and then sell the stock. Remember, you can't sell stock before you buy it!

About

Ruby and Rspec Test-Driven Development Projects from App Academy Open

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages