def test_number_open_sites_2_b(self): pg = Percolation(4) pg.open(1, 2) pg.open(1, 2) # already open, should not be counted twice pg.open(2, 2) expected, actual = 2, pg.number_of_open_sites() self.assertEqual(expected, actual)
def _simulate(self, n): """ Process independent percolation experiment """ p = Percolation(n) while True: p.open(random.randint(0, n - 1), random.randint(0, n - 1)) if p.is_percolates(): return p.number_of_open_sites() / (n * n)
def test_number_open_sites_2_a(self): pg = Percolation(4) pg.open(1, 2) pg.open(2, 2) expected, actual = 2, pg.number_of_open_sites() self.assertEqual(expected, actual)
def test_number_open_sites_0(self): pg = Percolation(4) expected, actual = 0, pg.number_of_open_sites() self.assertEqual(expected, actual)
def single_threshold(self): perc = Percolation(self.n) while not perc.percolates(): perc.open(row=randint(0, self.n - 1), col=randint(0, self.n - 1)) return perc.number_of_open_sites() / (self.n * self.n)