class TestFramework_getEntities(TestCase): c1testSignature = ['c1'] d1testSignature = ['d1'] def setUp(self): f = Framework() c1sys = SimpleSystem(f) c1sys.setRunFunc(lambda e: None, TestFramework_getEntities.c1testSignature) f.registerSystem(c1sys) self.ckey = f.registerEntityFactory( [basicStateComponentBuilderFactory('c1', 'clear', 1)]) ef = f.getEntityFactory(self.ckey) f.registerEntities([ef.new(), ef.new(), ef.new()]) self.d1System = SimpleSystem(f) self.d1System.setRunFunc(lambda e: None, TestFramework_getEntities.d1testSignature) self.d1Factory = EntityFactory( [basicStateComponentBuilderFactory('d1', 'foo', 1)]) self.framework = f def test_getEntities_allEntitiesMatch(self): entities = self.framework.getEntities( TestFramework_getEntities.c1testSignature) AssertThat(entities).HasSize(3) def test_getEntities_oneEntityDoesNotMatch_noD1System(self): e = self.d1Factory.new() self.framework.registerEntity(e) entities = self.framework.getEntities( TestFramework_getEntities.c1testSignature) AssertThat(entities).HasSize(3) def test_getEntities_oneEntityDoesNotMatch(self): self.framework.registerSystem(self.d1System) d = self.d1Factory.new() self.framework.registerEntity(d) entities = self.framework.getEntities( TestFramework_getEntities.c1testSignature) AssertThat(entities).HasSize(3) def test_getEntities_noEntitiesMatch(self): entities = self.framework.getEntities( TestFramework_getEntities.d1testSignature) AssertThat(entities).HasSize(0)
class TestSimpleSystem_setRunFunc(TestCase): def setUp(self): self.testSystem = SimpleSystem(Parent()) def tRunFunc(self, e): pass def testSetRunFunc_entitySignatureSet(self): self.testSystem.setRunFunc(self.tRunFunc, ['aState']) AssertThat(self.testSystem.entitySignature).Contains('aState')
def setUp(self): f = Framework() c1sys = SimpleSystem(f) c1sys.setRunFunc(lambda e: None, TestFramework_registerEntity.testSignature) f.registerSystem(c1sys) self.ckey = f.registerEntityFactory( [basicStateComponentBuilderFactory('c1', 'clear', 1)]) self.dkey = f.registerEntityFactory( [basicStateComponentBuilderFactory('d1', 'foo', 3)]) self.framework = f
class TestSimpleSystemRun(TestCase): def setUp(self): self.testSystem = SimpleSystem(Parent()) self.testSystem.setRunFunc(self.tRunFunc, ['aState']) self.runs = 0 def tRunFunc(self, e): self.runs += 1 def test_systemHasARunFunc(self): AssertThat(self.testSystem._runFunc).IsEqualTo(self.tRunFunc) def test_runsOncePerEntityReturned(self): self.testSystem.getEntities() self.testSystem.run() AssertThat(self.runs).IsEqualTo(3)
def setUp(self): f = Framework() c1sys = SimpleSystem(f) c1sys.setRunFunc(lambda e: None, TestFramework_getEntities.c1testSignature) f.registerSystem(c1sys) self.ckey = f.registerEntityFactory( [basicStateComponentBuilderFactory('c1', 'clear', 1)]) ef = f.getEntityFactory(self.ckey) f.registerEntities([ef.new(), ef.new(), ef.new()]) self.d1System = SimpleSystem(f) self.d1System.setRunFunc(lambda e: None, TestFramework_getEntities.d1testSignature) self.d1Factory = EntityFactory( [basicStateComponentBuilderFactory('d1', 'foo', 1)]) self.framework = f
from math import * from simple_system import SimpleSystem from pid_controller import PIDController from signal_generator import PWMGenerator font_name = "Microsoft YaHei" matplotlib.rcParams['font.family']=font_name matplotlib.rcParams['axes.unicode_minus']=False # in case minus sign is shown as box t = [] y = [] x = [] t_step_len = 1e-2 sim_time = 5. system = SimpleSystem(t_step_len) controller = PIDController(200, 50, 500, 0.05, (-500,500)) pwm = PWMGenerator(t_step_len, 2, .5) ts = 0. desire_val = 0 while ts < sim_time: t += [ts] y += [system.observe()] x += [desire_val] observe = 0 sample_time = 50 for i in range(0,sample_time): observe += system.observe() observe /= float(sample_time)
def setUp(self): self.testSystem = SimpleSystem(Parent()) self.testSystem.setRunFunc(self.tRunFunc, ['aState']) self.runs = 0
def setUp(self): self.testSystem = SimpleSystem(Parent())