Skip to content

Commit

Permalink
Merge pull request #396 from petertseng/multiple-examples
Browse files Browse the repository at this point in the history
travis: Support multiple example directories; anagram: Add multiple examples
  • Loading branch information
rbasso authored Oct 12, 2016
2 parents 767b32e + 56eb038 commit 4082786
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 10 deletions.
33 changes: 26 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ script:
SET_RESOLVER="--resolver ${RESOLVER}"
fi
test_exercise () {
stack test ${SET_RESOLVER} `# Select the correct resolver. `\
--install-ghc `# Download GHC if not in cache.`\
--no-terminal `# Terminal detection is broken.`\
--pedantic `# Enable -Wall and -Werror. `
}
for exercise in ${TRAVIS_BUILD_DIR}/exercises/* ; do
pushd ${exercise}
Expand All @@ -50,13 +57,25 @@ script:
mkdir -p "${HOME}/.foldercache/${exercise}/.stack-work"
ln -f -s "${HOME}/.foldercache/${exercise}/.stack-work"
# Here we prepare the exercise to be tested by Stack.
MODULE=`sed -n 's/ *module \+\([a-zA-Z0-9]\+\).*/\1/p' src/Example.hs`
mv src/Example.hs "src/${MODULE}.hs"
if [ -f src/Example.hs ]; then
# Here we prepare the exercise to be tested by Stack.
MODULE=`sed -n 's/ *module \+\([a-zA-Z0-9]\+\).*/\1/p' src/Example.hs`
mv src/Example.hs "src/${MODULE}.hs"
test_exercise
elif ! stat -t examples/*/ > /dev/null 2>&1; then
echo "No examples for ${exercise}!"
exit 1
else
for example in examples/*/ ; do
echo "testing ${example}"
rm -f src/*.hs
mv ${example}/*.hs src
mv ${example}/package.yaml .
test_exercise
done
fi
stack test ${SET_RESOLVER} `# Select the correct resolver. `\
--install-ghc `# Download GHC if not in cache.`\
--no-terminal `# Terminal detection is broken.`\
--pedantic `# Enable -Wall and -Werror. `
popd
done
10 changes: 10 additions & 0 deletions exercises/anagram/examples/list-string/Anagram.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Anagram (anagramsFor) where
import Data.List (sort)
import Data.Char (toLower)

anagramsFor :: String -> [String] -> [String]
anagramsFor word = filter (isAnagram . normalize)
where
normalize xs = let nxs = map toLower xs in (nxs, sort nxs)
(nw, sw) = normalize word
isAnagram (w, s) = nw /= w && sw == s
17 changes: 17 additions & 0 deletions exercises/anagram/examples/list-string/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: anagram

dependencies:
- base

library:
exposed-modules: Anagram
source-dirs: src
dependencies:

tests:
test:
main: Tests.hs
source-dirs: test
dependencies:
- anagram
- hspec
File renamed without changes.
20 changes: 20 additions & 0 deletions exercises/anagram/examples/set-text/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: anagram

dependencies:
- base

library:
exposed-modules: Anagram
source-dirs: src
dependencies:
- containers
- multiset
- text

tests:
test:
main: Tests.hs
source-dirs: test
dependencies:
- anagram
- hspec
3 changes: 0 additions & 3 deletions exercises/anagram/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ library:
dependencies:
# - foo # List here the packages you
# - bar # want to use in your solution.
- containers
- multiset
- text

tests:
test:
Expand Down

0 comments on commit 4082786

Please sign in to comment.