diff options
author | Nostalghia <b.vehikel@googlemail.com> | 2010-05-15 19:47:49 (GMT) |
---|---|---|
committer | Nostalghia <b.vehikel@googlemail.com> | 2010-05-15 19:47:49 (GMT) |
commit | 536028c401e4a4fa8aa8815edb661d3faf5f6dcc (patch) | |
tree | cbc8e324649d36828c04a82c16b96f5c94c3751e | |
parent | 5df6b4a80bc36ed657b85dc9d0f14defe59efdde (diff) |
Added a layer for rendering linear cellular automata
-rw-r--r-- | ep_colorgamut_analogous.py | 2 | ||||
-rw-r--r-- | ep_colorgamut_complement.py | 2 | ||||
-rw-r--r-- | ep_colorgamut_monchrome.py | 2 | ||||
-rw-r--r-- | ep_colorgamut_splitcomplementary.py | 2 | ||||
-rw-r--r-- | ep_colorgamut_triadic.py | 2 | ||||
-rw-r--r-- | ep_layer_filledspline.py | 4 | ||||
-rw-r--r-- | ep_layer_lca.py | 323 | ||||
-rw-r--r-- | ep_layer_markovchain.py | 4 | ||||
-rw-r--r-- | ep_layer_quadtree.py | 12 | ||||
-rw-r--r-- | ep_layer_voronoidiagram.py | 6 | ||||
-rw-r--r-- | ep_sampler_affineifs.py | 4 | ||||
-rw-r--r-- | model_constraintpool.py | 3 | ||||
-rw-r--r-- | test_buildingblocks.py | 6 | ||||
-rw-r--r-- | test_layer.py | 67 | ||||
-rw-r--r-- | test_model.py | 34 | ||||
-rw-r--r-- | test_suite.py | 2 |
16 files changed, 419 insertions, 56 deletions
diff --git a/ep_colorgamut_analogous.py b/ep_colorgamut_analogous.py index f88c795..e6b1a1b 100644 --- a/ep_colorgamut_analogous.py +++ b/ep_colorgamut_analogous.py @@ -63,7 +63,7 @@ class AnalogousColorGamut(model_locus.Locus): self.hue = model_random.cyclic_limit(self.hue + model_random.jitter(0.1)) self.range += model_random.jitter(0.1) - def mutate_color(self, color): + def adjust_color(self, color): """Adjust rgba value to mutated hue and similarity range. pre: len(color.rgba) == 4 """ diff --git a/ep_colorgamut_complement.py b/ep_colorgamut_complement.py index 720ef9f..344ca01 100644 --- a/ep_colorgamut_complement.py +++ b/ep_colorgamut_complement.py @@ -58,7 +58,7 @@ class ComplementaryColorGamut(model_locus.Locus): """ self.hue = model_random.cyclic_limit(self.hue + model_random.jitter(0.1)) - def mutate_color(self, color): + def adjust_color(self, color): """Adjust rgba value to mutated hue. pre: len(color.rgba) == 4 """ diff --git a/ep_colorgamut_monchrome.py b/ep_colorgamut_monchrome.py index 2dc4b9e..122b75b 100644 --- a/ep_colorgamut_monchrome.py +++ b/ep_colorgamut_monchrome.py @@ -55,7 +55,7 @@ class MonochromeColorGamut(model_locus.Locus): """ self.hue = model_random.cyclic_limit(self.hue + model_random.jitter(0.1)) - def mutate_color(self, color): + def adjust_color(self, color): """Adjust rgba value to mutated hue. pre: len(color.rgba) == 4 """ diff --git a/ep_colorgamut_splitcomplementary.py b/ep_colorgamut_splitcomplementary.py index 6efb5dc..3a8ba22 100644 --- a/ep_colorgamut_splitcomplementary.py +++ b/ep_colorgamut_splitcomplementary.py @@ -63,7 +63,7 @@ class SplitComplementaryColorGamut(model_locus.Locus): self.hue = model_random.cyclic_limit(self.hue + model_random.jitter(0.1)) self.hue_deviate += model_random.jitter(0.1) - def mutate_color(self, color): + def adjust_color(self, color): """Adjust rgba value to mutated hue and similarity range. pre: len(color.rgba) == 4 """ diff --git a/ep_colorgamut_triadic.py b/ep_colorgamut_triadic.py index 77025b5..af6c92a 100644 --- a/ep_colorgamut_triadic.py +++ b/ep_colorgamut_triadic.py @@ -62,7 +62,7 @@ class TriadicColorGamut(model_locus.Locus): """ self.hue = model_random.cyclic_limit(self.hue + model_random.jitter(0.1)) - def mutate_color(self, color): + def adjust_color(self, color): """Adjust rgba value to mutated hue. pre: len(color.rgba) == 4 """ diff --git a/ep_layer_filledspline.py b/ep_layer_filledspline.py index fb7dc11..bc4e24b 100644 --- a/ep_layer_filledspline.py +++ b/ep_layer_filledspline.py @@ -118,8 +118,8 @@ class FilledSpline(model_layer.Layer): line_width_constraint = cpool.get(self, 'line_width') roundness_constraint = cpool.get(self, 'roundness') self.colorgamut.mutate() - self.colorgamut.mutate_color(self.linecolor) - self.colorgamut.mutate_color(self.fillcolor) + self.colorgamut.adjust_color(self.linecolor) + self.colorgamut.adjust_color(self.fillcolor) self.line_width = model_random.jitter_constrained(self.line_width, line_width_constraint) self.roundness = model_random.jitter_constrained(self.roundness, roundness_constraint) self.center.mutate() diff --git a/ep_layer_lca.py b/ep_layer_lca.py new file mode 100644 index 0000000..6eee5a0 --- /dev/null +++ b/ep_layer_lca.py @@ -0,0 +1,323 @@ +# 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 random +import ka_debug +import model_random +import ka_factory +import model_locus +import model_layer +import model_constraintpool +from gettext import gettext as _ + +SIZE_CONSTRAINT = 'sizeconstraint' +STATES_CONSTRAINT = 'statesconstraint' +COLORGAMUTTYPE_CONSTRAINT = 'colorgamuttypeconstraint' +LEFT_NEIGHBORS_CONSTRAINT = 'leftneighborsconstraint' +RIGHT_NEIGHBORS_CONSTRAINT = 'rightneighborsconstraint' + +class LcaLayer(model_layer.Layer): + """LcaLayer + inv: len(self.cell_colors) > 0 + inv: self.size >= 1 + inv: self.states >= 1 + inv: self.left_neighbors >= 0 + inv: self.right_neighbors >= 0 + """ + + cdef = [{'bind' : SIZE_CONSTRAINT, + 'name' : 'Number of cells.', + 'domain': model_constraintpool.INT_RANGE, + 'min' : 2, 'max': 32}, + {'bind' : STATES_CONSTRAINT, + 'name' : 'Number of states.', + 'domain': model_constraintpool.INT_RANGE, + 'min' : 2, 'max': 6}, + {'bind' : LEFT_NEIGHBORS_CONSTRAINT, + 'name' : 'Number of left neighbors.', + 'domain': model_constraintpool.INT_RANGE, + 'min' : 0, 'max': 2}, + {'bind' : RIGHT_NEIGHBORS_CONSTRAINT, + 'name' : 'Number of right neighbors.', + 'domain': model_constraintpool.INT_RANGE, + 'min' : 0, 'max': 2}, + {'bind' : COLORGAMUTTYPE_CONSTRAINT, + 'name' : 'Permitted color gamut', + 'domain': model_constraintpool.STRING_M_OF_N, + 'enum' : ka_factory.get_factory('colorgamut').keys()}, + ] + + def __init__(self, trunk): + """linear cellular automata layer constructor + post: len(self.cell_colors) == self.states + """ + super(LcaLayer, self).__init__(trunk) + self.size = 2 + self.states = 2 + self.left_neighbors = 1 + self.right_neighbors = 1 + rsize = self.states ** (self.left_neighbors + 1 + self.right_neighbors) + self.rules = [0 for dummy in xrange(rsize)] + self.sequence_ordering = 0.25 + + colorgamut_factory = ka_factory.get_factory('colorgamut') + colorgamut_key = colorgamut_factory.keys()[0] + self.colorgamut = colorgamut_factory.create(colorgamut_key, self.path) + self.cell_colors = [self.colorgamut.get_randomized_color(self.path), + self.colorgamut.get_randomized_color(self.path), ] + + def dot(self): + result = "" + anchor = ka_debug.dot_id(self) + ' -> ' + for ref in [self.colorgamut, ]: + result += ka_debug.dot_ref(anchor, ref) + for ref in self.cell_colors: + result += ka_debug.dot_ref(anchor, ref) + return result + + def __eq__(self, other): + """Equality """ + equal = isinstance(other, LcaLayer) \ + and model_layer.Layer.__eq__(self, other) \ + and self.size == other.size \ + and self.states == other.states \ + and self.left_neighbors == other.left_neighbors \ + and self.right_neighbors == other.right_neighbors \ + and self.sequence_ordering == other.sequence_ordering \ + and len(self.cell_colors) == len(other.cell_colors) + if equal: + for index, rule in enumerate(self.rules): + equal = equal and rule == other.rules[index] + if equal: + for index, site_color in enumerate(self.cell_colors): + equal = equal and site_color == other.cell_colors[index] + return equal + + def randomize(self): + """Randomize the layers components. + post: len(self.cell_colors) == self.states + post: forall(self.rules, lambda f: 0 <= f < self.states) + """ + super(LcaLayer, self).randomize() + cpool = model_constraintpool.ConstraintPool.get_pool() + size_constraint = cpool.get(self, SIZE_CONSTRAINT) + self.size = model_random.randint_constrained(size_constraint) + + states_constraint = cpool.get(self, STATES_CONSTRAINT) + self.states = model_random.randint_constrained(states_constraint) + + left_neighbors_constraint = cpool.get(self, LEFT_NEIGHBORS_CONSTRAINT) + self.left_neighbors = model_random.randint_constrained(left_neighbors_constraint) + right_neighbors_constraint = cpool.get(self, RIGHT_NEIGHBORS_CONSTRAINT) + self.right_neighbors = model_random.randint_constrained(right_neighbors_constraint) + + self.rules = [random.randrange(0, self.states) \ + for dummy in xrange(self.get_numberof_rules())] + self.sequence_ordering = random.uniform(0.0, 1.0) + + colorgamut_factory = ka_factory.get_factory('colorgamut') + colorgamuttype_constraint = cpool.get(self, COLORGAMUTTYPE_CONSTRAINT) + self.colorgamut = colorgamut_factory.create_random(colorgamuttype_constraint, + self.path) + self.colorgamut.randomize() + + self.cell_colors = [] + for dummy in range(self.states): + site_color = self.colorgamut.get_randomized_color(self.path) + self.cell_colors.append(site_color) + + def fill_sequence(self, lca_state): + """ + post: forall(lca_state, lambda f: 0 <= f < self.states) + """ + seq_random = random.Random() + seq_random.seed(self.random_seed) + state = lca_state[0] = seq_random.randrange(0, self.states) + for index in xrange(1, len(lca_state)): + if seq_random.uniform(0.0, 1.0) < self.sequence_ordering: + state = seq_random.randrange(0, self.states) + lca_state[index] = state + + + def _patch_rulesize(self): + rsize = self.get_numberof_rules() + if len(self.rules) > rsize: + self.rules = self.rules[:rsize] + while len(self.rules) < rsize: + self.rules.append(random.randrange(0, self.states)) + + self.rules = [x % self.states for x in self.rules] + + + def _patch_colorsize(self): + if len(self.cell_colors) > self.states: + self.cell_colors = self.cell_colors[:self.states] + while len(self.cell_colors) < self.states: + site_color = self.colorgamut.get_randomized_color(self.path) + self.cell_colors.append(site_color) + + def mutate(self): + """Make small random changes to the layers components. + post: len(self.cell_colors) == self.states + post: forall(self.rules, lambda f: 0 <= f < self.states) + """ + super(LcaLayer, self).mutate() + cpool = model_constraintpool.ConstraintPool.get_pool() + size_constraint = cpool.get(self, SIZE_CONSTRAINT) + self.size = model_random.jitter_discret_constrained( + self.size, size_constraint) + states_constraint = cpool.get(self, STATES_CONSTRAINT) + self.states = model_random.jitter_discret_constrained( + self.states, states_constraint) + + left_neighbors_constraint = cpool.get(self, LEFT_NEIGHBORS_CONSTRAINT) + self.left_neighbors = model_random.randint_constrained(left_neighbors_constraint) + self.left_neighbors = model_random.jitter_discret_constrained( + self.left_neighbors, left_neighbors_constraint) + right_neighbors_constraint = cpool.get(self, RIGHT_NEIGHBORS_CONSTRAINT) + self.right_neighbors = model_random.jitter_discret_constrained( + self.right_neighbors, right_neighbors_constraint) + self._patch_rulesize() + + self._patch_colorsize() + self.colorgamut.mutate() + for cix in range(len(self.cell_colors)): + self.colorgamut.adjust_color(self.cell_colors[cix]) + + def swap_places(self): + """Shuffle similar components.""" + model_random.swap_places(self.cell_colors) + model_random.swap_places(self.rules) + + def crossingover(self, other): + """ + pre: isinstance(other, LcaLayer) + pre: isinstance(self, LcaLayer) + # check for distinct references, needs to copy content, not references + post: __return__ is not self + post: __return__ is not other + post: model_locus.unique_check(__return__, self, other) == '' + post: len(__return__.cell_colors) == __return__.states + post: len(__return__.rules) == __return__.get_numberof_rules() + post: forall(__return__.rules, lambda f: 0 <= f < __return__.states) + """ + new_one = LcaLayer(self.get_trunk()) + cross_sequence = self.crossingover_base(new_one, other, 6) + new_one.size = self.size if cross_sequence[0] \ + else other.size + new_one.states = self.states if cross_sequence[1] \ + else other.states + #TODO rules an die geƤnderten states anpassen. + + new_one.left_neighbors = self.left_neighbors if cross_sequence[2] \ + else other.left_neighbors + new_one.right_neighbors = self.right_neighbors if cross_sequence[3] \ + else other.right_neighbors + new_one.colorgamut = other.colorgamut.copy() if cross_sequence[4] \ + else self.colorgamut.copy() + new_one.sequence_ordering = self.sequence_ordering if cross_sequence[5] \ + else other.sequence_ordering + + new_one.rules = model_random.crossingover_nativeelement_list(self.rules, \ + other.rules) + new_one._patch_rulesize() + + new_one.cell_colors = model_random.crossingover_list(self.cell_colors, + other.cell_colors) + new_one._patch_colorsize() + for cix in range(len(new_one.cell_colors)): + new_one.colorgamut.adjust_color(new_one.cell_colors[cix]) + + return new_one + + def render(self, task, ctx, width, height): + """ + pre: ctx is not None + pre: width > 0 + pre: height > 0 + pre: width == height + """ + self.begin_render(ctx, width, height) + lca_state = [0 for dummy in xrange(self.size)] + lca_nextstate = [0 for dummy in xrange(self.size)] + self.fill_sequence(lca_state) + delta = 1.0 / self.size + next_state = 0 + x_pos = -0.5 + for dummy in xrange(self.size): + y_pos = -0.5 + for col in xrange(self.size): + ruleNumber = self.get_rule_index(lca_state, col) + next_state = lca_nextstate[col] = self.rules[ruleNumber] + rgba = self.cell_colors[next_state % len(self.cell_colors)].rgba + ctx.set_source_rgba(rgba[0], rgba[1], rgba[2], rgba[3]) + ctx.rectangle(x_pos, y_pos, delta, delta) + ctx.fill() + y_pos += delta + x_pos += delta + # copy temporary cell array to actual cell array + lca_state = lca_nextstate[:] + + def get_numberof_rules(self): + """ + post: __return__ >= 1 + """ + return self.states ** (self.left_neighbors + 1 + self.right_neighbors) + + def get_rule_index(self, lca_state, index): + """ + pre: len(lca_state) == self.size + pre: 0 <= index < self.size + post: 0 <= __return__ < len(self.rules) + """ + ruleNumber = 0 + for nx in xrange(index - self.left_neighbors, + index + self.right_neighbors + 1): + ruleNumber *= self.states + ruleNumber += lca_state[nx % len(lca_state)] + return ruleNumber + + def explain(self, formater): + formater.begin_list(_('Layer ') + self.__class__.__name__) + super(LcaLayer, self).explain(formater) + formater.text_item(_('Number of states: ') + str(self.states)) + formater.text_item(_('Number of left neighbors: ') + str(self.left_neighbors)) + formater.text_item(_('Number of right neighbors: ') + str(self.right_neighbors)) + formater.text_item(_('Number of cells: ') + str(self.size)) + formater.text_item(_('Stability of sequence ordering: ') + str(self.size)) + self.colorgamut.explain(formater) + formater.color_array(self.cell_colors, _('Cell colors:')) + formater.end_list() + + def copy(self): + """The linear cellular automata layers copy constructor. + # check for distinct references, needs to copy content, not references + post: __return__ is not self + pre: len(self.cell_colors) == self.states + post: len(__return__.cell_colors) == __return__.states + """ + new_one = LcaLayer(self.get_trunk()) + self.copy_base(new_one) + new_one.cell_colors = model_random.copy_list(self.cell_colors) + new_one.states = self.states + new_one.rules = self.rules[:] + new_one.size = self.size + new_one.left_neighbors = self.left_neighbors + new_one.right_neighbors = self.right_neighbors + new_one.sequence_ordering = self.sequence_ordering + new_one.colorgamut = self.colorgamut.copy() + return new_one diff --git a/ep_layer_markovchain.py b/ep_layer_markovchain.py index 94597ab..6818d6b 100644 --- a/ep_layer_markovchain.py +++ b/ep_layer_markovchain.py @@ -209,7 +209,7 @@ class MarkovChainLayer(model_layer.Layer): self.stamp.mutate() self.colorgamut.mutate() for cix in range(len(self.cell_colors)): - self.colorgamut.mutate_color(self.cell_colors[cix]) + self.colorgamut.adjust_color(self.cell_colors[cix]) def swap_places(self): """Shuffle similar components.""" @@ -255,7 +255,7 @@ class MarkovChainLayer(model_layer.Layer): new_one.cell_colors = [] for cix in range(len(cell_colors)): color = cell_colors[cix].copy() - new_one.colorgamut.mutate_color(color) + new_one.colorgamut.adjust_color(color) new_one.cell_colors.append(color) return new_one diff --git a/ep_layer_quadtree.py b/ep_layer_quadtree.py index ad92776..43b8d9b 100644 --- a/ep_layer_quadtree.py +++ b/ep_layer_quadtree.py @@ -77,7 +77,9 @@ class QuadTreeLayer(model_layer.Layer): equal = isinstance(other, QuadTreeLayer) \ and model_layer.Layer.__eq__(self, other) \ and len(self.tile_colors) == len(other.tile_colors) \ - and self.propability == other.propability + and self.depth == other.depth \ + and self.propability == other.propability \ + and self.border_width == other.border_width if equal: for index, site_color in enumerate(self.tile_colors): equal = equal and site_color == other.tile_colors[index] @@ -127,7 +129,7 @@ class QuadTreeLayer(model_layer.Layer): model_random.mutate_list(self.tile_colors, depth_constraint, new_site_color) for cix in range(len(self.tile_colors)): - self.colorgamut.mutate_color(self.tile_colors[cix]) + self.colorgamut.adjust_color(self.tile_colors[cix]) def swap_places(self): """Shuffle similar components.""" @@ -143,7 +145,7 @@ class QuadTreeLayer(model_layer.Layer): post: model_locus.unique_check(__return__, self, other) == '' """ new_one = QuadTreeLayer(self.get_trunk()) - cross_sequence = model_random.crossing_sequence(4) + cross_sequence = self.crossingover_base(new_one, other, 4) new_one.depth = self.depth if cross_sequence[0] \ else other.depth new_one.propability = self.propability if cross_sequence[1] \ @@ -155,7 +157,7 @@ class QuadTreeLayer(model_layer.Layer): new_one.tile_colors = model_random.crossingover_list(self.tile_colors, other.tile_colors) for cix in range(len(new_one.tile_colors)): - new_one.colorgamut.mutate_color(new_one.tile_colors[cix]) + new_one.colorgamut.adjust_color(new_one.tile_colors[cix]) return new_one @@ -202,7 +204,7 @@ class QuadTreeLayer(model_layer.Layer): formater.text_item(_('Width of the surrounding border: ') + str(self.border_width)) self.colorgamut.explain(formater) - formater.color_array(self.tile_colors, _('site colors:')) + formater.color_array(self.tile_colors, _('Site colors:')) formater.end_list() def copy(self): diff --git a/ep_layer_voronoidiagram.py b/ep_layer_voronoidiagram.py index 643dd4c..1b59222 100644 --- a/ep_layer_voronoidiagram.py +++ b/ep_layer_voronoidiagram.py @@ -159,7 +159,7 @@ class VoronoiDiagramLayer(model_layer.Layer): model_random.mutate_list(self.sites_color, number_of_constraint, new_site_color) for cix in range(len(self.sites_color)): - self.colorgamut.mutate_color(self.sites_color[cix]) + self.colorgamut.adjust_color(self.sites_color[cix]) order_constraint = cpool.get(self, ORDER_CONSTRAINT) self.order = model_random.jitter_constrained(self.order, order_constraint) @@ -184,7 +184,7 @@ class VoronoiDiagramLayer(model_layer.Layer): post: model_locus.unique_check(__return__, self, other) == '' """ new_one = VoronoiDiagramLayer(self.get_trunk()) - cross_sequence = model_random.crossing_sequence(2) + cross_sequence = self.crossingover_base(new_one, other, 2) new_one.sites_point = model_random.crossingover_list(self.sites_point, other.sites_point) @@ -193,7 +193,7 @@ class VoronoiDiagramLayer(model_layer.Layer): new_one.sites_color = model_random.crossingover_list(self.sites_color, other.sites_color) for cix in range(len(new_one.sites_color)): - new_one.colorgamut.mutate_color(new_one.sites_color[cix]) + new_one.colorgamut.adjust_color(new_one.sites_color[cix]) new_one.order = self.order if cross_sequence[1] else other.order new_one.sampler = model_random.crossingover_elem(self.sampler, diff --git a/ep_sampler_affineifs.py b/ep_sampler_affineifs.py index 2707948..b88d312 100644 --- a/ep_sampler_affineifs.py +++ b/ep_sampler_affineifs.py @@ -453,7 +453,7 @@ class AffineIfsSampler(model_allele.Allele): post: len(__return__) == 3 """ head = _('Affine iterated function system sampler') - details = _('iterations=%d, transformations=%d symmetry=%d, Dn=%d') + details = _('iterations=%d, transformations=%d symmetry=%d, Dn=%d: ') details = details % (self.orbits, self.num_transformations, self.symmetry, self.Dn) return ka_utils.explain_points(head + ' ' + details + ': ', @@ -470,7 +470,7 @@ class AffineIfsSampler(model_allele.Allele): new_one.random_seed = self.random_seed new_one.orbits = self.orbits new_one.num_transformations = self.num_transformations - new_one.pol_transf = [[.0, .0, .0, .0, .0, .0]] * MAX_TRANSFORMATIONS + new_one.pol_transf = [[.0, .0, .0, .0, .5, .5]] * MAX_TRANSFORMATIONS for pix in range(self.num_transformations): new_one.pol_transf[pix] = self.pol_transf[pix][:] new_one.symmetry = self.symmetry diff --git a/model_constraintpool.py b/model_constraintpool.py index b1b047e..5d0ef06 100644 --- a/model_constraintpool.py +++ b/model_constraintpool.py @@ -135,6 +135,9 @@ class ConstraintPool(object): #TODO read from persistence, provide an constraint editor # self.set('*', 'samplertypeconstraint', ['affineifs',]) # self.set('*', 'layertypeconstraint', ['filledspline', ]) +# self.set('*', 'layertypeconstraint', ['lca', ]) +# self.set('*', 'modifiertypeconstraint', ['flip', ]) +# self.set('*', 'modifiertypeconstraint', ['border', ]) # self.set('*', 'stamptypeconstraint', ['filledcyclic',]) # self.set('*', 'layertypeconstraint', ['markovchain', ]) # self.set('*', 'samplertypeconstraint', ['randomwalk',]) diff --git a/test_buildingblocks.py b/test_buildingblocks.py index 7392ac0..5c0b84b 100644 --- a/test_buildingblocks.py +++ b/test_buildingblocks.py @@ -58,7 +58,7 @@ class TestKandidBuildingBlocks(unittest.TestCase): mm3.swap_places() diff = not (mm3 == mm1 and mm3 == mm2) if not diff: - print mm1, mm2, mm3 + print 'no difference found:', key, mm1, mm2, mm3 self.assertTrue(diff) def test_sampler(self): @@ -96,7 +96,7 @@ class TestKandidBuildingBlocks(unittest.TestCase): mm1.randomize() mm1.mutate() color1 = mm1.get_randomized_color('/') - mm1.mutate_color(color1) + mm1.adjust_color(color1) self.assertEqual(4, len(color1.rgba)) class DummyFormater: def __init__(self): @@ -221,7 +221,7 @@ class TestKandidBuildingBlocks(unittest.TestCase): eql = eql and color4 == color3 self.assertFalse(eql) - def test_0ifs(self): + def test_ifs(self): model_random.set_flurry(9) ifs = AffineIfsSampler('/') ifs.randomize() diff --git a/test_layer.py b/test_layer.py new file mode 100644 index 0000000..43a6642 --- /dev/null +++ b/test_layer.py @@ -0,0 +1,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) + diff --git a/test_model.py b/test_model.py index fa2b320..b345d6a 100644 --- a/test_model.py +++ b/test_model.py @@ -279,40 +279,6 @@ class TestKandidModel(unittest.TestCase): self.assertFalse(model_population.contains_reference(poo, moderate)) self.assertFalse(model_population.contains_reference(poo, good)) - 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() - 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) - def test_protozoon(self): model_random.set_flurry(9) test_utils.neutral() diff --git a/test_suite.py b/test_suite.py index 3b9ed47..b9e3cf8 100644 --- a/test_suite.py +++ b/test_suite.py @@ -26,12 +26,14 @@ import test_buildingblocks import test_status import test_exporter import test_model +import test_layer ka_debug.info('starting TestSuite') ka_debug.err('testing error message channel.') gtk.gdk.threads_init() alltests = unittest.TestSuite((\ unittest.makeSuite(test_buildingblocks.TestKandidBuildingBlocks), \ + unittest.makeSuite(test_layer.TestKandidLayer), \ unittest.makeSuite(test_exporter.TestKandidExporter), \ unittest.makeSuite(test_status.TestKandidStatus), \ unittest.makeSuite(test_history.TestKandidHistory), \ |