Skip to content
Permalink
Browse files

Added solar tests and module

  • Loading branch information...
robconery committed Apr 17, 2016
1 parent d2eb25f commit 78185ef11437f32458377f455b973fdb14114ed8
Showing with 92 additions and 49 deletions.
  1. +1 −1 lib/converter.ex
  2. +17 −0 lib/solar.ex
  3. +2 −2 mix.exs
  4. +10 −0 mix.lock
  5. +0 −12 test/argument_error_test.exs
  6. +20 −0 test/calcs_test.exs
  7. +0 −19 test/compiler_problem_test.exs
  8. +9 −0 test/converter_test.exs
  9. +0 −15 test/physics_test.exs
  10. +33 −0 test/solar_test.exs
@@ -24,7 +24,7 @@ defmodule Converter do
round_to(val, 1)
end

def to_km(val) when is_integer(val)do
def to_km(val) when is_integer(val) or is_float(val) do
val / 1000
end

@@ -0,0 +1,17 @@
defmodule Solar do
def power(%{classification: :M, scale: s}), do: s * 10
def power(%{classification: :X, scale: s}), do: s * 1000
def power(%{classification: :C, scale: s}), do: s

def no_eva(flares) do
Enum.filter flares, fn(flare) ->
power(flare) > 1000
end
end

def deadliest(flares) do
Enum.map(flares, &(power(&1)))
|> Enum.max
end

end
@@ -14,7 +14,7 @@ defmodule Physics.Mixfile do
#
# Type "mix help compile.app" for more information
def application do
[applications: [:logger]]
[applications: [:logger, :timex]]
end

# Dependencies can be Hex packages:
@@ -27,6 +27,6 @@ defmodule Physics.Mixfile do
#
# Type "mix help deps" for more examples and options
defp deps do
[]
[{:timex, "~> 2.1.4"}]
end
end
@@ -0,0 +1,10 @@
%{"certifi": {:hex, :certifi, "0.4.0"},
"combine": {:hex, :combine, "0.7.0"},
"gettext": {:hex, :gettext, "0.11.0"},
"hackney": {:hex, :hackney, "1.6.0"},
"idna": {:hex, :idna, "1.2.0"},
"metrics": {:hex, :metrics, "1.0.1"},
"mimerl": {:hex, :mimerl, "1.0.2"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.0"},
"timex": {:hex, :timex, "2.1.4"},
"tzdata": {:hex, :tzdata, "0.5.7"}}

This file was deleted.

@@ -0,0 +1,20 @@
defmodule CalcsTest do
use ExUnit.Case


test "cubing" do
val = 3 |> Calcs.cubed
assert val == 27
end

test "squaring" do
val = 5654987423 |> Calcs.squared
assert val == 31978882754288180929
end

test "square root" do
val = 66445577 |> Calcs.square_root
assert val == 8151.415643923453
end

end

This file was deleted.

@@ -0,0 +1,9 @@
defmodule ConverterTest do
use ExUnit.Case

test "to_light_seconds returns ... something" do
converted = Converter.to_light_seconds({:miles, 1000}, precision: 5)
assert converted == 0.00537
end

end
@@ -22,24 +22,9 @@ defmodule PhysicsTest do
#use assert here
end

test "Converting to to_light_seconds" do
ls = Converter.to_light_seconds({:miles, 1000}, precision: 5)
assert ls == 0.00537
end

test "Converter one works" do
ls = Converter.to_light_seconds({:miles, 1000}, precision: 5)
assert ls == 0.00537
end

test "Orbital acceleration for earth at 100km" do
orbital_acc = Physics.Rocketry.orbital_acceleration(100)
assert orbital_acc == 9.515619587729839
end

test "Orbital term for 100km above earth" do
term = Physics.Rocketry.orbital_term(100)
assert (term > 4) && (term < 5) #crap fix this!
end

end
@@ -0,0 +1,33 @@
defmodule SolarTest do
use ExUnit.Case
use Timex

setup do
flares = [
%{classification: :X, scale: 99, date: Date.from({1859, 8, 29})},
%{classification: :M, scale: 5.8, date: Date.from({2015, 1, 12})},
%{classification: :M, scale: 1.2, date: Date.from({2015, 2, 9})},
%{classification: :C, scale: 3.2, date: Date.from({2015, 4, 18})},
%{classification: :M, scale: 83.6, date: Date.from({2015, 6, 23})},
%{classification: :C, scale: 2.5, date: Date.from({2015, 7, 4})},
%{classification: :X, scale: 72, date: Date.from({2012, 7, 23})},
%{classification: :X, scale: 45, date: Date.from({2003, 11, 4})},
]
{:ok, data: flares}
end

test "We have 8 solar flares", %{data: flares} do
assert length(flares) == 8
end

test "Go inside", %{data: flares} do
d = Solar.no_eva(flares)
assert length(d) == 3
end

test "the deadliest flare", %{data: flares} do
death = Solar.deadliest(flares) |> IO.inspect
assert death == 83600 #hmmm
end

end

1 comment on commit 78185ef

@g33klady

This comment has been minimized.

Copy link

commented on 78185ef Dec 11, 2017

with timex 3.1.24, syntax seems to be:
Timex.to_date() rather than Date.from()

Please sign in to comment.
You can’t perform that action at this time.