Tested Stack
Mix.install([
{:jason, "~> 1.4"},
{:kino, "~> 0.9", override: true},
{:youtube, github: "brooklinjazz/youtube"},
{:hidden_cell, github: "brooklinjazz/hidden_cell"}
])
Navigation
Home Report An Issue Stack ServerTraffic Light ServerTested Stack
Previously you created a Stack GenServer. Now you’re going to re-create the Stack GenServer with a full test suite.
The Stack process should store a list as state and push/2 elements onto the stack, and pop/2 elements off of the stack like so.
{:ok, pid} = Stack.start_link([])
[:one] = Stack.push(pid, :one)
[:two, :one] = Stack.push(pid, :two)
:two = Stack.pop(pid)
:one = Stack.pop(pid)
# Return No Value When The Stack Is Empty
nil = Stack.pop(pid)
Pair Testing
This will be a pair testing exercise. One student will be the tester and the other will be the implementer. The tester will write the test, and the implementer will implement the code for the test.
As the implementer you may challenge your tester to improve their tests by writing only the code necessary to make the test pass (within reason) even if it is a false-positive. This will encourage your tester to write more comprehensive tests.
Swap roles for each new test.
Create A Mix Project
Create a new mix project and use LiveShare to make it simpler to collaborate with your pair partner.
mix new stack
Copy the code below into your Stack module.
defmodule Stack do
use GenServer
def start_link(_opts) do
end
def push(pid, element) do
end
def pop(pid) do
end
end
Then copy the following code into the associated test file for the Stack module.
defmodule StackTest do
use ExUnit.Case
describe "start_link/1" do
test "with no configuration"
test "with a default state"
end
describe "push/2" do
test "an element onto an empty stack"
test "an element onto a stack with one element"
test "an element onto a stack with multiple elements"
end
describe "pop/1" do
test "an empty stack"
test "a stack with one element"
test "a stack with multiple elements"
end
end
Bonus: GitHub Repository
Upload your stack project to GitHub. You may add your partner as a collaborator, or they can fork the project so that you both own a copy.
Create a README that describes the purpose of the project and what you learned.
Commit Your Progress
DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.
Run git status to ensure there are no undesirable changes.
Then run the following in your command line from the curriculum folder to commit your progress.
$ git add .
$ git commit -m "finish Tested Stack exercise"
$ git push
We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.
We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.