Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
portaloffreedom committed Apr 4, 2019
1 parent 2c0f71b commit 5b80907
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 225 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ RUN apt-get install -y build-essential \
python \
python3-pip \
libyaml-cpp-dev \
xsltproc
xsltproc \
libcairo2-dev
RUN apt-get install -y libgazebo9-dev gazebo9
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

Expand Down
4 changes: 2 additions & 2 deletions pyrevolve/revolve_bot/brain/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class Brain(object):
def from_yaml(yaml_brain):
brain_type = yaml_brain['type']

if brain_type == 'neural-network':
if brain_type == pyrevolve.revolve_bot.brain.BrainNN.TYPE:
return pyrevolve.revolve_bot.brain.BrainNN.from_yaml(yaml_brain)
elif brain_type == 'rlpower-splines':
elif brain_type == pyrevolve.revolve_bot.brain.BrainRLPowerSplines.TYPE:
return pyrevolve.revolve_bot.brain.BrainRLPowerSplines.from_yaml(yaml_brain)
else:
return Brain()
Expand Down
2 changes: 2 additions & 0 deletions pyrevolve/revolve_bot/brain/brain_nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class BrainNN(Brain):
"""
Base class allowing for constructing neural network controller components in an overviewable manner
"""
TYPE = 'neural-network'

def __init__(self):
self.nodes = {}
Expand Down Expand Up @@ -51,6 +52,7 @@ def from_yaml(yaml_object):

def to_yaml(self):
yaml_dict_brain = OrderedDict()
yaml_dict_brain['type'] = self.TYPE

yaml_dict_neurons = OrderedDict()
for node in self.nodes:
Expand Down
5 changes: 4 additions & 1 deletion pyrevolve/revolve_bot/brain/rlpower_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@


class BrainRLPowerSplines(Brain):
TYPE = 'rlpower-splines'

@staticmethod
def from_yaml(yaml_object):
return BrainRLPowerSplines()

def to_yaml(self):
return {}
return {
'type': self.TYPE
}

def learner_sdf(self):
return xml.etree.ElementTree.Element('rv:learner', {'type': 'rlpower'})
Expand Down
133 changes: 0 additions & 133 deletions test_py/generate/test_body.py

This file was deleted.

80 changes: 0 additions & 80 deletions test_py/generate/test_neural_network.py

This file was deleted.

30 changes: 22 additions & 8 deletions test_py/generate/test_revolvebot.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
from __future__ import absolute_import

import unittest

from pyrevolve.revolve_bot import RevolveBot


class TestRevolveBot(unittest.TestCase):
"""
Basic tests for RobolveBot body and brain generation
"""
def revolve_bot_equal(self, roba, robb):
self._revolve_bot_body_equal(roba._body, robb._body)
self._revolve_bot_brain_equal(roba._brain, robb._brain)

def test_load_save_yaml(self):
"""
We load a YAML file and save it
"""
def _revolve_bot_body_equal(self, bodya, bodyb):
self.assertEqual(type(bodya), type(bodyb))

def _revolve_bot_brain_equal(self, braina, brainb):
self.assertEqual(type(braina), type(brainb))

def _proto_test(self, filename):

revolve_bot = RevolveBot()
revolve_bot.load_file(
path='experiments/examples/yaml/simple_robot.yaml',
path=filename,
conf_type='yaml'
)
revolve_bot.save_file(
Expand All @@ -30,4 +35,13 @@ def test_load_save_yaml(self):
conf_type='yaml'
)

self.assertEqual(revolve_bot, revolve_bot2)
self.revolve_bot_equal(revolve_bot, revolve_bot2)

def test_load_save_yaml(self):
"""
We load a YAML file and save it
"""
self._proto_test('experiments/examples/yaml/simple_robot.yaml')
self._proto_test('experiments/examples/yaml/spider.yaml')
self._proto_test('experiments/examples/yaml/gecko.yaml')
self._proto_test('experiments/examples/yaml/snake.yaml')

0 comments on commit 5b80907

Please sign in to comment.