public PercolationStats(int N, int T) { var rnd = new Random(); for (int k = 0; k < T; k++) { Console.WriteLine("Iteration {0}", k); _percolation = new Percolation(N); var countOpened = 0; do { var i = rnd.Next(1, N + 1); var j = rnd.Next(1, N + 1); if (_percolation.IsOpen(i, j)) continue; _percolation.Open(i, j); countOpened++; } while (!_percolation.Percolates()); Console.WriteLine("Count opened {0}", countOpened); _mean = (_mean + (double) countOpened/(N*N)) / 2; Console.WriteLine("mean {0}", _mean); } }
public void Given_opened_cell_below_when_open_should_connect_with_cell_below() { // arrange var percolation = new Percolation(2); // act percolation.Open(2, 2); percolation.Open(1, 2); // assert Assert.IsTrue(percolation.Connected(2, 4)); }
public void Given_opened_cell_on_the_right_when_open_should_connect_it_with_cell_right() { // arrange var percolation = new Percolation(5); // act percolation.Open(2, 3); percolation.Open(2, 2); // assert Assert.IsTrue(percolation.Connected(7, 8)); }
public void Given_path_from_up_to_down_percolates_should_return_true() { // arrange var percolation = new Percolation(5); percolation.Open(2,3); percolation.Open(3,3); percolation.Open(4,3); percolation.Open(5,3); percolation.Open(1,3); // act var actual = percolation.Percolates(); // assert Assert.IsTrue(actual); }
public void Open_cells_without_path_from_up_to_down_should_return_false() { // arrange var percolation = new Percolation(5); percolation.Open(2, 2); percolation.Open(3, 3); percolation.Open(4, 4); percolation.Open(5, 5); percolation.Open(1, 1); // act var actual = percolation.Percolates(); // assert Assert.IsFalse(actual); }
public void Open_cell_should_open_it() { // arrange var percolation = new Percolation(5); // act percolation.Open(2, 3); // assert Assert.IsTrue(percolation.IsOpen(2, 3)); }
public void Open_cell_on_the_top_shold_connect_it_with_root_above() { // arrange var percolation = new Percolation(2); // act percolation.Open(1, 1); // assert Assert.IsTrue(percolation.Connected(0, 1)); }
public void Open_cell_on_the_right_side_of_the_grid_shouldnt_connect_it_with_next_cell() { // arrange var percolation = new Percolation(5); // act percolation.Open(2, 1); percolation.Open(1, 5); // assert Assert.IsFalse(percolation.Connected(5, 6)); }
public void Open_cell_on_the_right_bottom_corner() { // arrange var percolation = new Percolation(5); // act percolation.Open(5, 5); // assert Assert.IsTrue(percolation.IsOpen(5, 5)); }
public void Open_cell_on_the_bottom_should_connect_it_with_root_below() { // arrange var percolation = new Percolation(2); // act percolation.Open(2, 2); // assert Assert.IsTrue(percolation.Connected(5, 4)); }