commit b647d8b8f404f4f55c70952f40cc840444896163 Author: Liru Date: Fri Apr 20 21:41:52 2018 -0400 Finished phase 1 diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..525446d --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b377c4 --- /dev/null +++ b/.gitignore @@ -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 + diff --git a/README.md b/README.md new file mode 100644 index 0000000..5f6262d --- /dev/null +++ b/README.md @@ -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). + diff --git a/config/config.exs b/config/config.exs new file mode 100644 index 0000000..8e4ea55 --- /dev/null +++ b/config/config.exs @@ -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" diff --git a/lib/zombie_survivor.ex b/lib/zombie_survivor.ex new file mode 100644 index 0000000..34a4819 --- /dev/null +++ b/lib/zombie_survivor.ex @@ -0,0 +1,5 @@ +defmodule ZombieSurvivor do + @moduledoc """ + Documentation for ZombieSurvivor. + """ +end diff --git a/lib/zombie_survivor/application.ex b/lib/zombie_survivor/application.ex new file mode 100644 index 0000000..178c002 --- /dev/null +++ b/lib/zombie_survivor/application.ex @@ -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 diff --git a/lib/zombie_survivor/survivor.ex b/lib/zombie_survivor/survivor.ex new file mode 100644 index 0000000..8d6e31d --- /dev/null +++ b/lib/zombie_survivor/survivor.ex @@ -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 diff --git a/mix.exs b/mix.exs new file mode 100644 index 0000000..68975ad --- /dev/null +++ b/mix.exs @@ -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 diff --git a/test/survivor_test.exs b/test/survivor_test.exs new file mode 100644 index 0000000..e2d5373 --- /dev/null +++ b/test/survivor_test.exs @@ -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 diff --git a/test/test_helper.exs b/test/test_helper.exs new file mode 100644 index 0000000..869559e --- /dev/null +++ b/test/test_helper.exs @@ -0,0 +1 @@ +ExUnit.start() diff --git a/test/zombie_survivor_test.exs b/test/zombie_survivor_test.exs new file mode 100644 index 0000000..ef28bb2 --- /dev/null +++ b/test/zombie_survivor_test.exs @@ -0,0 +1,4 @@ +defmodule ZombieSurvivorTest do + use ExUnit.Case + doctest ZombieSurvivor +end