File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ module MatrixCreation (getMatrix ) where
2+
3+ -- https://www.codewars.com/kata/5a34da5dee1aae516d00004a/train/haskell
4+
5+ getMatrix :: Int -> [[Int ]]
6+ getMatrix x = map makeRow [0 .. x - 1 ]
7+ where
8+ makeRow n = replicate n 0 ++ [1 ] ++ replicate (x - n - 1 ) 0
Original file line number Diff line number Diff line change 1+ module MatrixCreationSpec (spec ) where
2+
3+ import MatrixCreation (getMatrix )
4+ import Test.HUnit (assertEqual )
5+ import Test.Hspec
6+
7+ spec :: Spec
8+ spec = do
9+ it " example tests" $ do
10+ assertEqual " getMatrix 0" [] $ getMatrix 0
11+ assertEqual " getMatrix 1" [[1 ]] $ getMatrix 1
12+ assertEqual
13+ " getMatrix 2"
14+ [ [1 , 0 ],
15+ [0 , 1 ]
16+ ]
17+ $ getMatrix 2
18+ assertEqual
19+ " getMatrix 5"
20+ [ [1 , 0 , 0 , 0 , 0 ],
21+ [0 , 1 , 0 , 0 , 0 ],
22+ [0 , 0 , 1 , 0 , 0 ],
23+ [0 , 0 , 0 , 1 , 0 ],
24+ [0 , 0 , 0 , 0 , 1 ]
25+ ]
26+ $ getMatrix 5
You can’t perform that action at this time.
0 commit comments