Warmup: Time Traveling
A good way to get familiar with and begin contributing to a new project is to write tests for it. It’s also the best way to become familiar with a new code base, something you’ll have to do when you start working. It’s pretty common for test code to ultimately take up twice as many lines of code as the actual project code!
You still may feel shaky on RSpec at this point (which is totally normal), so let’s go back in time and write tests for some of the code you’ve already done to build up a bit of muscle memory. If you’ve written a good batch, submit them below and we’ll include them as part of the original project description to help future students!
Assignment 1
- Go back to the Building Blocks Project and write tests for your “Caesar’s Cipher” code. It shouldn’t take more than a half-dozen tests to cover all the possible cases.
- Go back to the Advanced Building Blocks Project and write tests for any 6 of the enumerable methods you wrote there. In this case, identify several possible inputs for each of those functions and test to make sure that your implementation of them actually makes the tests pass. Be sure to try and cover some of the odd edge cases where you can.
- Write tests for your Tic Tac Toe project. In this situation, it’s not quite as simple as just coming up with inputs and making sure the method returns the correct thing. You’ll need to make the tests determine victory or loss conditions are correctly assessed.
- Start by writing tests to make sure players win when they should, e.g. when the board reads X X X across the top row, your
#game-over
method (or its equivalent) should trigger.
- Test each of your critical methods to make sure they function properly and handle edge cases.
- Try using mocks/doubles to isolate methods and make sure that they’re sending back the right outputs.
Student Solutions
Submit a link below to this file on the ruby course github repo with your files in it by using a pull request. See the section on Contributing for how.
Show Student Solutions
- Add your solution below this line!
- Vollantre’s Solution: Caesar Cipher, Enumerable Methods, Tic Tac Toe
- Kevin Vuong’s Solution: Caesar Cipher, Enumerable Methods, Tic Tac Toe
- Rudi Boshoff’s SolutionCaesar Cipher, Enumerable Methods, Tic Tac Toe
- Mohamed Elattar’s SolutionCaesar Cipher, Enumerable Methods, Tic Tac Toe
- prw001’s solutions
- Max Garber’s solutions:Caesar Cipher, Enumerable Methods, Tic-Tac-Toe
- Romane Green’s solutions: Caesar Cipher, Enumerable Methods, Tic-Tac-Toe
- Demo318’s solutions: Caesar Cipher, Enumerable Methods, Tic-Tac-Toe
- Isil Donmez’s solutions: Caesar’s Cipher, Enumerable Methods, Tic-Tac-Toe
- Bruno Parga’s solutions: Caesar’s Cipher, Enumerable Methods, Tic-Tac-Toe
- Ovsjah Schweinefresser’s Solutions: Caesar Cipher, Enumerable Methods, Tic-Tac-Toe
- Jonathan Yiv’s Solutions: Caesar Cipher, Enumerable Methods, Tic-Tac-Toe
- Clayton’s solutions: Caesar Cipher, enumerable methods, Tic Tac Toe
- Kasey’s solutions : Caesar Cipher, enumerable methods,Tic Tac Toe
- xavier’s solutions : Caesar Cipher, enumerable methods,Tic Tac Toe
- Oleh Sliusar’s solutions: Caesar Cipher, Enumerable Methods, Tic-tac-toe
- holdercp’s solutions Caesar Cipher and Enumerable Methods, Tic-Tac-Toe
- theghall’s solutions Caesar Cipher, Enumerable methods, Tic Tac Toe
- Nikolay Dyulgerov’s solutions Caesar Cippher, Enumerable Methods, Tic Tac Toe
- mindovermiles262’s Solutions Caesar Enumerable Tic-Tac-Toe
- yilmazgunalp’s solution Enumerable, TicTacToe
- ToTenMilan’s solution Caesar’s_cipher & stock_picker, Enumerable Methods, Mastermind
- nmac’s solution (Caesar’s cipher, Enumerable methods, Tic-tac-toe)
- Jib’s Solution
- Leonard Soaivan’s solution (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- Donald’s solution
- Marina Sergeyeva’s solution
- Kate McFaul’s solution
- Artur Janik’s solution
- Dominik Stodolny’s solution (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- Lara Finnegan’s solution (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- AtActionPark’s solution (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- Matias Pan’s solution
- Alex Chen’s solution (Caesar Cipher and Enumerable Methods, Tic Tac Toe)
- Dan Hoying’s solution (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- PiotrAleksander’s solution
- Sander Schepens’s solution
- Florian Mainguy’s solution (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- Aviv Levinsky’s solution (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- Giorgos’s solution (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- srashidi’s solution(Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- cdouglass’s solution (Caesar Cipher, Enumerable Methods, Tic-Tac-Toe)
- James Brooks’s solution (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- Luke Walker’s solution (Caesar Cipher, Enumerable, Tic Tac Toe
- Miguel Herrera’s solution
- Max Gallant’s solution
- Fabricio Carrara’s solution (Caesar Cipher, Enumerable, Tic Tac Toe
- Ricardo Villegas’ solution (Caesar Cipher, My_Enumerable Methods,) Tic-Tac-Toe)
- Deepak’s solution
- Kevin Mulherns solution
- DV’s solution (Caesar Cipher, Enumerable, Tic Tac Toe
- Jiazhi Guo’s solution (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- at0micr3d’s solution
- David Chapman’s solution (Ceaser Cipher, Enumerable, and Tic Tac Toe)
- Dylan’s solutions
- Austin Mason’s solution (Ceaser Cipher, Enumerable, and Tic Tac Toe)
- Jerry Gao’s solution (Caesar, Enumerable, Tic-Tac-Toe)
- tholymap’s solution (Caesar Cipher, Enumerable, Tic-Tac-Toe)
- Francisco Carlos’s solution (Ceaser Cipher, Enumerable, Tic-Tac-Toe)
- Sophia Wu’s solution (Caesar Cipher, Enumerable, Tic Tac Toe)
- John Connor’s solution(Caesar Cipher,Enumerable,Tic Tac Toe)
- Simon’s solution(Caesar Cipher,Enumerable,Tic Tac Toe)
- Luján Fernaud’s solution (Caesar Cipher, Enumerable, Tic Tac Toe)
- Cody Buffaloe’s solutions (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- Anistor86’s solutions (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- Jamesredux’s solutions (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- HSaad’s solutions (Caesar Cipher, Enumerable Methods, Tic Tac Toe)
- zasman’s solutions(Caesar Cipher)
- Punnadittr’s solutions
- Tommy’s solution (Caesar Cipher, Enumerable, Tic Tac Toe)
- bchalman’s solutions: Caesar Cipher, Enumerable Methods, Tic Tac Toe
- Alex’s solutions: Caesar Cipher, Enumerable, Tic Tac Toe (incomplete)
- Leila Alderman’s solutions: Caesar cipher and Enumerables
- Emil Dimitrov’s solutions: Caesar’s Cipher, Enumerable, Tic Tac Toe
- Vitaly Osipov’s solutions: Caesar’s Cipher, Enumerable
- Alex Krewson’s solutions
Project: TDD Connect Four
Hopefully everyone has played Connect Four at some point (if not, see the Wikipedia page). It’s a basic game where each player takes turns dropping pieces into the cage. Players win if they manage to get 4 of their pieces consecutively in a row, column, or along a diagonal.
The game rules are fairly straightforward and you’ll be building it on the command line like you did with the other games. If you want to spice up your game pieces, look up the unicode miscellaneous symbols. The Ruby part of this should be well within your capability by now so it shouldn’t tax you much to think about it.
The major difference here is that you’ll be doing this TDD-style. So figure out what needs to happen, write a (failing) test for it, then write the code to make that test pass, then see if there’s anything you can do to refactor your code and make it better.
Only write exactly enough code to make your test pass. Oftentimes, you’ll end up having to write two tests in order to make a method do anything useful. That’s okay here. It may feel a bit like overkill, but that’s the point of the exercise. Your thoughts will probably be something like “Okay, I need to make this thing happen. How do I test it? Okay, wrote the test, how do I code it into Ruby? Okay, wrote the Ruby, how can I make this better?” You’ll find yourself spending a fair bit of time Googling and trying to figure out exactly how to test a particular bit of functionality. That’s also okay… You’re really learning RSpec here, not Ruby, and it takes some getting used to.
Assignment 2
- Build Connect Four! Just be sure to keep it TDD.
Student Solutions
Send us your solution so we can show others! Submit a link to the Github repo with your files in it here using any of the methods listed on the contributing page. Please include your partner’s github handle somewhere in the description if they would like attribution.
Show Student Solutions
Additional Resources
This section contains helpful links to other content. It isn’t required, so consider it supplemental for if you need to dive deeper into something.