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

/A4-Relationen/RelationTest.rb

http://ss2011-prp1.googlecode.com/
Ruby | 245 lines | 193 code | 35 blank | 17 comment | 0 complexity | a41637c89b5bab77a61c36fcad6b2887 MD5 | raw file
  1. require 'test/unit'
  2. require "Relation"
  3. class RelationTest < Test::Unit::TestCase
  4. #setup - Fixture definieren
  5. def setup()
  6. a = Set.new [1,2,3,4,5]
  7. b = Set.new [6,7,8,9,10]
  8. c = a | [a,b]
  9. d = b | [11]
  10. @r_empty = Relation.new(a,a)
  11. @r_nothing_aa = Relation.new(a,a)
  12. @r_nothing_aa << Paar.new(1, 2) \
  13. << Paar.new(2, 1) \
  14. << Paar.new(3, 4) \
  15. << Paar.new(3, 3) \
  16. << Paar.new(2, 4)
  17. @r_nothing_ab = Relation.new(a,b)
  18. @r_nothing_ab << Paar.new(1, 6) \
  19. << Paar.new(1, 7) \
  20. << Paar.new(2, 7)
  21. @r_reflexiv = Relation.new(a,a)
  22. @r_reflexiv << Paar.new(1,1) \
  23. << Paar.new(2,2) \
  24. << Paar.new(3,3) \
  25. << Paar.new(4,4) \
  26. << Paar.new(5,5)
  27. @r_symmetrisch = Relation.new(a,a)
  28. @r_symmetrisch << Paar.new(2,5) \
  29. << Paar.new(5,2) \
  30. << Paar.new(1,3) \
  31. << Paar.new(3,1)
  32. @r_asymmetrisch = Relation.new(a,a)
  33. @r_asymmetrisch << Paar.new(1,3) \
  34. << Paar.new(2,4) \
  35. << Paar.new(2,5) \
  36. << Paar.new(5,3)
  37. @r_antisymmetrisch = Relation.new(a,a)
  38. @r_antisymmetrisch << Paar.new(2,2) \
  39. << Paar.new(3,3) \
  40. << Paar.new(5,5)
  41. @r_transitiv = Relation.new(a,a)
  42. @r_transitiv << Paar.new(1,2) \
  43. << Paar.new(2,3) \
  44. << Paar.new(1,3) \
  45. #<< Paar.new(4,5) \
  46. #<< Paar.new(5,1) \
  47. #<< Paar.new(4,1)
  48. @r_rechtseindeutig = Relation.new(a,b)
  49. @r_rechtseindeutig << Paar.new(1,7) \
  50. << Paar.new(2,9) \
  51. << Paar.new(3,6) \
  52. << Paar.new(4,6)
  53. @r_linkseindeutig = Relation.new(a,b)
  54. @r_linkseindeutig << Paar.new(1,7) \
  55. << Paar.new(2,9) \
  56. << Paar.new(3,6) \
  57. << Paar.new(3,10)
  58. @r_rechtstotal = Relation.new(a,d)
  59. @r_rechtstotal << Paar.new(1,10) \
  60. << Paar.new(2, 9) \
  61. << Paar.new(2, 8) \
  62. << Paar.new(3, 7) \
  63. << Paar.new(4, 6) \
  64. << Paar.new(4, 11)
  65. @r_linkstotal = Relation.new(a,b)
  66. @r_linkstotal << Paar.new(1, 6) \
  67. << Paar.new(2, 6) \
  68. << Paar.new(3, 7) \
  69. << Paar.new(4, 7) \
  70. << Paar.new(5, 8) \
  71. << Paar.new(5, 9)
  72. @r_abbildung = Relation.new(a,b)
  73. @r_abbildung << Paar.new(1, 10) \
  74. << Paar.new(2, 10) \
  75. << Paar.new(3, 9) \
  76. << Paar.new(4, 7) \
  77. << Paar.new(5, 8)
  78. @r_injektiv = Relation.new(a,d)
  79. @r_injektiv << Paar.new(1, 11) \
  80. << Paar.new(2, 9) \
  81. << Paar.new(3, 8) \
  82. << Paar.new(4, 7) \
  83. << Paar.new(5, 6)
  84. @r_surjektiv = Relation.new(c, d)
  85. @r_surjektiv << Paar.new(1, 6) \
  86. << Paar.new(2, 7) \
  87. << Paar.new(3, 7) \
  88. << Paar.new(4, 8) \
  89. << Paar.new(5, 9) \
  90. << Paar.new(a, 10) \
  91. << Paar.new(b, 11)
  92. @r_bijektiv = Relation.new(a,b)
  93. @r_bijektiv << Paar.new(1,10) \
  94. << Paar.new(2, 9) \
  95. << Paar.new(3, 8) \
  96. << Paar.new(4, 7) \
  97. << Paar.new(5, 6)
  98. end
  99. #Test für Reflexiv
  100. def test_ist_reflexiv()
  101. assert(@r_reflexiv.reflexiv?)
  102. assert(!@r_nothing_aa.reflexiv?)
  103. assert(!@r_nothing_ab.reflexiv?)
  104. assert(!@r_empty.reflexiv?)
  105. end
  106. #Test für Symmetrisch
  107. def test_ist_symmetrisch
  108. assert(@r_symmetrisch.symmetrisch?)
  109. assert(!@r_nothing_aa.symmetrisch?)
  110. assert(!@r_nothing_ab.symmetrisch?)
  111. assert(@r_empty.symmetrisch?)
  112. end
  113. #Test für Asymetrisch
  114. def test_ist_asymmetrisch
  115. assert(@r_asymmetrisch.asymmetrisch?)
  116. assert(!@r_nothing_aa.asymmetrisch?)
  117. assert(!@r_nothing_ab.asymmetrisch?)
  118. assert(@r_empty.asymmetrisch?)
  119. end
  120. #Test für Antisymmetrisch
  121. def test_ist_antisymmetrisch
  122. assert(@r_antisymmetrisch.anti_symmetrisch?)
  123. assert(!@r_nothing_aa.anti_symmetrisch?)
  124. assert(!@r_nothing_ab.anti_symmetrisch?)
  125. assert(@r_empty.anti_symmetrisch?)
  126. end
  127. #Test für Transitiv
  128. def test_ist_transitiv
  129. assert(@r_transitiv.transitiv?)
  130. assert(!@r_nothing_aa.transitiv?)
  131. assert(!@r_nothing_ab.transitiv?)
  132. assert(@r_empty.transitiv?)
  133. end
  134. #Test für Rechtseindeutig
  135. def test_ist_rechts_eindeutig
  136. assert(@r_rechtseindeutig.rechts_eindeutig?)
  137. assert(!@r_nothing_aa.rechts_eindeutig?)
  138. assert(!@r_nothing_ab.rechts_eindeutig?)
  139. assert(@r_empty.rechts_eindeutig?)
  140. end
  141. #Test für Linkseideutig
  142. def test_ist_links_eindeutig
  143. assert(@r_linkseindeutig.links_eindeutig?)
  144. assert(!@r_nothing_aa.links_eindeutig?)
  145. assert(!@r_nothing_ab.links_eindeutig?)
  146. assert(@r_empty.links_eindeutig?)
  147. end
  148. #Test für Rechtstotal
  149. def test_ist_rechts_total
  150. assert(@r_rechtstotal.rechts_total?)
  151. assert(!@r_nothing_aa.rechts_total?)
  152. assert(!@r_nothing_ab.rechts_total?)
  153. assert(@r_empty.rechts_total?)
  154. end
  155. #Test für Linkstotal
  156. def test_ist_linkstotal
  157. assert(@r_linkstotal.links_total?)
  158. assert(!@r_nothing_aa.links_total?)
  159. assert(!@r_nothing_ab.links_total?)
  160. assert(@r_empty.links_total?)
  161. end
  162. #Test für Abbildung
  163. def test_ist_abbildung
  164. assert(@r_abbildung.abbildung?)
  165. assert(!@r_nothing_aa.abbildung?)
  166. assert(!@r_nothing_ab.abbildung?)
  167. assert(@r_empty.abbildung?)
  168. end
  169. #Test für Injektiv
  170. def test_ist_injektiv
  171. assert(@r_injektiv.abbildung?)
  172. assert(@r_injektiv.injektiv?)
  173. assert(!@r_nothing_aa.abbildung?)
  174. assert(!@r_nothing_aa.injektiv?)
  175. assert(!@r_nothing_ab.abbildung?)
  176. assert(!@r_nothing_ab.injektiv?)
  177. assert(@r_empty.abbildung?)
  178. assert(@r_empty.injektiv?)
  179. end
  180. #Test für Surjeltiv
  181. def test_ist_surjektiv
  182. assert(@r_surjektiv.abbildung?)
  183. assert(@r_surjektiv.surjektiv?)
  184. assert(!@r_nothing_aa.abbildung?)
  185. assert(!@r_nothing_aa.surjektiv?)
  186. assert(!@r_nothing_ab.abbildung?)
  187. assert(!@r_nothing_ab.surjektiv?)
  188. assert(@r_empty.abbildung?)
  189. assert(@r_empty.surjektiv?)
  190. end
  191. #Test für Bijektiv
  192. def test_ist_bijektiv
  193. assert(@r_bijektiv.abbildung?)
  194. assert(@r_bijektiv.injektiv?)
  195. assert(@r_bijektiv.surjektiv?)
  196. assert(@r_bijektiv.bijektiv?)
  197. assert(!@r_nothing_aa.abbildung?)
  198. assert(!@r_nothing_aa.injektiv?)
  199. assert(!@r_nothing_aa.surjektiv?)
  200. assert(!@r_nothing_aa.bijektiv?)
  201. assert(!@r_nothing_ab.abbildung?)
  202. assert(!@r_nothing_ab.injektiv?)
  203. assert(!@r_nothing_ab.surjektiv?)
  204. assert(!@r_nothing_ab.bijektiv?)
  205. assert(@r_empty.abbildung?)
  206. assert(@r_empty.surjektiv?)
  207. assert(@r_empty.injektiv?)
  208. assert(@r_empty.bijektiv?)
  209. end
  210. end