File: test_logbook.py

package info (click to toggle)
deap 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 3,500 kB
  • sloc: python: 8,558; ansic: 1,054; cpp: 592; makefile: 94; sh: 5
file content (44 lines) | stat: -rw-r--r-- 1,759 bytes parent folder | download
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
import sys
import unittest

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},
                                          'obj 2' : {'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},
                                          'obj 2' : {'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)