Skip to content

Ch2 Consolidate getting started guides #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions exercises/chapter2/spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
Welcome to a Spago project!
You can edit this file as you like.
-}
{ name =
"my-project"
{ name = "my-project"
, dependencies =
[ "console", "effect", "math", "psci-support" ]
, packages =
./packages.dhall
, sources =
[ "src/**/*.purs", "test/**/*.purs" ]
[ "console"
, "effect"
, "lists"
, "math"
, "psci-support"
, "test-unit"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
}
11 changes: 11 additions & 0 deletions exercises/chapter2/src/Euler.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Euler where

import Prelude
import Data.List (range, filter)
import Data.Foldable (sum)

ns n = range 0 (n - 1)

multiples n = filter (\n -> mod n 3 == 0 || mod n 5 == 0) (ns n)

answer n = sum (multiples n)
12 changes: 4 additions & 8 deletions exercises/chapter2/src/Main.purs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
module Main where

import Prelude
import Euler (answer)
import Effect.Console (log)

import Effect.Console (logShow)
import Math (sqrt)


diagonal :: Number -> Number -> Number
diagonal w h = sqrt (w * w + h * h)

main = logShow (diagonal 3.0 4.0)
main = do
log ("The answer is " <> show (answer 1000))
38 changes: 34 additions & 4 deletions exercises/chapter2/test/Main.purs
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
module Test.Main where

import Prelude

import Test.Solutions
import Effect (Effect)
import Effect.Class.Console (log)
import Euler (answer)
import Test.Unit (suite, test)
import Test.Unit.Assert as Assert
import Test.Unit.Main (runTest)

main :: Effect Unit
main = do
log "🍝"
log "You should add some tests."
runTest do
suite "Euler - Sum of Multiples" do
test "below 10" do
Assert.equal 23 (answer 10)
test "below 1000" do
Assert.equal 233168 (answer 1000)

{- Move this block comment starting point to enable more tests
suite "diagonal" do
test "3 4 5" do
Assert.equal 5.0 (diagonal 3.0 4.0)
test "5 12 13" do
Assert.equal 13.0 (diagonal 5.0 12.0)
suite "circleArea" do
test "radius 1" do
Assert.equal 3.141592653589793 (circleArea 1.0)
test "radius 3" do
Assert.equal 28.274333882308138 (circleArea 3.0)
suite "circleArea" do
test "radius 1" do
Assert.equal 3.141592653589793 (circleArea 1.0)
test "radius 3" do
Assert.equal 28.274333882308138 (circleArea 3.0)
suite "addE" do
test "1.23" do
Assert.equal 3.948281828459045 (addE "1.23")
test "4.56" do
Assert.equal 7.278281828459045 (addE "4.56")
-}
3 changes: 3 additions & 0 deletions exercises/chapter2/test/Solutions.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Test.Solutions where

import Prelude
Loading