Skip to content

Commit

Permalink
Solve 'Check three and two' kata
Browse files Browse the repository at this point in the history
  • Loading branch information
borisskert committed Oct 15, 2024
1 parent 27c6697 commit de093f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ThreeAndTwo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module ThreeAndTwo (checkThreeAndTwo) where

-- https://www.codewars.com/kata/5a9e86705ee396d6be000091/train/haskell

import Data.List (sort)

checkThreeAndTwo :: [Char] -> Bool
checkThreeAndTwo xs
| a == b && b == c && c /= d && d == e = True
| a == b && b /= c && c == d && d == e = True
| otherwise = False
where
[a, b, c, d, e] = sort xs
13 changes: 13 additions & 0 deletions test/ThreeAndTwoSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module ThreeAndTwoSpec where

import Test.HUnit
import Test.Hspec
import ThreeAndTwo (checkThreeAndTwo)

spec :: Spec
spec = do
describe "Fixed Tests" $ do
it "Works on the examples" $ do
assertEqual "\"aaabb\"" True $ checkThreeAndTwo "aaabb"
assertEqual "\"abcbc\"" False $ checkThreeAndTwo "abcbc"
assertEqual "\"aaaaa\"" False $ checkThreeAndTwo "aaaaa"

0 comments on commit de093f8

Please sign in to comment.