Skip to content

Commit

Permalink
Add docstrings for tests.core.base (#23, #27)
Browse files Browse the repository at this point in the history
  • Loading branch information
a5kin committed Dec 6, 2017
1 parent 1b09cdc commit 55fde27
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/core/test_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Tests for ``xentica.core.base`` module."""
import unittest
import os
import binascii
Expand All @@ -14,11 +15,18 @@


class TestCellularAutomaton(unittest.TestCase):
"""Tests for ``CellularAutomaton`` class."""

num_steps = 1000
num_runs = 3

def test_single_ca(self):
"""
Test single CA model.
Run vanilla GoL for 1000 steps and make sure board checksum is correct.
"""
for i in range(self.num_runs):
ca = GameOfLife(GOLExperiment)
for j in range(self.num_steps):
Expand All @@ -27,6 +35,7 @@ def test_single_ca(self):
self.assertEqual(3106211755, checksum, "Wrong field checksum.")

def test_multiple_ca(self):
"""Test two CellularAutomaton instances could be ran in parallel."""
ca1 = GameOfLife(GOLExperiment)
ca2 = GameOfLife(GOLExperiment)
for j in range(self.num_steps):
Expand All @@ -38,6 +47,12 @@ def test_multiple_ca(self):
self.assertEqual(3106211755, checksum, "Wrong field checksum (CA #2).")

def test_render(self):
"""
Test basic rendering working.
Run vanilla GoL for 1000 steps and check resulting image's checksum.
"""
experiment = GOLExperiment
experiment.zoom = 1
ca = GameOfLife(experiment)
Expand All @@ -49,6 +64,7 @@ def test_render(self):
"Wrong image checksum.")

def test_pause(self):
"""Test CA is not evolving when paused."""
ca = GameOfLife(GOLExperiment)
ca.paused = False
checksum_before = binascii.crc32(ca.cells_gpu.get()[:ca.cells_num])
Expand All @@ -64,6 +80,7 @@ def test_pause(self):
"CA is not paused.")

def test_save_load(self):
"""Save CA and test it's state is identical after load."""
ca1 = GameOfLife(GOLExperiment)
for i in range(self.num_steps // 2):
ca1.step()
Expand All @@ -77,6 +94,7 @@ def test_save_load(self):
os.remove("test.ca")

def test_load_random(self):
"""Save CA and test it's RNG state is identical after load."""
ca1 = GameOfLife(GOLExperiment)
ca1.save("test.ca")
ca2 = GameOfLife(GOLExperiment)
Expand All @@ -90,17 +108,20 @@ def test_load_random(self):
os.remove("test.ca")

def test_no_topology(self):
"""Test exception is raised if ``Topology`` is not declared."""
with self.assertRaises(XenticaException):
class NoTopologyCA(CellularAutomaton):
pass

def test_empty_topology(self):
"""Test exception is raised if ``Topology`` is empty."""
with self.assertRaises(XenticaException):
class NoLatticeCA(CellularAutomaton):
class Topology:
pass

def test_static_border(self):
"""Test exception is raised if ``Topology`` is empty."""
ca = GameOfLifeStatic(GOLExperiment)
for j in range(self.num_steps):
ca.step()
Expand All @@ -110,13 +131,15 @@ def test_static_border(self):
self.assertEqual(1660369157, checksum, "Wrong field checksum.")

def test_multiple_properties(self):
"""Test CA with multiple properties works correctly."""
ca = GameOfLifeColor(GOLExperimentColor)
for j in range(self.num_steps):
ca.step()
checksum = binascii.crc32(ca.cells_gpu.get()[:ca.cells_num])
self.assertEqual(3492385663, checksum, "Wrong field checksum.")

def test_multidimensional(self):
"""Test 6-dimensional CA works correctly."""
class GOLExperiment6DLite(GOLExperiment2):
size = (64, 36, 3, 3, 3, 3)
ca = GameOfLife6D(GOLExperiment6DLite)
Expand All @@ -126,6 +149,7 @@ class GOLExperiment6DLite(GOLExperiment2):
self.assertEqual(1854122883, checksum, "Wrong field checksum.")

def test_cell_width(self):
"""Test CA with 16 bit/cell works correctly."""
class GameOfLifeInt(GameOfLife):
state = IntegerProperty(max_val=2 ** 16 - 1)
ca = GameOfLifeInt(GOLExperiment)
Expand Down

0 comments on commit 55fde27

Please sign in to comment.