Skip to content

Instantly share code, notes, and snippets.

@alogic0
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alogic0/c002ce8586d82b126b41 to your computer and use it in GitHub Desktop.
Save alogic0/c002ce8586d82b126b41 to your computer and use it in GitHub Desktop.
NPTEL Haskell 2015, HUnit test for Assignment 2
module Nptel_ass2_test_hunit
where
import Test.HUnit
import Test.Hspec
import Test.Hspec.Contrib.HUnit
-- Name of your file with the assignment
-- without trailing .hs
import Nptel_ass2
main :: IO Counts
main = runTestTT tests
mainHspec :: IO ()
mainHspec = hspec $ fromHUnitTest tests
tests :: Test
tests =
TestList [
TestLabel "ramanujan" (
TestList [
TestLabel "1" (TestCase (assertEqual "ramanujan 1" (ramanujan 1) 1729))
,TestLabel "2" (TestCase (assertEqual "ramanujan 2" (ramanujan 2) 4104))
,TestLabel "3" (TestCase (assertEqual "ramanujan 3" (ramanujan 3) 13832))
,TestLabel "4" (TestCase (assertEqual "ramanujan 4" (ramanujan 4) 20683))
{- ,TestLabel "5" (TestCase (assertEqual "ramanujan 5" (ramanujan 5) 32832))
,TestLabel "6" (TestCase (assertEqual "ramanujan 6" (ramanujan 6) 39312))
,TestLabel "7" (TestCase (assertEqual "ramanujan 7" (ramanujan 7) 40033))
,TestLabel "8" (TestCase (assertEqual "ramanujan 8" (ramanujan 8) 46683))
-} ]
),
TestLabel "is_matrix" (
TestList [
TestLabel "1" (TestCase (assertBool "empty matrix" (not $ is_matrix []))),
TestLabel "2" (TestCase (assertBool "empty rows/columns" (not $ is_matrix [[], [], []]))),
TestLabel "3" (TestCase (assertBool "valid 2 x 2 matrix" (is_matrix [[ 2, 3 ], [ 4, 5 ], [ 6, 7 ]]))),
TestLabel "4" (TestCase (assertBool "valid 1 x 6 matrix" (is_matrix [[ 2, 3, 4, 5, 6, 7 ]])))
]
),
TestLabel "is_square_matrix" (
TestList [
TestLabel "1" (TestCase (assertBool "empty matrix" (not $ is_square_matrix []))),
TestLabel "2" (TestCase (assertBool "empty rows/columns" (not $ is_square_matrix [[], [], []]))),
TestLabel "3" (TestCase (assertBool "valid 1 x 1 matrix" (is_square_matrix [[ 1 ]]))),
TestLabel "4" (TestCase (assertBool "valid 3 x 3 matrix" (is_square_matrix [[ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]])))
]
),
TestLabel "addable" (
TestList [
TestLabel "1" (TestCase (assertBool "2 x 2 is incompatible to 2 x 3 matrix" (not $ addable [[ 1, 2 ], [ 3, 4 ]] [[ 1, 2, 3 ], [ 4, 5, 6 ]]))),
TestLabel "2" (TestCase (assertBool "valid 2 x 2 matrices" (addable [[ 1, 2 ], [ 3, 4 ]] [[ 5, 6 ], [ 7, 8 ]]))),
TestLabel "3" (TestCase (assertBool "valid 1 x 4 matrices" (addable [[ 1, 2, 3, 4 ]] [[ 5, 6, 7, 8 ]])))
]
),
TestLabel "add_matrix" (
TestList [
TestLabel "1" (TestCase (assertEqual "incorrect result" (add_matrix [[ 1, 2 ], [ 3, 4 ]] [[ 5, 6 ], [ 7, 8 ]]) [[ 6, 8], [ 10, 12 ]])),
TestLabel "2" (TestCase (assertEqual "incorrect result" (add_matrix [[ 1, 2, 3, 4 ]] [[ 5, 6, 7, 8 ]]) [[ 6, 8, 10, 12 ]]))
]
),
TestLabel "multiplicable" (
TestList [
TestLabel "1" (TestCase (assertBool "2 x 3 incompatible w/ 2 x 2 matrix" (not $ multiplyable [[ 1, 2, 3 ], [ 4, 5, 6 ]] [[ 1, 2 ], [ 3, 4 ]]))),
TestLabel "2" (TestCase (assertBool "2 x 2 compatible w/ 2 x 3 matrix" (multiplyable [[ 1, 2 ], [ 3, 4 ]] [[ 1, 2, 3 ], [ 4, 5, 6 ]]))),
TestLabel "3" (TestCase (assertBool "2 x 2 compatible w/ 2 x 3 matrix" (multiplyable [[ 1, 2, 3 ], [ 4, 5, 6 ]] [[ 1, 2 ], [ 3, 4], [ 5, 6 ]])))
]
),
TestLabel "multiply_matrix" (
TestList [
TestLabel "1" (TestCase (assertEqual "incorrect result" (multiply_matrix [[ 1, 2 ], [ 3, 4 ]] [[ 1, 2, 3 ], [ 4, 5, 6 ]]) [[ 9, 12, 15 ], [ 19, 26, 33 ]])),
TestLabel "2" (TestCase (assertEqual "incorrect result" (multiply_matrix [[ 1, 2, 3 ], [ 4, 5, 6 ]] [[ 1, 2 ], [ 3, 4], [ 5, 6 ]]) [[ 22, 28 ], [ 49, 64 ]]))
]
)
]
@alogic0
Copy link
Author

alogic0 commented Aug 19, 2015

Author of this is Catull (Carlo Dapor)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment