PageRenderTime 59ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/elm-stuff/packages/elm-lang/core/2.1.0/tests/Test/Basics.elm

https://gitlab.com/suyesh/elm-bingo
Elm | 152 lines | 150 code | 2 blank | 0 comment | 9 complexity | 8222c804b0d76d620f7d5d6d9667d5b7 MD5 | raw file
  1. module Test.Basics (tests) where
  2. import Basics exposing (..)
  3. import ElmTest.Assertion exposing (..)
  4. import ElmTest.Test exposing (..)
  5. tests : Test
  6. tests =
  7. let comparison =
  8. suite "Comparison"
  9. [ test "max" <| assertEqual 42 (max 32 42)
  10. , test "min" <| assertEqual 42 (min 91 42)
  11. , test "clamp low" <| assertEqual 10 (clamp 10 20 5)
  12. , test "clamp mid" <| assertEqual 15 (clamp 10 20 15)
  13. , test "clamp high" <| assertEqual 20 (clamp 10 20 25)
  14. , test "5 < 6" <| assertEqual True (5 < 6)
  15. , test "6 < 5" <| assertEqual False (6 < 5)
  16. , test "6 < 6" <| assertEqual False (6 < 6)
  17. , test "5 > 6" <| assertEqual False (5 > 6)
  18. , test "6 > 5" <| assertEqual True (6 > 5)
  19. , test "6 > 6" <| assertEqual False (6 > 6)
  20. , test "5 <= 6" <| assertEqual True (5 <= 6)
  21. , test "6 <= 5" <| assertEqual False (6 <= 5)
  22. , test "6 <= 6" <| assertEqual True (6 <= 6)
  23. , test "compare \"A\" \"B\"" <| assertEqual LT (compare "A" "B")
  24. , test "compare 'f' 'f'" <| assertEqual EQ (compare 'f' 'f')
  25. , test "compare (1, 2, 3, 4, 5, 6) (0, 1, 2, 3, 4, 5)" <| assertEqual GT (compare (1, 2, 3, 4, 5, 6) (0, 1, 2, 3, 4, 5))
  26. , test "compare ['a'] ['b']" <| assertEqual LT (compare ['a'] ['b'])
  27. , test "==" <| assertEqual True (sqrt == sqrt)
  28. , test "/=" <| assertEqual False (sqrt /= sqrt)
  29. ]
  30. toStringTests = suite "toString Tests"
  31. [ test "toString Int" <| assertEqual "42" (toString 42)
  32. , test "toString Float" <| assertEqual "42.52" (toString 42.52)
  33. , test "toString Char" <| assertEqual "'c'" (toString 'c')
  34. , test "toString Char single quote" <| assertEqual "'\\''" (toString '\'')
  35. , test "toString Char double quote" <| assertEqual "'\"'" (toString '"')
  36. , test "toString String single quote" <| assertEqual "\"not 'escaped'\"" (toString "not 'escaped'")
  37. , test "toString String double quote" <| assertEqual "\"are \\\"escaped\\\"\"" (toString "are \"escaped\"")
  38. ]
  39. trigTests = suite "Trigonometry Tests"
  40. [ test "radians 0" <| assertEqual 0 (radians 0)
  41. , test "radians positive" <| assertEqual 5 (radians 5)
  42. , test "radians negative" <| assertEqual -5 (radians -5)
  43. , test "degrees 0" <| assertEqual 0 (degrees 0)
  44. , test "degrees 90" <| assert (abs (1.57 - degrees 90) < 0.01) -- This should test to enough precision to know if anything's breaking
  45. , test "degrees -145" <| assert (abs (-2.53 - degrees -145) < 0.01) -- This should test to enough precision to know if anything's breaking
  46. , test "turns 0" <| assertEqual 0 (turns 0)
  47. , test "turns 8" <| assert (abs (50.26 - turns 8) < 0.01) -- This should test to enough precision to know if anything's breaking
  48. , test "turns -133" <| assert (abs (-835.66 - turns -133) < 0.01) -- This should test to enough precision to know if anything's breaking
  49. , test "fromPolar (0, 0)" <| assertEqual (0, 0) (fromPolar (0, 0))
  50. , test "fromPolar (1, 0)" <| assertEqual (1, 0) (fromPolar (1, 0))
  51. , test "fromPolar (0, 1)" <| assertEqual (0, 0) (fromPolar (0, 1))
  52. , test "fromPolar (1, 1)" <| assert (let (x, y) = fromPolar (1, 1) in 0.54 - x < 0.01 && 0.84 - y < 0.01)
  53. , test "toPolar (0, 0)" <| assertEqual (0, 0) (toPolar (0, 0))
  54. , test "toPolar (1, 0)" <| assertEqual (1, 0) (toPolar (1, 0))
  55. , test "toPolar (0, 1)" <| assert (let (r, theta) = toPolar (0, 1) in r == 1 && abs (1.57 - theta) < 0.01)
  56. , test "toPolar (1, 1)" <| assert (let (r, theta) = toPolar (1, 1) in abs (1.41 - r) < 0.01 && abs (0.78 - theta) < 0.01)
  57. , test "cos" <| assertEqual 1 (cos 0)
  58. , test "sin" <| assertEqual 0 (sin 0)
  59. , test "tan" <| assert (abs (12.67 - tan 17.2) < 0.01)
  60. , test "acos" <| assert (abs (3.14 - acos -1) < 0.01)
  61. , test "asin" <| assert (abs (0.30 - asin 0.3) < 0.01)
  62. , test "atan" <| assert (abs (1.57 - atan 4567.8) < 0.01)
  63. , test "atan2" <| assert (abs (1.55 - atan2 36 0.65) < 0.01)
  64. , test "pi" <| assert (abs (3.14 - pi) < 0.01)
  65. ]
  66. basicMathTests = suite "Basic Math Tests"
  67. [ test "add float" <| assertEqual 159 (155.6 + 3.4)
  68. , test "add int" <| assertEqual 17 ((round 10) + (round 7))
  69. , test "subtract float" <| assertEqual -6.3 (1 - 7.3)
  70. , test "subtract int" <| assertEqual 1130 ((round 9432) - (round 8302))
  71. , test "multiply float" <| assertEqual 432 (96 * 4.5)
  72. , test "multiply int" <| assertEqual 90 ((round 10) * (round 9))
  73. , test "divide float" <| assertEqual 13.175 (527 / 40)
  74. , test "divide int" <| assertEqual 23 (70 // 3)
  75. , test "7 `rem` 2" <| assertEqual 1 (7 `rem` 2)
  76. , test "-1 `rem` 4" <| assertEqual -1 (-1 `rem` 4)
  77. , test "7 % 2" <| assertEqual 1 (7 % 2)
  78. , test "-1 % 4" <| assertEqual 3 (-1 % 4)
  79. , test "3^2" <| assertEqual 9 (3^2)
  80. , test "sqrt" <| assertEqual 9 (sqrt 81)
  81. , test "negate 42" <| assertEqual -42 (negate 42)
  82. , test "negate -42" <| assertEqual 42 (negate -42)
  83. , test "negate 0" <| assertEqual 0 (negate 0)
  84. , test "abs -25" <| assertEqual 25 (abs -25)
  85. , test "abs 76" <| assertEqual 76 (abs 76)
  86. , test "logBase 10 100" <| assertEqual 2 (logBase 10 100)
  87. , test "logBase 2 256" <| assertEqual 8 (logBase 2 256)
  88. , test "e" <| assert (abs (2.72 - e) < 0.01)
  89. ]
  90. booleanTests = suite "Boolean Tests"
  91. [ test "False && False" <| assertEqual False (False && False)
  92. , test "False && True" <| assertEqual False (False && True)
  93. , test "True && False" <| assertEqual False (True && False)
  94. , test "True && True" <| assertEqual True (True && True)
  95. , test "False || False" <| assertEqual False (False || False)
  96. , test "False || True" <| assertEqual True (False || True)
  97. , test "True || False" <| assertEqual True (True || False)
  98. , test "True || True" <| assertEqual True (True || True)
  99. , test "xor False False" <| assertEqual False (xor False False)
  100. , test "xor False True" <| assertEqual True (xor False True)
  101. , test "xor True False" <| assertEqual True (xor True False)
  102. , test "xor True True" <| assertEqual False (xor True True)
  103. , test "not True" <| assertEqual False (not True)
  104. , test "not False" <| assertEqual True (not False)
  105. , test "otherwise" <| assertEqual True otherwise
  106. ]
  107. conversionTests = suite "Conversion Tests"
  108. [ test "round 0.6" <| assertEqual 1 (round 0.6)
  109. , test "round 0.4" <| assertEqual 0 (round 0.4)
  110. , test "round 0.5" <| assertEqual 1 (round 0.5)
  111. , test "truncate -2367.9267" <| assertEqual -2367 (truncate -2367.9267)
  112. , test "floor -2367.9267" <| assertEqual -2368 (floor -2367.9267)
  113. , test "ceiling 37.2" <| assertEqual 38 (ceiling 37.2)
  114. , test "toFloat 25" <| assertEqual 25 (toFloat 25)
  115. ]
  116. miscTests = suite "Miscellaneous Tests"
  117. [ test "isNaN (0/0)" <| assertEqual True (isNaN (0/0))
  118. , test "isNaN (sqrt -1)" <| assertEqual True (isNaN (sqrt -1))
  119. , test "isNaN (1/0)" <| assertEqual False (isNaN (1/0))
  120. , test "isNaN 1" <| assertEqual False (isNaN 1)
  121. , test "isInfinite (0/0)" <| assertEqual False (isInfinite (0/0))
  122. , test "isInfinite (sqrt -1)" <| assertEqual False (isInfinite (sqrt -1))
  123. , test "isInfinite (1/0)" <| assertEqual True (isInfinite (1/0))
  124. , test "isInfinite 1" <| assertEqual False (isInfinite 1)
  125. , test "\"hello\" ++ \"world\"" <| assertEqual "helloworld" ("hello" ++ "world")
  126. , test "[1, 1, 2] ++ [3, 5, 8]" <| assertEqual [1, 1, 2, 3, 5, 8] ([1, 1, 2] ++ [3, 5, 8])
  127. , test "fst (1, 2)" <| assertEqual 1 (fst (1, 2))
  128. , test "snd (1, 2)" <| assertEqual 2 (snd (1, 2))
  129. ]
  130. higherOrderTests = suite "Higher Order Helpers Tests"
  131. [ test "identity 'c'" <| assertEqual 'c' (identity 'c')
  132. , test "always 42 ()" <| assertEqual 42 (always 42 ())
  133. , test "<|" <| assertEqual 9 (identity <| 3 + 6)
  134. , test "|>" <| assertEqual 9 (3 + 6 |> identity)
  135. , test "<<" <| assertEqual True (not << xor True <| True)
  136. , test ">>" <| assertEqual True (True |> xor True >> not)
  137. , test "flip" <| assertEqual 10 ((flip (//)) 2 20)
  138. , test "curry" <| assertEqual 1 ((curry (\(a, b) -> a + b)) -5 6)
  139. , test "uncurry" <| assertEqual 1 ((uncurry (+)) (-5, 6))
  140. ]
  141. in
  142. suite "Basics"
  143. [ comparison
  144. , toStringTests
  145. , trigTests
  146. , basicMathTests
  147. , booleanTests
  148. , miscTests
  149. , higherOrderTests
  150. ]