diff --git a/.gitignore b/.gitignore index 8630a11..eaaa90f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ bin/configlet.exe **/output **/.psc* **/.psa* + +.work diff --git a/.travis.yml b/.travis.yml index 4e07b85..3b5b6fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ sudo: false install: - nvm install 6 - nvm use 6 - - npm install -g purescript@0.11.1 pulp@11.0.0 bower + - npm install -g purescript@0.11.6 pulp@12.0.1 bower script: - bin/fetch-configlet @@ -15,4 +15,3 @@ script: cache: directories: - $HOME/.cache/bower/ - - $HOME/.exercise_cache/ diff --git a/bin/test-one.sh b/bin/test-one.sh deleted file mode 100755 index 4ff986c..0000000 --- a/bin/test-one.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash - -exercise_dir="$1" -if [[ -z "$exercise_dir" ]]; then - echo "Usage: $BASH_SOURCE " - exit 1 -fi - -xpurescript=$(dirname "$BASH_SOURCE") -xpurescript=$(readlink -f "$xpurescript/..") -cd "$xpurescript" - -cache_dir="$HOME" -if [ -z "$TRAVIS" ]; then - cache_dir="$xpurescript" -fi -cache_dir="$cache_dir/.exercise_cache" - -declare -i TEST_RESULT=0 - -echo -echo -e "\e[1;34m----- Testing exercise \e[33m$exercise_dir\e[34m -----\e[0;39m" -echo - -if [[ ! -f "exercises/$exercise_dir/bower.json" ]]; then - echo -e "\e[1;31mExercise \e[33m$exercise_dir\e[31m is missing bower.json, failing test\e[0;39m" - exit 1 -fi - -cd "exercises/$exercise_dir" - -exercise_src=src -exercise_examples_src=examples/src - -# Setup Travis cache -for dir in bower_components output; do - cache="$cache_dir/$dir" - - mkdir -p "$cache" - ln -f -s "$cache" -done - -mv "$exercise_src" "$exercise_src.impl" -mv "$exercise_examples_src" "$exercise_src" - -time bower install -time pulp test - -# capture result from last command (pulp test) -if [[ $? == 0 ]]; then - TEST_RESULT=1 -fi - -# be kind, rewind -mv "$exercise_src" "$exercise_examples_src" -mv "$exercise_src.impl" "$exercise_src" - -exit $TEST_RESULT diff --git a/bin/test.sh b/bin/test.sh index 34d0c76..540b0d4 100755 --- a/bin/test.sh +++ b/bin/test.sh @@ -4,30 +4,71 @@ xpurescript=$(dirname "$BASH_SOURCE") xpurescript=$(readlink -f "$xpurescript/..") cd "$xpurescript" -declare -i TEST_RESULT=0 -FAILED_EXERCISES='' +# Prepare the work directory -cd exercises +work_dir="$xpurescript/.work" -for exercise_dir in * -do - "$xpurescript/bin/test-one.sh" "$exercise_dir" +mkdir -p $work_dir - if [[ $? == 0 ]]; then - TEST_RESULT=1 - FAILED_EXERCISES+="$exercise_dir\n" - fi +# Clean up if this is used locally (not on Travis) + +if [[ -z "$TRAVIS" ]]; then + rm $work_dir/bower.json + rm -f $work_dir/src/*.purs + rm -f $work_dir/test/*.purs +fi + +for dir in src test; do + mkdir -p $work_dir/$dir done -echo -if [[ $TEST_RESULT == 0 ]]; then - echo -e "\e[1;32mAll exercises passed\e[0;39m" -else - echo -e "\e[1;31mThe following exercises failed" +# Copy the exercises, tests and common bower.json + +cp etc/bower.json $work_dir +cp exercises/*/examples/src/*.purs $work_dir/src + +for exercise_full in exercises/*; do + exercise=$(basename $exercise_full) + module=$(basename $exercise_full/examples/src/*.purs) + + cp exercises/$exercise/test/Main.purs $work_dir/test/$module +done + +# List for troubleshooting purposes + +cd $work_dir + +for f in bower.json src test; do + echo + echo -e "\e[1;32m--- [ $f ]\e[0;39m" + echo - echo -e "\e[1;33m" - printf $FAILED_EXERCISES - echo -e "\e[0;39m" + ls --color -l $f +done + +# Create Test.Main and update exercise test modules + +cd $xpurescript + +node etc/test-main-maker.js $work_dir/test +node etc/test-module-updater.js $work_dir/test + +# Install bower dependencies, build and test + +cd $work_dir - exit $TEST_RESULT +time bower install +time pulp test + +test_result=$? + +# Report the results + +echo +if [[ $test_result == 0 ]]; then + echo -e "\e[1;32m[ All tests have passed ]\e[0;39m" +else + echo -e "\e[1;31m[ Some tests have failed ]\e[0;39m" fi + +exit $test_result \ No newline at end of file diff --git a/etc/bower.json b/etc/bower.json new file mode 100644 index 0000000..7dc82bd --- /dev/null +++ b/etc/bower.json @@ -0,0 +1,26 @@ +{ + "name": "purescript-exercise", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "output" + ], + "dependencies": { + "purescript-console": "^3.0.0", + "purescript-datetime": "^3.4.0", + "purescript-either": "^3.1.0", + "purescript-enums": "^3.2.1", + "purescript-integers": "^3.1.0", + "purescript-lists": "^4.10.0", + "purescript-maps": "^3.5.2", + "purescript-prelude": "^3.1.0", + "purescript-sets": "^3.0.0", + "purescript-strings": "^3.3.1", + "purescript-unicode": "^3.0.1" + }, + "devDependencies": { + "purescript-psci-support": "^3.0.0", + "purescript-test-unit": "^13.0.0" + } +} diff --git a/etc/test-main-maker.js b/etc/test-main-maker.js new file mode 100644 index 0000000..8550d00 --- /dev/null +++ b/etc/test-main-maker.js @@ -0,0 +1,48 @@ +const fs = require('fs') +const os = require('os') +const path = require('path') + +const testDir = process.argv[2] + +const modules = fs + .readdirSync(testDir) + .map(f => f.replace(/.purs$/, '')) + +const testMainFile = path.join(testDir, 'Main.purs') + +const eol = os.EOL + +const imports = modules + .map(m => 'import Test.' + m + ' as Test' + m) + .join(eol) + +const calls = modules + .map(m => ' Test' + m + '.suites') + .join(eol) + +const testMain = ` +module Test.Main where + +import Prelude +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) +import Test.Unit.Console (TESTOUTPUT) +import Test.Unit.Main (runTest) + +` ++ imports + +` + +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest do +` ++ calls + +fs.writeFileSync(testMainFile, testMain) diff --git a/etc/test-module-updater.js b/etc/test-module-updater.js new file mode 100644 index 0000000..0bf8d92 --- /dev/null +++ b/etc/test-module-updater.js @@ -0,0 +1,20 @@ +const fs = require('fs') +const os = require('os') +const path = require('path') + +const testDir = process.argv[2] + +const modules = fs + .readdirSync(testDir) + .forEach(f => { + const moduleFile = path.join(testDir, f) + const moduleName = f.replace(/.purs$/, '') + + const module = fs.readFileSync(moduleFile, 'utf8') + + const moduleMod = module.replace( + /module Test\.Main where/, + 'module Test.' + moduleName + ' where') + + fs.writeFileSync(moduleFile, moduleMod) + }) diff --git a/exercises/accumulate/test/Main.purs b/exercises/accumulate/test/Main.purs index 3f22fe8..c37f7a5 100644 --- a/exercises/accumulate/test/Main.purs +++ b/exercises/accumulate/test/Main.purs @@ -2,16 +2,27 @@ module Test.Main where import Prelude import Control.Monad.Eff (Eff) -import Test.Unit (suite, test) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import Test.Unit.Assert as Assert import Data.List (List(Nil), fromFoldable) import Data.String as String import Accumulate (accumulate) - -main :: Eff _ Unit -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "Accumulate.accumulate" do test "empty accumulation" $ let diff --git a/exercises/acronym/test/Main.purs b/exercises/acronym/test/Main.purs index 65048a5..fd60ec6 100644 --- a/exercises/acronym/test/Main.purs +++ b/exercises/acronym/test/Main.purs @@ -4,12 +4,23 @@ import Prelude import Test.Unit.Assert as Assert import Acronym (abbreviate) import Control.Monad.Eff (Eff) -import Test.Unit (suite, test) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites -main :: Eff _ Unit -main = runTest do +suites :: forall e. TestSuite e +suites = do suite "Acronym.abbreviate" do test "acronyms from title case" $ Assert.equal diff --git a/exercises/all-your-base/test/Main.purs b/exercises/all-your-base/test/Main.purs index 6a48ab1..2aec2d1 100644 --- a/exercises/all-your-base/test/Main.purs +++ b/exercises/all-your-base/test/Main.purs @@ -2,14 +2,26 @@ module Test.Main where import Prelude import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Data.Maybe (Maybe(..)) import Test.Unit.Assert as Assert -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import AllYourBase (rebase) -main :: Eff _ Unit -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "AllYourBase.rebase" do test "single bit one to decimal" $ diff --git a/exercises/allergies/test/Main.purs b/exercises/allergies/test/Main.purs index 3da5c22..0816d4c 100644 --- a/exercises/allergies/test/Main.purs +++ b/exercises/allergies/test/Main.purs @@ -2,15 +2,25 @@ module Test.Main where import Prelude import Control.Monad.Eff (Eff) -import Data.Maybe (Maybe(..)) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Test.Unit.Assert as Assert -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import Allergies (allergicTo, list) -main :: Eff _ Unit -main = runTest do - +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "Allergies.allergicTo" do test "no allergies means not allergic" $ diff --git a/exercises/atbash-cipher/test/Main.purs b/exercises/atbash-cipher/test/Main.purs index d236767..5b8e3a8 100644 --- a/exercises/atbash-cipher/test/Main.purs +++ b/exercises/atbash-cipher/test/Main.purs @@ -2,15 +2,26 @@ module Test.Main where import Prelude import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Data.Maybe (Maybe(..)) import Test.Unit.Assert as Assert -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import AtbashCipher (decode, encode) -main :: Eff _ Unit -main = runTest do - +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "AtbashCipher.encode" do test "encode yes" $ diff --git a/exercises/binary-search/test/Main.purs b/exercises/binary-search/test/Main.purs index b12f5cc..568024b 100644 --- a/exercises/binary-search/test/Main.purs +++ b/exercises/binary-search/test/Main.purs @@ -2,14 +2,26 @@ module Test.Main where import Prelude import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Data.Maybe (Maybe(..)) import Test.Unit.Assert as Assert -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import BinarySearch (find) -main :: Eff _ Unit -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "BinarySearch.find" do test "finds a value in an array with one element" $ diff --git a/exercises/bob/examples/src/Bob.purs b/exercises/bob/examples/src/Bob.purs index 367e4ae..6ba5e98 100644 --- a/exercises/bob/examples/src/Bob.purs +++ b/exercises/bob/examples/src/Bob.purs @@ -12,7 +12,7 @@ import Partial.Unsafe as Partial hey :: String -> String hey msg = if hasLetters msg && allUppercase msg then - "Whoachill out!" + "Whoa, chill out!" else if isQuestion msg then "Sure." else if isSilence msg then diff --git a/exercises/bob/test/Main.purs b/exercises/bob/test/Main.purs index 624fa23..07178dc 100644 --- a/exercises/bob/test/Main.purs +++ b/exercises/bob/test/Main.purs @@ -1,13 +1,26 @@ module Test.Main where import Prelude -import Test.Unit (suite, test) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import Test.Unit.Assert as Assert import Bob as Bob - -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "Bob.hey" do test "stating something" do Assert.equal "Whatever." $ diff --git a/exercises/bracket-push/test/Main.purs b/exercises/bracket-push/test/Main.purs index 0e82a47..a56e201 100644 --- a/exercises/bracket-push/test/Main.purs +++ b/exercises/bracket-push/test/Main.purs @@ -2,13 +2,25 @@ module Test.Main where import Prelude import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Test.Unit.Assert as Assert -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import BracketPush (isPaired) -main :: Eff _ Unit -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "BracketPush.isPaired" do test "paired square brackets" $ diff --git a/exercises/crypto-square/test/Main.purs b/exercises/crypto-square/test/Main.purs index f4c1854..cf4e37f 100644 --- a/exercises/crypto-square/test/Main.purs +++ b/exercises/crypto-square/test/Main.purs @@ -2,8 +2,11 @@ module Test.Main where import Prelude import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Test.Unit.Assert as Assert -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import CryptoSquare ( normalizedPlaintext , plaintextSegments @@ -11,9 +14,17 @@ import CryptoSquare ( normalizedPlaintext , ciphertext ) -main :: Eff _ Unit -main = runTest do - +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "CryptoSquare.normalizedPlaintext" do test "Lowercase" $ diff --git a/exercises/diamond/test/Main.purs b/exercises/diamond/test/Main.purs index 098a94a..1455348 100644 --- a/exercises/diamond/test/Main.purs +++ b/exercises/diamond/test/Main.purs @@ -2,14 +2,25 @@ module Test.Main where import Prelude import Control.Monad.Eff (Eff) -import Data.Maybe (Maybe(..)) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Test.Unit.Assert as Assert -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import Diamond (rows) -main :: Eff _ Unit -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "Diamond.rows" do test "Degenerate case with a single 'A' row" $ diff --git a/exercises/difference-of-squares/test/Main.purs b/exercises/difference-of-squares/test/Main.purs index 19c3262..4b254ec 100644 --- a/exercises/difference-of-squares/test/Main.purs +++ b/exercises/difference-of-squares/test/Main.purs @@ -2,14 +2,25 @@ module Test.Main where import Prelude import Control.Monad.Eff (Eff) -import Data.Maybe (Maybe(..)) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Test.Unit.Assert as Assert -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import DifferenceOfSquares (differenceOfSquares, squareOfSum, sumOfSquares) -main :: Eff _ Unit -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "Square the sum of the numbers up to the given number" do test "square of sum 5" $ diff --git a/exercises/etl/test/Main.purs b/exercises/etl/test/Main.purs index c9d6c57..a5c3201 100644 --- a/exercises/etl/test/Main.purs +++ b/exercises/etl/test/Main.purs @@ -2,16 +2,27 @@ module Test.Main where import Prelude import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Data.Map (fromFoldable) -import Data.Maybe (Maybe(..)) import Data.Tuple (Tuple(..)) import Test.Unit.Assert as Assert -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import Etl (transform) -main :: Eff _ Unit -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "Etl.transform" do test "a single letter" $ diff --git a/exercises/hamming/test/Main.purs b/exercises/hamming/test/Main.purs index c37ec76..6df7379 100644 --- a/exercises/hamming/test/Main.purs +++ b/exercises/hamming/test/Main.purs @@ -4,15 +4,26 @@ module Test.Main where import Prelude import Control.Monad.Eff (Eff) -import Test.Unit (suite, test) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import Test.Unit.Assert as Assert -import Data.String as String -import Data.Maybe (Maybe(Just, Nothing)) +import Data.Maybe (Maybe(..)) import Hamming (distance) -main :: Eff _ Unit -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "hamming" do test "identical strands" $ Assert.equal (Just 0) (distance "A" "A") diff --git a/exercises/hello-world/test/Main.purs b/exercises/hello-world/test/Main.purs index 7b18c46..a62cca6 100644 --- a/exercises/hello-world/test/Main.purs +++ b/exercises/hello-world/test/Main.purs @@ -1,14 +1,27 @@ module Test.Main where import Prelude -import Test.Unit (suite, test) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import Test.Unit.Assert as Assert import Data.Maybe (Maybe(Just, Nothing)) import HelloWorld (helloWorld) +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites -main = runTest do +suites :: forall e. TestSuite e +suites = do suite "HelloWorld.helloWorld" do test "Hello with no name" do Assert.equal "Hello, World!" (helloWorld Nothing) diff --git a/exercises/isogram/test/Main.purs b/exercises/isogram/test/Main.purs index 6822e7f..071e2b7 100644 --- a/exercises/isogram/test/Main.purs +++ b/exercises/isogram/test/Main.purs @@ -2,13 +2,25 @@ module Test.Main where import Prelude import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Test.Unit.Assert as Assert -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import Isogram (isIsogram) -main :: Eff _ Unit -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "Isogram.transform" do test "empty string" $ diff --git a/exercises/largest-series-product/test/Main.purs b/exercises/largest-series-product/test/Main.purs index 8c05472..e5dd569 100644 --- a/exercises/largest-series-product/test/Main.purs +++ b/exercises/largest-series-product/test/Main.purs @@ -2,14 +2,26 @@ module Test.Main where import Prelude import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Data.Maybe (Maybe(..)) import Test.Unit.Assert as Assert -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import LargestSeriesProduct (largestProduct) -main :: Eff _ Unit -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "LargestSeriesProduct.largestProduct" do test "finds the largest product if span equals length" $ diff --git a/exercises/leap/test/Main.purs b/exercises/leap/test/Main.purs index e35451a..e316c42 100644 --- a/exercises/leap/test/Main.purs +++ b/exercises/leap/test/Main.purs @@ -1,13 +1,26 @@ module Test.Main where import Prelude -import Test.Unit (suite, test) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import Test.Unit.Assert as Assert import Leap as Leap +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites -main = runTest do +suites :: forall e. TestSuite e +suites = do suite "Leap.isLeapYear" do test "leap year" do Assert.equal true $ Leap.isLeapYear 1996 diff --git a/exercises/meetup/test/Main.purs b/exercises/meetup/test/Main.purs index 3160c6b..e8db0e3 100644 --- a/exercises/meetup/test/Main.purs +++ b/exercises/meetup/test/Main.purs @@ -3,15 +3,27 @@ module Test.Main where import Prelude import Test.Unit.Assert as Assert import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Data.Date (Weekday(..), canonicalDate) import Data.Enum (toEnum) import Data.Maybe (Maybe(..)) import Meetup (Week(..), meetup) -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) -main :: Eff _ Unit -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "Meetup.meetup" do test "monteenth of May 2013" $ diff --git a/exercises/pangram/test/Main.purs b/exercises/pangram/test/Main.purs index 526ba46..0a6e302 100644 --- a/exercises/pangram/test/Main.purs +++ b/exercises/pangram/test/Main.purs @@ -1,13 +1,26 @@ module Test.Main where import Prelude -import Test.Unit (suite, test) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import Test.Unit.Assert as Assert import Pangram (isPangram) - -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "Pangram.isPangram" do test "sentence empty" do Assert.equal false $ diff --git a/exercises/pascals-triangle/test/Main.purs b/exercises/pascals-triangle/test/Main.purs index 9e57760..f8ee7d3 100644 --- a/exercises/pascals-triangle/test/Main.purs +++ b/exercises/pascals-triangle/test/Main.purs @@ -2,21 +2,26 @@ module Test.Main where import Prelude import Test.Unit.Assert as Assert -import Control.Monad.Aff.AVar (AVAR) import Control.Monad.Eff (Eff) +import Control.Monad.Aff.AVar (AVAR) import Control.Monad.Eff.Console (CONSOLE) import Data.Maybe (Maybe(..)) import PascalsTriangle (rows) -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) -main :: Eff ( console :: CONSOLE - , testOutput :: TESTOUTPUT - , avar :: AVAR - ) +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) Unit -main = runTest do +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "Given a count, return a collection of that many rows of pascal's triangle" do test "zero rows" $ diff --git a/exercises/raindrops/test/Main.purs b/exercises/raindrops/test/Main.purs index bb0a88f..8e8fecb 100644 --- a/exercises/raindrops/test/Main.purs +++ b/exercises/raindrops/test/Main.purs @@ -1,13 +1,26 @@ module Test.Main where import Prelude -import Test.Unit (suite, test) +import Control.Monad.Eff (Eff) +import Control.Monad.Aff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import Test.Unit.Assert as Assert import Raindrops (raindrops) +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites -main = runTest do +suites :: forall e. TestSuite e +suites = do suite "Raindrops.raindrops" do test "1" do Assert.equal "1" $ raindrops 1 diff --git a/exercises/scrabble-score/test/Main.purs b/exercises/scrabble-score/test/Main.purs index 3e78aa5..217cc98 100644 --- a/exercises/scrabble-score/test/Main.purs +++ b/exercises/scrabble-score/test/Main.purs @@ -3,13 +3,24 @@ module Test.Main where import Prelude import Test.Unit.Assert as Assert import Control.Monad.Eff (Eff) +import Control.Monad.Aff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import ScrabbleScore (scoreWord) -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) - -main :: Eff _ Unit -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "ScrabbleScore.scoreWord" do test "lowercase letter" do Assert.equal 1 (scoreWord "a") diff --git a/exercises/triangle/test/Main.purs b/exercises/triangle/test/Main.purs index a6d4dd1..a013c2e 100644 --- a/exercises/triangle/test/Main.purs +++ b/exercises/triangle/test/Main.purs @@ -3,14 +3,25 @@ module Test.Main where import Prelude import Test.Unit.Assert as Assert import Control.Monad.Eff (Eff) +import Control.Monad.Aff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Data.Either (Either(Left, Right)) -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import Triangle (triangleKind, Triangle(Equilateral, Isosceles, Scalene)) +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites -main :: Eff _ Unit -main = runTest do +suites :: forall e. TestSuite e +suites = do suite "Triangle.triangleKind" do test "equilateral triangles have equal sides" do Assert.equal diff --git a/exercises/word-count/test/Main.purs b/exercises/word-count/test/Main.purs index ff8b8a0..43775ba 100644 --- a/exercises/word-count/test/Main.purs +++ b/exercises/word-count/test/Main.purs @@ -3,14 +3,26 @@ module Test.Main where import Prelude import Test.Unit.Assert as Assert import Control.Monad.Eff (Eff) +import Control.Monad.Aff.AVar (AVAR) +import Control.Monad.Eff.Console (CONSOLE) import Data.StrMap (fromFoldable) import Data.Tuple (Tuple(..)) -import Test.Unit (suite, test) +import Test.Unit (TestSuite, suite, test) +import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) import WordCount (wordCount) -main :: Eff _ Unit -main = runTest do +main :: forall eff + . Eff ( avar :: AVAR + , console :: CONSOLE + , testOutput :: TESTOUTPUT + | eff + ) + Unit +main = runTest suites + +suites :: forall e. TestSuite e +suites = do suite "WordCount.wordCount" do test "count one word" $