Skip to content

Commit

Permalink
Now tired of having everything in the same file.
Browse files Browse the repository at this point in the history
Scrolling! Boo!
  • Loading branch information
marick committed Apr 7, 2021
1 parent aecc931 commit 87910da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 49 deletions.
39 changes: 28 additions & 11 deletions lib/hillel_budget.ex
@@ -1,18 +1,35 @@
defmodule HillelBudget do
@moduledoc """
Documentation for `HillelBudget`.
"""
def remaining_total_after_bill(limit, bill) do
item_charges = for item <- bill do
count = Map.get(item, :count, 1)
item.cost * count
end

limit - Enum.sum(item_charges)
end

def can_afford?(budget, bill) do
remaining_total_after_bill(budget.total_limit, bill) >= 0
end

@doc """
Hello world.
def budget(total_limit) do
%{total_limit: total_limit}
end

# I noticed that I'd gotten my terminology messed up, using "bills and bill"
# instead of "bill and item"

## Examples
def normalize(item) when is_map(item) do
cost = item.cost
categories = Map.get(item, :categories, [])
count = Map.get(item, :count, 1)

iex> HillelBudget.hello()
:world
Enum.map(1..count, fn _ ->
%{cost: cost, categories: categories}
end)
end

"""
def hello do
:world
def normalize(bill) when is_list(bill) do
Enum.flat_map(bill, &normalize/1)
end
end
41 changes: 3 additions & 38 deletions test/hillel_budget_test.exs
@@ -1,42 +1,6 @@
defmodule HillelBudgetTest do
use ExUnit.Case

# Next step, I'll be working on debiting from categories, so I should treat the
# total the same way.

def remaining_total_after_bill(limit, bill) do
item_charges = for item <- bill do
count = Map.get(item, :count, 1)
item.cost * count
end

limit - Enum.sum(item_charges)
end

def can_afford?(budget, bill) do
remaining_total_after_bill(budget.total_limit, bill) >= 0
end

def budget(total_limit) do
%{total_limit: total_limit}
end

# I noticed that I'd gotten my terminology messed up, using "bills and bill"
# instead of "bill and item"

def normalize(item) when is_map(item) do
cost = item.cost
categories = Map.get(item, :categories, [])
count = Map.get(item, :count, 1)

Enum.map(1..count, fn _ ->
%{cost: cost, categories: categories}
end)
end

def normalize(bill) when is_list(bill) do
Enum.flat_map(bill, &normalize/1)
end
import HillelBudget

describe "normalization" do
test "normalizing a single item" do
Expand All @@ -58,6 +22,8 @@ defmodule HillelBudgetTest do
end
end



describe "total budget alone" do
test "total budget boundaries" do
bill = [%{cost: 50}]
Expand All @@ -77,5 +43,4 @@ defmodule HillelBudgetTest do
@tag :skip
test "category with total"
end

end

0 comments on commit 87910da

Please sign in to comment.