Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/test_layer.py
blob: 43a6642c58aea8a896bd5aa466ab5c2e99754c86 (plain)
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
# coding: UTF-8
# Copyright 2009, 2010 Thomas Jourdan
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import unittest
import ka_factory
import model_random
import test_utils

class TestKandidLayer(unittest.TestCase):


    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_layer_factory(self):
        test_utils.neutral()
        layer_factory = ka_factory.get_factory('layer')
        keys = layer_factory.keys()
        self.assertTrue(layer_factory.count() >= 1)
        self.assertEqual(len(keys), layer_factory.count())
        for layer_key in keys:
            self.assertTrue(layer_factory.create(layer_key, '/') is not None)
        self.assertTrue(layer_factory.create_random([keys[0]], '/') is not None)
        
    def test_layer(self):
        model_random.set_flurry(9)
        test_utils.neutral()
        
        layer_factory = ka_factory.get_factory('layer')
        for layer_key in layer_factory.keys():
            layer1 = layer_factory.create(layer_key, '/')
            layer2 = layer1.copy()
            if not (layer2 == layer1):
                pass
            self.assertTrue(layer2 is not layer1)
            self.assertTrue(layer2 == layer1)
            layer1.randomize()
            layer1.swap_places()
            if layer2 == layer1:
                pass
            self.assertFalse(layer2 == layer1)
            layer3 = layer1.crossingover(layer2)
            self.assertTrue(layer3 is not layer1)
            self.assertTrue(layer3 is not layer2)
            layer4 = layer3.copy()
            layer4.mutate()
            for dummy in range(32):
                layer4.swap_places()
#            self.assertFalse(layer4 == layer3)