Ejemplo n.º 1
0
def test_simulation():
    """Test that Simulation class can be used as required."""

    start, home, seed, n_sim = 10, 20, 12345, 5
    s = Simulation(start, home, seed)
    assert s.single_walk() > 0
    r = s.run_simulation(n_sim)
    assert len(r) == n_sim
    assert all(rs > 0 for rs in r)
Ejemplo n.º 2
0
        right_limit : int
            The right boundary  of walker movement
        """
        self.left_limit = left_limit
        self.right_limit = right_limit
        self.start = start
        self.home = home
        self.seed = seed

        super().__init__(start, home, seed)

    def single_walk(self):
        single_walker = BoundedWalker(self.start,
                                      self.home,
                                      self.left_limit,
                                      self.right_limit)
        while not single_walker.is_at_home():
            random.seed(self.seed)
            single_walker.move()
        return single_walker.get_steps()

    def run_simulation(self, num_walks):
        return super().run_simulation(num_walks)


if __name__ == '__main__':
    sim1 = BoundedSimulation(0, 10, 54321, -1, 11)
    print(sim1.run_simulation(10))
    sim2 = Simulation(0, 10, 5)
    print(sim2.run_simulation(10))