Skip to content

Instantly share code, notes, and snippets.

@LeilaniL
Last active January 22, 2021 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeilaniL/60fd14dd69c4cfb4130e108fb17c9b25 to your computer and use it in GitHub Desktop.
Save LeilaniL/60fd14dd69c4cfb4130e108fb17c9b25 to your computer and use it in GitHub Desktop.
Example of ordering specs from least to most complex

An example solution to the warm-up exercise on this LearnHowToProgram lesson.

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

This is simplest because you'd only need to compare a single letter to a list of vowels -- nothing to worry about in terms of case-sensitivity, spaces, or punctuation etc.

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

Same as above, except now we run that comparison within a for-loop to go through each letter in the word

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

We should be able to do this with the code we have so far that's already checking whether each letter in a word is a vowel and adding to the count.

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

Now we add on the built-in string method, toLowerCase(), before comparing letters. You could argue for this scenario actually being the 2nd simplest to handle.

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

We now need to make sure our for-loop will continue regardless of whether it encounters an empty space or a letter, and that it continues to only increment the count if it encounters a vowel.

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

Should already be handled by our code since we started converting everything to lower-case before comparing.

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

Same as above.

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

This is a weird one. I think the complexity depends on the language. You could argue for it being the simplest -- in C#, you can just use a built-in method Char.IsLetter() and filter out special chars right from the get-go. With JavaScript, I don't know of a similar method, and I think you'd have to write some RegEx (regular expressions) to deal with it, or even write an array of all letters and check whether the character in question is found in that array. You could also check the ASCII code value of the character and make sure it's within 65 - 122, which corresponds with everything from A to z.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment