GithubHelp home page GithubHelp logo

enums-exercises's Introduction

Enums Exercises

Setup

Clone this repository:

$ cd ~/turing/1module/
$ git clone https://github.com/turingschool/enums-exercises.git
$ cd enums-exercises

How the Exercises are Organized

These exercises are broken up by method -- each enumerable method will be covered by 2 test files. In one test file, we'll practice using the enumerable in question (map, find, etc). In the other, we'll look at how the enumerable might be implemented in terms of the fundamental each method.

Remember that all the enumerable methods are implemented in terms of each, so by looking at the methods in this way, we'll gain some insight into how each method is put together under the hood.

Solving the Exercises

After cloning the repository down, and checking out a new branch, we are ready to get started on these enumerables exercises.

The goal of these exercises is to help you understand enumerables, both how they work and how they can be replicated through the use of the #each, the basis of all enumerables.

For each method, there are two files of interest. Let's look at map as an example:

  1. exercises/map_pattern_test.rb
  2. exercises/map_test.rb

In the map_pattern_test.rb you'll find a collection of exercises which do what map is good at, but they do it just with each. This file will give us some insight into how map works internally, hopefully helping us gain a deeper understanding around when we might use each one.

Then, in the other file, map_test.rb you'll find the same examples using map itself. These examples will generally be much more concise, and will give a good demonstration of how using the appropriate enumerable method (as opposed to doing everything with each) can make our lives much easier!

Running the Test Files

To run each example, we'll simply use the ruby command in combination with the path to that file. For example to run the 2 map files above, we would use: ruby exercises/map_pattern_test.rb and ruby exercises/map_test.rb, respectively.

Recommended Exercise Order

You should perform the exercises in the order below:

  • map
  • select
  • find (aka detect)
  • sort_by
  • count
  • reject
  • reduce
  • any?
  • all?
  • none?
  • one?
  • group_by
  • zip

You should perform the pattern test first, and then the test.

For example, you should work on map_pattern_test.rb followed by map_test.rb Upon completing that, you should do select_pattern_test.rb and then select_test.rb and so forth.

Recommended Workflow

Here's how we recommend you work through the exercises:

  • Open your text editor with two panes (left and right)
  • In the left pane, open the pattern file like map_pattern_test.rb
  • In the right pane, open the matching file like map_test.rb
  • Run the map_pattern_test.rb and solve the first exercise
  • Run the map_test.rb and solve the same exercise
  • Repeat for each matching pair of exercises
  • Commit your solutions after finishing each file

Contributing Patches

Fixing Errors in Exercises

If you find an error in one of the exercises, then it needs to be fixed upstream in the generators or templates.

For example, someone discovered that there were two tests with the same name in the all_pattern_test.rb exercise:

def test_all_gone
  skip
  words = ["gone", "gone", "gone", "gone", "gone", "gone", "gone"]
  all_gone = true
  # Your code goes here
  assert all_gone
end

def test_all_gone
  skip
  words = ["gone", "gone", "gone", "gone", "gone", "there", "gone", "gone"]
  # Your code goes here
  refute all_gone
end

The second test should have been named test_not_all_gone.

In order to fix this, we need to locate the problem generator: lib/generator/all_problem.rb.

exercise << Problem.new(
  "all_gone",
  {"words" => %w(gone gone gone gone gone gone gone)},
  {"all_gone" => "assert"},
  "word == 'gone'"
).assignment!

exercise << Problem.new(
  "all_gone",
  {"words" => %w(gone gone gone gone gone there gone gone)},
  {"all_gone" => "refute"},
  "word == 'gone'"
)

The name of the second problem can be changed.

Then regenerate the exercises with:

rake generate

Finally, run the tests:

rake test

Creating New Exercises

Check out master:

$ git checkout master

Create a new branch:

$ git checkout -b new-exercises

Make up one extra test for each test suite. Remember to delete the implementation once it's passing, and add a skip to it.

$ git diff
$ git add -A
$ git commit -m "Add more exercises"

Push your branch up to GitHub:

$ git push -u origin new-exercises

Submit a pull request (go to the front page of your own enums-exercises repository, there should be a button to compare/create a pull request for the branch that you just pushed up).

Keeping in sync with the upstream repository

origin is your fork of the project. We'll need to connect to the upstream repository.

To do this, add a new remote named upstream that points to the Turing School repository:

$ git remote add upstream [email protected]:turingschool/enums-exercises.git

Then pull down the updated version of upstream:

$ git fetch upstream

And now make sure you're on master:

$ git checkout master
$ git branch # should say *master

Make master point to the exact commit that upstream/master is pointing at:

$ git reset --hard upstream/master

License

The MIT License (MIT)

Copyright (c) 2014 Jumpstart Lab

enums-exercises's People

Contributors

agsiegert avatar fluxusfrequency avatar jcasimir avatar kytrinyx avatar mikedao avatar neslom avatar rajeshreddym avatar rjmcdonald83 avatar seeflanigan avatar srt32 avatar worace avatar wvmitchell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

enums-exercises's Issues

Add generators for more methods

  • include? N/A -- too simple
  • sort_by
  • count
  • reduce
  • grep -- this is a one-liner in the enum template
  • each_slice
  • zip -- this is a one-liner in the enum template
  • each_with_index
  • max_by
  • min_by
  • group_by
  • none?
  • one?
  • max
  • min
  • cycle
  • each_with_object

Fill out the second test suite in each file

The first test suite is #each, the second is whichever enumerable method we're focusing on. For the moment I just have the first test filled in, we should have all the tests with some implementation removed.

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.