Skip to content

Magicianred/test-driven-javascript-dsa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Test-Driven JavaScript Data Structures & Algorithms


Data structures and algorithms implemented with test-driven JavaScript.




Maybe writing all unit tests ahead of time to cover all possible edge cases for a specific function is quite impractical due to time always being against us as software engineers; hopefully, the practice of test-driven development, with the time we can give it, can aid a mindset of considering the full breadth of scenarios for often open-ended problems and their potential solutions.

This is my own educational journey of understanding the how and the why for JavaScript code written to solve common, and often ambiguous, problems. I hope you find my examples helpful as I start to add more.

— @pjnalls




Running Tests for a JavaScript Data Structure or Algorithm


Navigate to location of file of JavaScript data-structure or algorithm problem-solution

~/test-driven-javascript-dsa (main) $ cd algorithms

Use the node command to run the JavaScript program to run test cases for solution.

~/test-driven-javascript-dsa/algorithms (main) $ node fizzbuzz.js

If all test pass, all output should display in green.

$ node fizzbuzz.js

 ✓ Output is Fizz: 33, Buzz: 20, FizzBuzz: 6 as expected.
 ✓ Output is Fizz: 0, Buzz: 0, FizzBuzz: 0 as expected.
 ✓ Output is Fizz: 3, Buzz: 2, FizzBuzz: 0 as expected.
 ✓ Output is Fizz: 3, Buzz: 1, FizzBuzz: 0 as expected.
 ✓ Output is Fizz: 1, Buzz: 0, FizzBuzz: 0 as expected.
 ✓ Output is Fizz: 1, Buzz: 1, FizzBuzz: 0 as expected.
 ✓ Output is Fizz: 5, Buzz: 3, FizzBuzz: 1 as expected.
 ✓ Output is Fizz: 33333, Buzz: 19999, FizzBuzz: 6666 as expected.

 ✓ All tests for 'getNumberOfFizzBuzzWith' solution passed.

If any test fails, the output for the test case and the test suite result should display in red.

$ node fizzbuzz.js

 ✓ Output is Fizz: 33, Buzz: 20, FizzBuzz: 6 as expected.
 ✓ Output is Fizz: 0, Buzz: 0, FizzBuzz: 0 as expected.
 ✓ Output is Fizz: 3, Buzz: 2, FizzBuzz: 0 as expected.
 ✓ Output is Fizz: 3, Buzz: 1, FizzBuzz: 0 as expected.
 ✓ Output is Fizz: 1, Buzz: 0, FizzBuzz: 0 as expected.
 ✓ Output is Fizz: 1, Buzz: 1, FizzBuzz: 0 as expected.
 ✓ Output is Fizz: 5, Buzz: 3, FizzBuzz: 1 as expected.
 ✖ Output is Fizz: 3, Buzz: 2, FizzBuzz: 0 but expected Fizz: 33333, Buzz: 19999, FizzBuzz: 6666.

 ✖ 1 of 8 tests for 'getNumberOfFizzBuzzWith' solution failed.


About

Data structures and algorithms implemented with test-driven JavaScript.

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published