/A4-Relationen/RelationTest.rb
Ruby | 245 lines | 193 code | 35 blank | 17 comment | 0 complexity | a41637c89b5bab77a61c36fcad6b2887 MD5 | raw file
- require 'test/unit'
- require "Relation"
- class RelationTest < Test::Unit::TestCase
-
- #setup - Fixture definieren
- def setup()
- a = Set.new [1,2,3,4,5]
- b = Set.new [6,7,8,9,10]
- c = a | [a,b]
- d = b | [11]
-
- @r_empty = Relation.new(a,a)
-
- @r_nothing_aa = Relation.new(a,a)
- @r_nothing_aa << Paar.new(1, 2) \
- << Paar.new(2, 1) \
- << Paar.new(3, 4) \
- << Paar.new(3, 3) \
- << Paar.new(2, 4)
-
- @r_nothing_ab = Relation.new(a,b)
- @r_nothing_ab << Paar.new(1, 6) \
- << Paar.new(1, 7) \
- << Paar.new(2, 7)
-
- @r_reflexiv = Relation.new(a,a)
- @r_reflexiv << Paar.new(1,1) \
- << Paar.new(2,2) \
- << Paar.new(3,3) \
- << Paar.new(4,4) \
- << Paar.new(5,5)
-
- @r_symmetrisch = Relation.new(a,a)
- @r_symmetrisch << Paar.new(2,5) \
- << Paar.new(5,2) \
- << Paar.new(1,3) \
- << Paar.new(3,1)
-
- @r_asymmetrisch = Relation.new(a,a)
- @r_asymmetrisch << Paar.new(1,3) \
- << Paar.new(2,4) \
- << Paar.new(2,5) \
- << Paar.new(5,3)
-
- @r_antisymmetrisch = Relation.new(a,a)
- @r_antisymmetrisch << Paar.new(2,2) \
- << Paar.new(3,3) \
- << Paar.new(5,5)
-
- @r_transitiv = Relation.new(a,a)
- @r_transitiv << Paar.new(1,2) \
- << Paar.new(2,3) \
- << Paar.new(1,3) \
- #<< Paar.new(4,5) \
- #<< Paar.new(5,1) \
- #<< Paar.new(4,1)
-
- @r_rechtseindeutig = Relation.new(a,b)
- @r_rechtseindeutig << Paar.new(1,7) \
- << Paar.new(2,9) \
- << Paar.new(3,6) \
- << Paar.new(4,6)
-
- @r_linkseindeutig = Relation.new(a,b)
- @r_linkseindeutig << Paar.new(1,7) \
- << Paar.new(2,9) \
- << Paar.new(3,6) \
- << Paar.new(3,10)
-
- @r_rechtstotal = Relation.new(a,d)
- @r_rechtstotal << Paar.new(1,10) \
- << Paar.new(2, 9) \
- << Paar.new(2, 8) \
- << Paar.new(3, 7) \
- << Paar.new(4, 6) \
- << Paar.new(4, 11)
-
- @r_linkstotal = Relation.new(a,b)
- @r_linkstotal << Paar.new(1, 6) \
- << Paar.new(2, 6) \
- << Paar.new(3, 7) \
- << Paar.new(4, 7) \
- << Paar.new(5, 8) \
- << Paar.new(5, 9)
-
- @r_abbildung = Relation.new(a,b)
- @r_abbildung << Paar.new(1, 10) \
- << Paar.new(2, 10) \
- << Paar.new(3, 9) \
- << Paar.new(4, 7) \
- << Paar.new(5, 8)
- @r_injektiv = Relation.new(a,d)
- @r_injektiv << Paar.new(1, 11) \
- << Paar.new(2, 9) \
- << Paar.new(3, 8) \
- << Paar.new(4, 7) \
- << Paar.new(5, 6)
-
-
- @r_surjektiv = Relation.new(c, d)
- @r_surjektiv << Paar.new(1, 6) \
- << Paar.new(2, 7) \
- << Paar.new(3, 7) \
- << Paar.new(4, 8) \
- << Paar.new(5, 9) \
- << Paar.new(a, 10) \
- << Paar.new(b, 11)
-
- @r_bijektiv = Relation.new(a,b)
- @r_bijektiv << Paar.new(1,10) \
- << Paar.new(2, 9) \
- << Paar.new(3, 8) \
- << Paar.new(4, 7) \
- << Paar.new(5, 6)
-
- end
-
- #Test für Reflexiv
- def test_ist_reflexiv()
- assert(@r_reflexiv.reflexiv?)
- assert(!@r_nothing_aa.reflexiv?)
- assert(!@r_nothing_ab.reflexiv?)
- assert(!@r_empty.reflexiv?)
- end
-
- #Test für Symmetrisch
- def test_ist_symmetrisch
- assert(@r_symmetrisch.symmetrisch?)
- assert(!@r_nothing_aa.symmetrisch?)
- assert(!@r_nothing_ab.symmetrisch?)
- assert(@r_empty.symmetrisch?)
- end
-
- #Test für Asymetrisch
- def test_ist_asymmetrisch
- assert(@r_asymmetrisch.asymmetrisch?)
- assert(!@r_nothing_aa.asymmetrisch?)
- assert(!@r_nothing_ab.asymmetrisch?)
- assert(@r_empty.asymmetrisch?)
- end
-
- #Test für Antisymmetrisch
- def test_ist_antisymmetrisch
- assert(@r_antisymmetrisch.anti_symmetrisch?)
- assert(!@r_nothing_aa.anti_symmetrisch?)
- assert(!@r_nothing_ab.anti_symmetrisch?)
- assert(@r_empty.anti_symmetrisch?)
- end
-
- #Test für Transitiv
- def test_ist_transitiv
- assert(@r_transitiv.transitiv?)
- assert(!@r_nothing_aa.transitiv?)
- assert(!@r_nothing_ab.transitiv?)
- assert(@r_empty.transitiv?)
- end
-
- #Test für Rechtseindeutig
- def test_ist_rechts_eindeutig
- assert(@r_rechtseindeutig.rechts_eindeutig?)
- assert(!@r_nothing_aa.rechts_eindeutig?)
- assert(!@r_nothing_ab.rechts_eindeutig?)
- assert(@r_empty.rechts_eindeutig?)
- end
-
- #Test für Linkseideutig
- def test_ist_links_eindeutig
- assert(@r_linkseindeutig.links_eindeutig?)
- assert(!@r_nothing_aa.links_eindeutig?)
- assert(!@r_nothing_ab.links_eindeutig?)
- assert(@r_empty.links_eindeutig?)
- end
-
- #Test für Rechtstotal
- def test_ist_rechts_total
- assert(@r_rechtstotal.rechts_total?)
- assert(!@r_nothing_aa.rechts_total?)
- assert(!@r_nothing_ab.rechts_total?)
- assert(@r_empty.rechts_total?)
- end
-
- #Test für Linkstotal
- def test_ist_linkstotal
- assert(@r_linkstotal.links_total?)
- assert(!@r_nothing_aa.links_total?)
- assert(!@r_nothing_ab.links_total?)
- assert(@r_empty.links_total?)
- end
-
- #Test für Abbildung
- def test_ist_abbildung
- assert(@r_abbildung.abbildung?)
- assert(!@r_nothing_aa.abbildung?)
- assert(!@r_nothing_ab.abbildung?)
- assert(@r_empty.abbildung?)
- end
-
- #Test für Injektiv
- def test_ist_injektiv
- assert(@r_injektiv.abbildung?)
- assert(@r_injektiv.injektiv?)
- assert(!@r_nothing_aa.abbildung?)
- assert(!@r_nothing_aa.injektiv?)
- assert(!@r_nothing_ab.abbildung?)
- assert(!@r_nothing_ab.injektiv?)
- assert(@r_empty.abbildung?)
- assert(@r_empty.injektiv?)
- end
-
- #Test für Surjeltiv
- def test_ist_surjektiv
- assert(@r_surjektiv.abbildung?)
- assert(@r_surjektiv.surjektiv?)
- assert(!@r_nothing_aa.abbildung?)
- assert(!@r_nothing_aa.surjektiv?)
- assert(!@r_nothing_ab.abbildung?)
- assert(!@r_nothing_ab.surjektiv?)
- assert(@r_empty.abbildung?)
- assert(@r_empty.surjektiv?)
- end
-
- #Test für Bijektiv
- def test_ist_bijektiv
- assert(@r_bijektiv.abbildung?)
- assert(@r_bijektiv.injektiv?)
- assert(@r_bijektiv.surjektiv?)
- assert(@r_bijektiv.bijektiv?)
- assert(!@r_nothing_aa.abbildung?)
- assert(!@r_nothing_aa.injektiv?)
- assert(!@r_nothing_aa.surjektiv?)
- assert(!@r_nothing_aa.bijektiv?)
- assert(!@r_nothing_ab.abbildung?)
- assert(!@r_nothing_ab.injektiv?)
- assert(!@r_nothing_ab.surjektiv?)
- assert(!@r_nothing_ab.bijektiv?)
- assert(@r_empty.abbildung?)
- assert(@r_empty.surjektiv?)
- assert(@r_empty.injektiv?)
- assert(@r_empty.bijektiv?)
- end
-
-
- end