File: test_logbook.py

package info (click to toggle)
deap 1.0.1-3+deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,784 kB
  • ctags: 1,036
  • sloc: python: 6,905; cpp: 482; makefile: 80; sh: 8
file content (46 lines) | stat: -rw-r--r-- 1,767 bytes parent folder | download | duplicates (3)
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
import sys
import unittest

sys.path.append("..")

from deap import tools

class LogbookTest(unittest.TestCase):

    def setUp(self):
        self.logbook = tools.Logbook()
        print

    def test_multi_chapters(self):
        self.logbook.record(gen=0, evals=100, fitness={'obj 1' : {'avg' : 1.0, 'max' : 10},
                                          'avg' : 1.0, 'max' : 10},
                            length={'avg' : 1.0, 'max' : 30},
                            test={'avg' : 1.0, 'max' : 20})
        self.logbook.record(gen=0, evals=100, fitness={'obj 1' : {'avg' : 1.0, 'max' : 10},
                                          'avg' : 1.0, 'max' : 10},
                            length={'avg' : 1.0, 'max' : 30},
                            test={'avg' : 1.0, 'max' : 20})
        print(self.logbook.stream)


    def test_one_chapter(self):
        self.logbook.record(gen=0, evals=100, fitness={'avg' : 1.0, 'max' : 10})
        self.logbook.record(gen=0, evals=100, fitness={'avg' : 1.0, 'max' : 10})
        print(self.logbook.stream)

    def test_one_big_chapter(self):
        self.logbook.record(gen=0, evals=100, fitness={'obj 1' : {'avg' : 1.0, 'max' : 10}, 'obj 2' : {'avg' : 1.0, 'max' : 10}})
        self.logbook.record(gen=0, evals=100, fitness={'obj 1' : {'avg' : 1.0, 'max' : 10}, 'obj 2' : {'avg' : 1.0, 'max' : 10}})
        print(self.logbook.stream)

    def test_no_chapters(self):
        self.logbook.record(gen=0, evals=100, **{'avg' : 1.0, 'max' : 10})
        self.logbook.record(gen=0, evals=100, **{'avg' : 1.0, 'max' : 10})        
        print(self.logbook.stream)



if __name__ == "__main__":
    suite = unittest.TestLoader().loadTestsFromTestCase(LogbookTest)
    unittest.TextTestRunner(verbosity=2).run(suite)