mirror of
https://github.com/gsi-upm/soil
synced 2025-10-15 19:32:21 +00:00
1.0pre4
This commit is contained in:
@@ -4,26 +4,6 @@ from soil import time, agents, environment
|
||||
|
||||
|
||||
class TestMain(TestCase):
|
||||
def test_cond(self):
|
||||
"""
|
||||
A condition should match a When if the concition is True
|
||||
"""
|
||||
|
||||
t = time.Cond(lambda t: True)
|
||||
f = time.Cond(lambda t: False)
|
||||
for i in range(10):
|
||||
w = time.When(i)
|
||||
assert w == t
|
||||
assert w is not f
|
||||
|
||||
def test_cond(self):
|
||||
"""
|
||||
Comparing a Cond to a Delta should always return False
|
||||
"""
|
||||
|
||||
c = time.Cond(lambda t: False)
|
||||
d = time.Delta(1)
|
||||
assert c is not d
|
||||
|
||||
def test_cond_env(self):
|
||||
""" """
|
||||
@@ -36,11 +16,12 @@ class TestMain(TestCase):
|
||||
|
||||
class CondAgent(agents.BaseAgent):
|
||||
def step(self):
|
||||
nonlocal done
|
||||
nonlocal done, times_started, times_asleep, times_awakened
|
||||
times_started.append(self.now)
|
||||
while True:
|
||||
times_asleep.append(self.now)
|
||||
yield time.Cond(lambda agent: agent.now >= 10, delta=2)
|
||||
while self.now < 10:
|
||||
yield self.delay(2)
|
||||
times_awakened.append(self.now)
|
||||
if self.now >= 10:
|
||||
break
|
||||
@@ -57,7 +38,6 @@ class TestMain(TestCase):
|
||||
assert times_started == [0]
|
||||
assert times_awakened == [10]
|
||||
assert done == [10]
|
||||
# The first time will produce the Cond.
|
||||
assert env.schedule.steps == 6
|
||||
assert len(times) == 6
|
||||
|
||||
@@ -65,11 +45,10 @@ class TestMain(TestCase):
|
||||
times.append(env.now)
|
||||
env.step()
|
||||
|
||||
assert times == [0, 2, 4, 6, 8, 10, 11]
|
||||
assert times == [0, 2, 4, 6, 8, 10, 11, 12]
|
||||
assert env.schedule.time == 13
|
||||
assert times_started == [0, 11]
|
||||
assert times_awakened == [10]
|
||||
assert done == [10]
|
||||
# Once more to yield the cond, another one to continue
|
||||
assert env.schedule.steps == 7
|
||||
assert len(times) == 7
|
||||
assert times_started == [0, 11, 12]
|
||||
assert times_awakened == [10, 11, 12]
|
||||
assert done == [10, 11, 12]
|
||||
assert env.schedule.steps == 8
|
||||
assert len(times) == 8
|
||||
|
Reference in New Issue
Block a user