Last active
July 13, 2019 14:53
-
-
Save mjc/90b2c0130bbaf61804f529252a362971 to your computer and use it in GitHub Desktop.
test for fizzbuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule FizzBuzzTest do | |
use ExUnit.Case | |
# to run tests: mix test | |
# to get an irb equivalent with your code loaded in it: iex -S mix | |
# to get a pry in your code: `require IEx;IEx.pry()` | |
# Phase 1: make the test pass. | |
# Phase 2: implement the fizz/buzz check as a pattern match | |
# Phase 3: move the pattern match into multiple function clauses. | |
# Phase 4: add typespecs. https://elixirschool.com/en/lessons/advanced/typespec/ | |
# to test your typespecs: | |
# delete the deps method in your mix.exs file (this is the equivalent of Gemfile) and replace it with this: | |
# def deps, do: [{:dialyxir, "~> 1.0.0-rc.6", only: [:dev], runtime: false}] | |
# to test your typespecs: mix dialyzer | |
# this will take several minutes the first time. | |
# Phase 5: switch to recursion | |
test "passes FizzBuzz" do | |
assert FizzBuzz.fizzbuzz(1, 100) == [ | |
1, | |
2, | |
"Fizz", | |
4, | |
"Buzz", | |
"Fizz", | |
7, | |
8, | |
"Fizz", | |
"Buzz", | |
11, | |
"Fizz", | |
13, | |
14, | |
"FizzBuzz", | |
16, | |
17, | |
"Fizz", | |
19, | |
"Buzz", | |
"Fizz", | |
22, | |
23, | |
"Fizz", | |
"Buzz", | |
26, | |
"Fizz", | |
28, | |
29, | |
"FizzBuzz", | |
31, | |
32, | |
"Fizz", | |
34, | |
"Buzz", | |
"Fizz", | |
37, | |
38, | |
"Fizz", | |
"Buzz", | |
41, | |
"Fizz", | |
43, | |
44, | |
"FizzBuzz", | |
46, | |
47, | |
"Fizz", | |
49, | |
"Buzz", | |
"Fizz", | |
52, | |
53, | |
"Fizz", | |
"Buzz", | |
56, | |
"Fizz", | |
58, | |
59, | |
"FizzBuzz", | |
61, | |
62, | |
"Fizz", | |
64, | |
"Buzz", | |
"Fizz", | |
67, | |
68, | |
"Fizz", | |
"Buzz", | |
71, | |
"Fizz", | |
73, | |
74, | |
"FizzBuzz", | |
76, | |
77, | |
"Fizz", | |
79, | |
"Buzz", | |
"Fizz", | |
82, | |
83, | |
"Fizz", | |
"Buzz", | |
86, | |
"Fizz", | |
88, | |
89, | |
"FizzBuzz", | |
91, | |
92, | |
"Fizz", | |
94, | |
"Buzz", | |
"Fizz", | |
97, | |
98, | |
"Fizz", | |
"Buzz" | |
] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment