-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndividualTest.rb
71 lines (56 loc) · 1.41 KB
/
IndividualTest.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# encoding: UTF-8
#
# Evolution.ruby
# (Konsolenanwendung in Ruby)
#
# String-Evolution in Ruby mit Kreuzung und Mutation
# erstellt von Conrad Kernrot 4-2015
# github@conradhenke.de
#
require "./Individual.rb"
require "test/unit"
class TestIndividual < Test::Unit::TestCase
Genpool = [*'0'..'9', *'a'..'z', *'A'..'Z']
def test_initalisation
i = Individual.new("IndividualGENE",Genpool,"TargetGENE")
assert("IndividualGENE" == i.gene)
end
def test_rating
testGene = ["GENE1", "GENA", "GENEN"] # alle verlieren
testGene.each{ |t|
loose = Individual.new(t,Genpool,"GENE")
assert(loose.rating > 0)
}
win = Individual.new("TargetGENE",Genpool,"TargetGENE")
assert(win.rating == 0)
end
def test_mutation
i = Individual.new("IndividualGENE",Genpool,"TargetGENE")
i.mutate
assert(i.gene != "IndividualGENE")
assert(i.gene != "")
end
def test_mutationAdd
i = Individual.new("IndividualGENE",Genpool,"TargetGENE")
oldLength = i.gene.length
i.mutateAdd
assert(i.gene.length>oldLength)
end
def test_mutationAdd
i = Individual.new("IndividualGENE",Genpool,"TargetGENE")
oldLength = i.gene.length
i.mutateRem
assert(i.gene.length<oldLength)
end
def test_mutationChange
i = Individual.new("IndividualGENE",Genpool,"TargetGENE")
oldGene = i.gene.dup
i.mutateChange
assert(i.gene!=oldGene)
assert(i.gene.length==oldGene.length)
end
def setup
end
def teardown
end
end