Finished phase 1

This commit is contained in:
Liru 2018-04-20 21:41:52 -04:00
commit b647d8b8f4
11 changed files with 201 additions and 0 deletions

4
.formatter.exs Normal file
View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

24
.gitignore vendored Normal file
View File

@ -0,0 +1,24 @@
# The directory Mix will write compiled artifacts to.
/_build/
# If you run "mix test --cover", coverage assets end up here.
/cover/
# The directory Mix downloads your dependencies sources to.
/deps/
# Where 3rd-party dependencies like ExDoc output generated docs.
/doc/
# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch
# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez
# Ignore package tarball (built via "mix hex.build").
zombie_survivor-*.tar

21
README.md Normal file
View File

@ -0,0 +1,21 @@
# ZombieSurvivor
**TODO: Add description**
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `zombie_survivor` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:zombie_survivor, "~> 0.1.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/zombie_survivor](https://hexdocs.pm/zombie_survivor).

30
config/config.exs Normal file
View File

@ -0,0 +1,30 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# 3rd-party users, it should be done in your "mix.exs" file.
# You can configure your application as:
#
# config :zombie_survivor, key: :value
#
# and access this configuration in your application as:
#
# Application.get_env(:zombie_survivor, :key)
#
# You can also configure a 3rd-party app:
#
# config :logger, level: :info
#
# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"

5
lib/zombie_survivor.ex Normal file
View File

@ -0,0 +1,5 @@
defmodule ZombieSurvivor do
@moduledoc """
Documentation for ZombieSurvivor.
"""
end

View File

@ -0,0 +1,20 @@
defmodule ZombieSurvivor.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
def start(_type, _args) do
# List all child processes to be supervised
children = [
# Starts a worker by calling: ZombieSurvivor.Worker.start_link(arg)
# {ZombieSurvivor.Worker, arg},
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: ZombieSurvivor.Supervisor]
Supervisor.start_link(children, opts)
end
end

View File

@ -0,0 +1,21 @@
defmodule ZombieSurvivor.Survivor do
alias __MODULE__
@type t :: %__MODULE__{
name: String.t(),
wounds: non_neg_integer
}
defstruct name: "", wounds: 0
@spec new([{atom, any}]) :: Survivor.t()
def new(opts \\ []), do: struct(__MODULE__, opts)
@spec dead?(Survivor.t()) :: boolean
def dead?(survivor), do: survivor.wounds >= 2
@spec max_actions(Survivor.t()) :: non_neg_integer
def max_actions(_survivor) do
3
end
end

29
mix.exs Normal file
View File

@ -0,0 +1,29 @@
defmodule ZombieSurvivor.MixProject do
use Mix.Project
def project do
[
app: :zombie_survivor,
version: "0.1.0",
elixir: "~> 1.6",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger],
mod: {ZombieSurvivor.Application, []}
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
]
end
end

42
test/survivor_test.exs Normal file
View File

@ -0,0 +1,42 @@
defmodule SurvivorTest do
use ExUnit.Case
alias ZombieSurvivor.Survivor
import Survivor
describe "new" do
test "gives a survivor with a name" do
assert %Survivor{name: _} = Survivor.new()
end
test "gives a survivor with 0 wounds" do
assert %Survivor{wounds: 0} = Survivor.new()
end
end
describe "dead?/1" do
# TODO: Add property test for this
test "returns true if a survivor has 2 or more wounds" do
s = Survivor.new(wounds: 2)
assert Survivor.dead?(s)
s = Survivor.new(wounds: 3)
assert Survivor.dead?(s)
end
test "returns false if a survivor has less than 2 wounds" do
s = Survivor.new()
refute Survivor.dead?(s)
s = Survivor.new()
refute Survivor.dead?(s)
end
end
describe "max_actions/1" do
test "returns 3 for a new survivor" do
s = Survivor.new()
assert Survivor.max_actions(s) == 3
end
end
end

1
test/test_helper.exs Normal file
View File

@ -0,0 +1 @@
ExUnit.start()

View File

@ -0,0 +1,4 @@
defmodule ZombieSurvivorTest do
use ExUnit.Case
doctest ZombieSurvivor
end