diff options
author | eugue <eug.sun@gmail.com> | 2011-02-12 20:09:41 -0500 |
---|---|---|
committer | eugue <eug.sun@gmail.com> | 2011-02-12 20:09:41 -0500 |
commit | 1e8b07e52c8b15b9bf4d9dc357f56bc8bbccc718 (patch) | |
tree | cb80c07023d8f4781d95e23f989976093f7c9d5d /tests | |
parent | 9e342041f05e88f8d1987a48fdcdc10c14ef095f (diff) | |
parent | a239c7accdc634459d2db014b8d8b6d5b78bab1b (diff) |
Merge branch 'master' of github.com:rcoh/SmootLight into behavior-factory
Diffstat (limited to 'tests')
-rw-r--r-- | tests/TestBQS.py | 40 | ||||
-rw-r--r-- | tests/TestConfigLoaders.py | 14 | ||||
-rw-r--r-- | tests/__init__.py | 3 |
3 files changed, 57 insertions, 0 deletions
diff --git a/tests/TestBQS.py b/tests/TestBQS.py new file mode 100644 index 0000000..7316c31 --- /dev/null +++ b/tests/TestBQS.py @@ -0,0 +1,40 @@ +import unittest +import util.BehaviorQuerySystem as bqs +from behaviors.ColorChangerBehavior import * +import util.Geo as geo +class TestBQS(unittest.TestCase): + def setUp(self): + bqs.initBQS() + b = ColorChangerBehavior({'Id': 'color','ColorList':[(255,0,0)]}) + c = ColorChangerBehavior({'Id': 'color2', 'ColorList':[(0,0,255)]}) + bqs.addBehavior(b) + bqs.addBehavior(c) + b.addInput({'Location':(3,4)}) + c.addInput({'Location':(5,12)}) + b.timeStep() + c.timeStep() + def tearDown(self): + bqs.initBQS() + def test_simple_query(self): + validQuery = lambda args:args['Color']==(255,0,0) + invalidQuery = lambda args:args['Color']==(254,0,0) + assert bqs.query(validQuery) == [{'Color':(255,0,0), 'Location':(3,4)}] + assert bqs.query(invalidQuery) == [] + def test_dist_query(self): + validDist = lambda args:geo.dist(args['Location'], (0,0)) <= 5 + invalidDist = lambda args:geo.dist(args['Location'], (0,0)) <= 2 + doubleDist = lambda args:geo.dist(args['Location'], (0,0)) <= 20 + + assert bqs.query(validDist) == [{'Color':(255,0,0), 'Location':(3,4)}] + assert bqs.query(invalidDist) == [] + assert bqs.query(doubleDist) == [{'Color':(255,0,0), 'Location':(3,4)}, {'Color':(0,0,255),\ + 'Location':(5,12)}] + def test_complex_queries(self): + + validQuery = lambda args:args['Color']==(255,0,0) + doubleDist = lambda args:geo.dist(args['Location'], (0,0)) <= 20 + + twoPartPredicate = lambda args:doubleDist(args) and validQuery(args) + assert bqs.query(twoPartPredicate) == [{'Color':(255,0,0), 'Location':(3,4)}] + assert bqs.query([validQuery, doubleDist]) == [{'Color':(255,0,0), 'Location':(3,4)}] + diff --git a/tests/TestConfigLoaders.py b/tests/TestConfigLoaders.py index c79bbf1..02c8865 100644 --- a/tests/TestConfigLoaders.py +++ b/tests/TestConfigLoaders.py @@ -29,6 +29,20 @@ class TestConfigLoaders(unittest.TestCase): result.write('tests/testdata/inheritanceTESTout.xml') assert filecmp.cmp('tests/testdata/inheritanceTESTout.xml',\ 'tests/testdata/inheritanceTRUTH.xml') + #Tests our fancy new XML Eval Function + def test_eval(self): + assert Config.attemptEval('5') == 5 + assert Config.attemptEval('{5:10, 12:15}') == {5:10, 12:15} + singleLayerLambda = Config.attemptEval('${Val}$*5') + assert singleLayerLambda({'Val':2}) == 10 + doubleLayerLambda = Config.attemptEval("${Val1}$*'${Val2}$'") + assert doubleLayerLambda({'Val1':3})({'Val2':7}) == 21 + conditional = Config.attemptEval("${Val1}$*5=='${Val2}$'") + assert conditional({'Val1':5})({'Val2':25}) == True + assert conditional({'Val1':5})({'Val2':26}) == False + + onlyDouble = Config.attemptEval("'${Val1}$'*'${Val2}$'") + assert onlyDouble({})({'Val1':3, 'Val2':7}) == 21 if __name__ == '__main__': unittest.main() diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..0365616 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,3 @@ +from TestComponentRegistry import TestComponentRegistry +from TestConfigLoaders import TestConfigLoaders +from TestBQS import TestBQS |