PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/inst/tests/test-is-a-type.R

https://bitbucket.org/fmark/assertive
R | 202 lines | 156 code | 46 blank | 0 comment | 0 complexity | 360083cf0603fc3b9d49805239cd1abd MD5 | raw file
  1. test.is_a_bool.true.returns_true <- function()
  2. {
  3. checkTrue(is_a_bool(TRUE))
  4. }
  5. test.is_a_bool.false.returns_true <- function()
  6. {
  7. checkTrue(is_a_bool(FALSE))
  8. }
  9. test.is_a_bool.na.returns_true <- function()
  10. {
  11. checkTrue(is_a_bool(NA))
  12. }
  13. test.is_a_bool.a_vector.returns_false <- function()
  14. {
  15. checkTrue(!is_a_bool(c(TRUE, FALSE)))
  16. }
  17. test.is_a_bool.empty_logical.returns_false <- function()
  18. {
  19. checkTrue(!is_a_bool(logical()))
  20. }
  21. test.is_a_complex.1i.returns_true <- function()
  22. {
  23. checkTrue(is_a_complex(1i))
  24. }
  25. test.is_a_complex.1.returns_false <- function()
  26. {
  27. checkTrue(!is_a_complex(1L))
  28. }
  29. test.is_a_complex.1_plus_0i.returns_true <- function()
  30. {
  31. checkTrue(is_a_complex(1 + 0i))
  32. }
  33. test.is_a_complex.na_complex_.returns_true <- function()
  34. {
  35. checkTrue(is_a_complex(NA_complex_))
  36. }
  37. test.is_a_complex.a_vector.returns_false <- function()
  38. {
  39. checkTrue(!is_a_complex(c(1i, 2i)))
  40. }
  41. test.is_a_complex.empty_complex.returns_false <- function()
  42. {
  43. checkTrue(!is_a_number(complex()))
  44. }
  45. test.is_a_non_empty_string.non_empty_string.returns_true <- function()
  46. {
  47. checkTrue(is_a_non_empty_string("foo"))
  48. }
  49. test.is_a_non_empty_string.na_character_.returns_true <- function()
  50. {
  51. checkTrue(is_a_non_empty_string(NA_character_))
  52. }
  53. test.is_a_non_empty_string.empty_string.returns_false <- function()
  54. {
  55. checkTrue(!is_a_non_empty_string(""))
  56. }
  57. test.is_a_non_empty_string.empty_character.returns_false <- function()
  58. {
  59. checkTrue(!is_a_non_empty_string(character()))
  60. }
  61. test.is_a_number.1.returns_true <- function()
  62. {
  63. checkTrue(is_a_number(1))
  64. }
  65. test.is_a_number.1L.returns_true <- function()
  66. {
  67. checkTrue(is_a_number(1L))
  68. }
  69. test.is_a_number.Inf.returns_true <- function()
  70. {
  71. checkTrue(is_a_number(Inf))
  72. }
  73. test.is_a_number.na_real_.returns_true <- function()
  74. {
  75. checkTrue(is_a_number(NA_real_))
  76. }
  77. test.is_a_number.a_vector.returns_false <- function()
  78. {
  79. checkTrue(!is_a_number(1:10))
  80. }
  81. test.is_a_number.empty_numeric.returns_false <- function()
  82. {
  83. checkTrue(!is_a_number(numeric()))
  84. }
  85. test.is_a_raw.a_raw.returns_true <- function()
  86. {
  87. checkTrue(is_a_raw(as.raw(1)))
  88. }
  89. test.is_a_raw.a_vector.returns_false <- function()
  90. {
  91. checkTrue(!is_a_raw(as.raw(1:10)))
  92. }
  93. test.is_a_raw.empty_raw.returns_false <- function()
  94. {
  95. checkTrue(!is_a_raw(raw()))
  96. }
  97. test.is_a_string.foo.returns_true <- function()
  98. {
  99. checkTrue(is_a_string("foo"))
  100. }
  101. test.is_a_string.na.returns_true <- function()
  102. {
  103. checkTrue(is_a_string(NA_character_))
  104. }
  105. test.is_a_string.empty_string.returns_true <- function()
  106. {
  107. checkTrue(is_a_string(""))
  108. }
  109. test.is_a_string.a_vector.returns_false <- function()
  110. {
  111. checkTrue(!is_a_string(c("foo", "bar")))
  112. }
  113. test.is_a_string.empty_character.returns_false <- function()
  114. {
  115. checkTrue(!is_a_string(character()))
  116. }
  117. test.is_an_empty_string.empty_string.returns_true <- function()
  118. {
  119. checkTrue(is_an_empty_string(""))
  120. }
  121. test.is_an_empty_string.non_empty_string.returns_false <- function()
  122. {
  123. checkTrue(!is_an_empty_string("foo"))
  124. }
  125. test.is_an_empty_string.empty_character.returns_false <- function()
  126. {
  127. checkTrue(!is_an_empty_string(character()))
  128. }
  129. test.is_an_empty_string.na_character_.returns_false <- function()
  130. {
  131. checkTrue(!is_an_empty_string(NA_character_))
  132. }
  133. test.is_an_integer.1L.returns_true <- function()
  134. {
  135. checkTrue(is_an_integer(1L))
  136. }
  137. test.is_an_integer.minus_1L.returns_true <- function()
  138. {
  139. checkTrue(is_an_integer(-1L))
  140. }
  141. test.is_an_integer.na.returns_true <- function()
  142. {
  143. checkTrue(is_an_integer(NA_integer_))
  144. }
  145. test.is_an_integer.floating_point.returns_false <- function()
  146. {
  147. checkTrue(!is_an_integer(1))
  148. }
  149. test.is_an_integer.a_vector.returns_false <- function()
  150. {
  151. checkTrue(!is_an_integer(1L:2L))
  152. }
  153. test.is_an_integer.empty_integer.returns_false <- function()
  154. {
  155. checkTrue(!is_an_integer(integer()))
  156. }