Exercise Wednesday

Goal: Focus on breaking your project down into small behavior examples and writing one test at a time. Make a list of specifications with input and output examples before writing any code. Also, as our projects grow in size, continue to practice good organization by keeping business logic and user interface logic distinctly separate.

## Warm Up

Let's say we have an application that counts the number of vowels in a string. This application has tests detailing each behavior it must exhibit. However, they're out of order! Reorder the following list of tests from the simplest possible behavior to the most complex behavior with your partner. Consult with other pairs if necessary.

``````Describe: vowelCounter();

Test: "It recognizes vowels in a multiple word sentence regardless of capitalization."
Expect(vowelCounter("CATS CATERED THE EVENT")).toEqual(7);

Test: "It recognizes a single vowel in a word with multiple characters."
Expect(vowelCounter("cat")).toEqual(1);

Test: "It recognizes a single vowel."
Expect(vowelCounter("a")).toEqual(1);

Test: "It recognizes multiple vowels in a single word."
Expect(vowelCounter("cater")).toEqual(2);

Test: "It recognizes a single vowel regardless of case."
Expect(vowelCounter("A")).toEqual(1);

Test: "It recognizes all vowels in a multiple-word sentence regardless of inconsistent capitalization."
Expect(vowelCounter("CaTS CATEReD ThE EveNT")).toEqual(7);

Test: "It ignores non-alphabetical characters since they can't be vowels."
Expect(vowelCounter("*&\$92%")).toEqual(0);

Test: "It recognizes vowels in a multiple-word sentence."
Expect(vowelCounter("cats catered the event")).toEqual(7);
``````

## Code

### Leap Year

Follow along with the leap year lesson to build an application that identifies whether a given year is a leap year. You may choose to add a UI to the application if you wish.

### Pig Latin

Write a Pig Latin translator or should we say an "igPay atinLay anslatorTray"? Read all instructions carefully before beginning.

#### How Pig Latin Works

First, here are the rules of Pig Latin:

• For words beginning with a vowel, add "way" to the end.

• For words beginning with one or more consonants, move all of the first consecutive consonants to the end, and add "ay".

• If the first consonants include "qu", move the "u" along with the "q". Don't forget about words like "squeal" where "qu" doesn't come first!

• For words beginning with "y", treat "y" as a consonant.

#### Instructions

1. Before writing any code, make a list of specs detailing each behavior your program will have. Start with the simplest possible behavior, and slowly move up in complexity.

2. Have at least two other pairs check your specs before you begin coding. Ensure that each possible behavior is represented by a spec, and that they are ordered from simplest to most complex.

Now you're ready to start writing (and passing tests). Here's the process:

1. Write a test for the simplest possible behavior. We will get you started:
``````Describe: `pigLatin()`
Test: "It will add 'way' to the end of words that begin with a vowel"
Expect(pigLatin("a")).toEqual("away");
``````
1. Write the smallest amount of code needed to get the test passing.

2. Test the code in the console, REPL, or JSFiddle.

3. Once the test is passing, commit your code.

Repeat the cycle above for each test. Do not move onto the next test until the previous one passes.

Once you've completed your business logic, feel free to add a user interface with jQuery so you can run your application in the browser. Do not add a UI until after you've written and tested all business logic.

When you get to consonants, don't try to solve it all at once. Instead, start with an example of a word that only has one consonant. Next, try a word with two consonants. Finally, work your way up to a word with three consonants. After you've written passing tests for this code, tackle the exceptions to the rule like "qu" and "y". Then, when your application can successfully translate single words, work on translating entire sentences.

Here are a few methods that you may want to consider for solving this problem. Note that there are plenty of other ways to solve this problem, too!

Take a look at this and other documentation to gather the tools you'll need before you try to fulfill your specs.

### Further Exploration

#### Refactor with Regular Expressions

Refactor your code for the projects above using regular expressions.

Note: Once again, do not worry about using regex if you are still trying to understand loops. You do not need to use regex on any code reviews!

#### Bases

Binary: Write a method to convert numbers from binary to decimal. The input should be a string, and the output an integer. Decimal is the normal system we use for counting. We start at 0, increment until we reach 9, and then reset back to 0 and add another number to the left. In binary, we also start at zero, but we only increment until we reach 1. Then we reset back to zero and add another number to the left. Write specs, implement the smallest possible behavior, and don't move onto the next test until the previous test is passing.

Here are some example of numbers in decimal and binary:

``````Decimal  Binary
0        0
1        1
2       10
3       11
4      100
...      ...
``````

Trinary: You get where I'm going, right?

Hexadecimal: Here's what happens after 9...

``````Decimal  Hexadecimal
...      ...
9        9
10        a
11        b
12        c
13        d
14        e
15        f
16       10
17       11
...     ...
``````

If you get this far, write a method that takes two arguments: the number to be evaluated and the base you would like it to be evaluated in.

## Peer Code Review

• Are there tests for each behavior?
• Are all tests passing?
• If business and user interface logic well-separated?
• Does the application work as expected?

If you would like to view an example README, check out this one made by Epicodus graduates, David Wilson and Marilyn Carlin. Below is the raw version.

```# Scrabble Score Checker

#### A program that allows users to input a word and determine its raw Scrabble score, assuming no special tiles. 6/1/17

#### By **Marilyn Carlin and David Wilson**

## Description

A website created with C# and HTML where a user can submit a word and determine its raw Scrabble score.

### Specs
| Spec | Input | Output |
| :-------------     | :------------- | :------------- |
| **Homepage** | User accesses localhost:5004 | Homepage with user input form |
| **Program Gathers User Input** | User input: "pants" | Output: "pants" |
| **Program Removes Spaces from User Input**| User Input: "pants pants" | Output: "pantspants" |
| **Program Removes Punctuation from User Input**| Input: "p#an^[email protected]  /p(ant%s" | Output: "pantspants" |
| **Program Assigns Characters Numeric Values** | Input: "pants" | Output: "3 1 1 1 1" |
| **Program Sums Character Values**| Input: "3 1 1 1 1" | Page Displays: 7 |

## Setup/Installation Requirements

1. To run this program, you must have a C# compiler. I use [Mono](http://www.mono-project.com).
2. Install the [Nancy](http://nancyfx.org/) framework to use the view engine. Follow the link for installation instructions.
3. Clone this repository.
4. Open the command line--I use PowerShell--and navigate into the repository. Use the command "dnx kestrel" to start the server.
5. On your browser, navigate to "localhost:5004" and enjoy!

## Known Bugs
* No known bugs at this time.

## Technologies Used
* C#
* Nancy framework
* Razor View Engine
* ASP.NET Kestrel HTTP server
* xUnit

* HTML

## Support and contact details

_Email no one with any questions, comments, or concerns._