Skip to content

Commit

Permalink
Fix tests for new code generation workflow (#51, #36)
Browse files Browse the repository at this point in the history
  • Loading branch information
a5kin committed Apr 7, 2019
1 parent de45173 commit 786727e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
19 changes: 11 additions & 8 deletions tests/core/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from xentica.core.properties import (
Property, IntegerProperty, ContainerProperty
)
from xentica.core.exceptions import XenticaException
from examples.game_of_life import GameOfLife
from examples.noisetv import NoiseTV, NoiseTVExperiment

Expand Down Expand Up @@ -39,15 +40,17 @@ def test_set(self):
"Wrong property's class.")

def test_unbound(self):
"""Test unbound ``Property`` default flags values."""
"""Test unbound ``Property`` behavior."""
prop = Property()
self.assertFalse(prop.declared,
"Unbound property declared")
self.assertTrue(prop.coords_declared,
"Unbound coords not declared")
cprop = ContainerProperty()
self.assertFalse(cprop.unpacked,
"Unbound property unpacked")
with self.assertRaises(XenticaException):
self.assertFalse(prop.declared,
"Unbound property declared")
self.assertTrue(prop.coords_declared,
"Unbound coords not declared")
with self.assertRaises(XenticaException):
cprop = ContainerProperty()
self.assertFalse(cprop.unpacked,
"Unbound property unpacked")

def test_container_values(self):
"""Test iteration over CA properties."""
Expand Down
19 changes: 16 additions & 3 deletions tests/core/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from xentica.core.variables import Variable, IntegerVariable
from xentica.core.exceptions import XenticaException
from xentica import core
from xentica import seeds


class InvertCA(core.CellularAutomaton):
Expand Down Expand Up @@ -32,6 +33,17 @@ def color(self):
"""Do nothing, no color processing required."""


class InvertExperiment(core.Experiment):
"""Test experiment for ``InvertCA``."""

size = (64, 36, )
seed = seeds.patterns.PrimordialSoup(
vals={
"state": seeds.random.RandInt(0, 1),
}
)


class TestVariable(unittest.TestCase):
"""Tests for ``Variable`` class and its children."""

Expand All @@ -50,15 +62,16 @@ def test_illegal_assign(self):
"""Test illegal assign to ``DeferredExpression``."""

with self.assertRaises(XenticaException):
# this class raises exception and thus unusable
class BrokenCA(InvertCA): # pylint: disable=unused-variable
class BrokenCA(InvertCA):
"""Class for broken expressions testing."""

def emit(self):
"""Try to assign to DeferredExpression"""
deferred_exp = 1 + self.intvar
deferred_exp = 1 + self.main.state
deferred_exp += 1

BrokenCA(InvertExperiment)

def test_no_init_val(self):
"""Test initialization without initial value."""
with self.assertRaises(XenticaException):
Expand Down

0 comments on commit 786727e

Please sign in to comment.