diff --git a/details.md b/details.md index f739260..fd0b1f1 100644 --- a/details.md +++ b/details.md @@ -23,7 +23,7 @@ and I wanted to avoid requiring this of anyone else, wishing to run/test this pr ## Execute - ./prj/script/venv/bin/python -m src.main + ./prj/venv/bin/python -m src.main ...perc_value = 0.5967 ...perc_value = 0.582025 @@ -39,7 +39,7 @@ and I wanted to avoid requiring this of anyone else, wishing to run/test this pr ![alt example](supp/img/perc_50_200x200.png) ## Test - ex_auto> ./prj/script/venv/bin/pytest test/ + ex_auto> ./prj/venv/bin/pytest test/ ============================= test session starts ============================== collecting ... collected 8 items @@ -63,13 +63,15 @@ and I wanted to avoid requiring this of anyone else, wishing to run/test this pr ## Check Typing - > ./prj/script/venv/bin/mypy --check-untyped-defs -p test -p src + > ./prj/venv/bin/mypy --check-untyped-defs -p test -p src + + Success: no issues found in 18 source files - Success: no issues found in 17 source files - +## Formatting + `> ./prj/venv/bin/black --skip-string-normalization --line-length=120 src test [--check [--diff]]` + - `--check` -dont actually modify files. list files which would be modified + - `--diff` show actual changes in files diff --git a/prj/pip_reqs/pip_reqs_base.txt b/prj/pip_reqs/pip_reqs_base.txt index b6902e7..aa4013f 100644 --- a/prj/pip_reqs/pip_reqs_base.txt +++ b/prj/pip_reqs/pip_reqs_base.txt @@ -7,6 +7,7 @@ pytest # quality control mypy pylint +black numpy matplotlib diff --git a/src/_cell.py b/src/_cell.py index 6166b84..4e40704 100644 --- a/src/_cell.py +++ b/src/_cell.py @@ -4,28 +4,27 @@ # keep mypy happy, without actually importing (and thereby creating circular dependency cluster <-> cell) from typing import TYPE_CHECKING + if TYPE_CHECKING: from ._grid import Grid from ._cluster import Cluster - class Cell: - """ Smallest individual 'unit' of a grid. Has indices (x,y) and color""" + """Smallest individual 'unit' of a grid. Has indices (x,y) and color""" # ------------------------------- def __init__(self, row_idx: int, col_idx: int, is_black: bool = False, grid: Optional[Grid] = None): - """ order of indices: (row_idx, col_idx) -not- (col_idx, row_idx)~(x,y) - same convention as numpy/pandas """ + """order of indices: (row_idx, col_idx) -not- (col_idx, row_idx)~(x,y) + same convention as numpy/pandas""" - self.col_idx: int = col_idx - self.row_idx: int = row_idx + self.col_idx: int = col_idx + self.row_idx: int = row_idx self.is_black: bool = is_black self.grid: Optional[Grid] = grid self.cluster: Optional[Cluster] = None - # ------------------------------- def turn_black(self, on=True): self.is_black = on diff --git a/src/_cell_picker.py b/src/_cell_picker.py index e92e8de..85bc360 100644 --- a/src/_cell_picker.py +++ b/src/_cell_picker.py @@ -1,32 +1,31 @@ - import random from typing import List, Tuple class CellPicker: - """ Sequence of cells in (random) order from (num_rows x num_cols) sized grid""" - + """Sequence of cells in (random) order from (num_rows x num_cols) sized grid""" # ------------------------------- def __init__(self, num_rows: int, num_cols: int): - """ order of indices: (row_idx, col_idx) -not- (col_idx, row_idx)~(x,y) - same convention as numpy/pandas """ + """order of indices: (row_idx, col_idx) -not- (col_idx, row_idx)~(x,y) + same convention as numpy/pandas""" self.num_rows: int = num_rows self.num_cols: int = num_cols # ------------------------------- - def seq_random(self, deterministic=False) -> List[Tuple[int,int]]: - """ return random sequence of cells. - if deterministic is true, then returns the same sequence every time. """ + def seq_random(self, deterministic=False) -> List[Tuple[int, int]]: + """return random sequence of cells. + if deterministic is true, then returns the same sequence every time.""" # Generate a list of all cell indices indices = [(row, col) for row in range(self.num_rows) for col in range(self.num_cols)] - if(deterministic): + if deterministic: random.seed(42) # Shuffle the indices list in-place to ensure a different order each time random.shuffle(indices) return indices + # ------------------------------- diff --git a/src/_cluster.py b/src/_cluster.py index 38672ac..e2c1432 100644 --- a/src/_cluster.py +++ b/src/_cluster.py @@ -4,15 +4,14 @@ # keep mypy happy, without actually importing (and thereby creating circular dependency cluster <-> cell) from typing import TYPE_CHECKING + if TYPE_CHECKING: - from ._grid import Grid - from ._cell import Cell + from ._grid import Grid + from ._cell import Cell class Cluster: - """ Full islands (not subsets thereof) of black cells """ - - + """Full islands (not subsets thereof) of black cells""" # ------------------------------- def __init__(self, grid: Optional[Grid]): @@ -24,19 +23,18 @@ def __init__(self, grid: Optional[Grid]): self.row_idx_min: int = -1 # the closer to 0, the closer to top of grid self.row_idx_max: int = -1 # the closer to (grid.num_cols)-1, the closer to top of grid - # ------------------------------- def num_cells(self) -> int: return len(self.cells) # ------------------------------- def percolates(self) -> bool: - """ does cluster extend from top to bottom of grid? """ + """does cluster extend from top to bottom of grid?""" if self.grid is None: return False touches_top = self.row_idx_min == 0 - touches_bottom = self.row_idx_max == (self.grid.num_rows-1) + touches_bottom = self.row_idx_max == (self.grid.num_rows - 1) return touches_top and touches_bottom @@ -49,19 +47,19 @@ def add_cell(self, cell: Cell): # ------------------------------- def update_col_idx(self, cell: Cell) -> None: - """ updates col_idx_min/max if cell is closer to top/bottom of grid""" + """updates col_idx_min/max if cell is closer to top/bottom of grid""" if cell is None: return - if (self.row_idx_min <0) or (self.row_idx_min > cell.row_idx) : + if (self.row_idx_min < 0) or (self.row_idx_min > cell.row_idx): self.row_idx_min = cell.row_idx - if (self.row_idx_max <0) or (self.row_idx_max < cell.row_idx) : + if (self.row_idx_max < 0) or (self.row_idx_max < cell.row_idx): self.row_idx_max = cell.row_idx # ------------------------------- def merge(self, other: Cluster): - """ merges other cluster into this cluster """ + """merges other cluster into this cluster""" if (other is None) or (other is self): return diff --git a/src/_config.py b/src/_config.py index 3aa22be..4b694c7 100644 --- a/src/_config.py +++ b/src/_config.py @@ -1,5 +1,6 @@ import os + class Config: # set env var "CI" to disable default plot generation diff --git a/src/_experiment.py b/src/_experiment.py index b49e84f..0f681f2 100644 --- a/src/_experiment.py +++ b/src/_experiment.py @@ -1,12 +1,14 @@ - from ._stepper import Stepper from ._cell_picker import CellPicker from ._grid_visual import visualize_grid_clusters, visualize_grid_sequence + class Experiment: - """ Create a grid and find percolation threshold, with visualization """ + """Create a grid and find percolation threshold, with visualization""" - def do_it(self, num_rows: int = 5, num_cols: int = 6, want_vis_seq : bool = False, want_vis_clusters : bool = False) -> int : + def do_it( + self, num_rows: int = 5, num_cols: int = 6, want_vis_seq: bool = False, want_vis_clusters: bool = False + ) -> int: stepper = Stepper(num_rows, num_cols) seq = CellPicker(num_rows, num_cols).seq_random() @@ -16,7 +18,7 @@ def do_it(self, num_rows: int = 5, num_cols: int = 6, want_vis_seq : bool = Fals stepper.do_steps(seq) grid = stepper.grid - if (grid is None): + if grid is None: print("...empty grid in experiment??") return -1 diff --git a/src/_grid.py b/src/_grid.py index ffde937..9259509 100644 --- a/src/_grid.py +++ b/src/_grid.py @@ -7,8 +7,9 @@ Row = List[Cell] # Alias for List (so we can use eg "List[Row]" instead of "List[List[Cell]]" ) + class Grid: - """ Matrix of size (rows x cols) cells """ + """Matrix of size (rows x cols) cells""" # ------------------------------- def __init__(self, num_rows: int, num_cols: int): @@ -37,20 +38,23 @@ def init_cells(self): cell = Cell(row_idx=row_idx, col_idx=col_idx, is_black=False, grid=self) row.append(cell) self.rows.append(row) + # ------------------------------- def perc_value(self): - return float(self.steps_taken)/(float(self.num_cols * self.num_rows)) + return float(self.steps_taken) / (float(self.num_cols * self.num_rows)) + # ------------------------------- @classmethod - def indices_adjacent_to(Cls, num_rows: int, num_cols: int, row_idx: int, col_idx: int) -> Optional[List[Tuple[int,int]]]: - """ return list of cells adjacent to given cell (row_idx, col_idx) in grid of size (num_rows x num_cols) """ - - + def indices_adjacent_to( + Cls, num_rows: int, num_cols: int, row_idx: int, col_idx: int + ) -> Optional[List[Tuple[int, int]]]: + """return list of cells adjacent to given cell (row_idx, col_idx) in grid of size (num_rows x num_cols)""" deltas = [ - (-1, 0), # Above row - (0, -1), (0, 1), # Same row - (1, 0), # Below row + (-1, 0), # Above row + (0, -1), + (0, 1), # Same row + (1, 0), # Below row ] ret = [] @@ -61,9 +65,14 @@ def indices_adjacent_to(Cls, num_rows: int, num_cols: int, row_idx: int, col_idx ret.append((adj_row, adj_col)) return ret + # ------------------------------- - def cells_adjacent_to(self, row_idx: int, col_idx: int,) -> Optional[List[Cell]]: - """ return list of cells adjacent to given cell (row_idx, col_idx) """ + def cells_adjacent_to( + self, + row_idx: int, + col_idx: int, + ) -> Optional[List[Cell]]: + """return list of cells adjacent to given cell (row_idx, col_idx)""" cell = self.cell_at(row_idx, col_idx) if cell is None: @@ -79,7 +88,7 @@ def cells_at(self, indices: Optional[List[Tuple[int, int]]]) -> Optional[List[Ce if indices is None: return ret - for (row_idx, col_idx) in indices: + for row_idx, col_idx in indices: cell = self.cell_at(row_idx, col_idx) if not cell is None: ret.append(cell) @@ -88,10 +97,10 @@ def cells_at(self, indices: Optional[List[Tuple[int, int]]]) -> Optional[List[Ce # ------------------------------- def cell_at(self, row_idx: int, col_idx: int) -> Optional[Cell]: - """ return cell at given posn (col_idx,row_idx), or None if invalid + """return cell at given posn (col_idx,row_idx), or None if invalid - order of indices: (row_idx, col_idx) -not- (col_idx, row_idx)~(x,y) - same convention as numpy/pandas """ + order of indices: (row_idx, col_idx) -not- (col_idx, row_idx)~(x,y) + same convention as numpy/pandas""" # check for out of bounds (num_rows, num_cols) of grid if row_idx < 0 or (row_idx > self.num_rows): @@ -106,7 +115,6 @@ def cell_at(self, row_idx: int, col_idx: int) -> Optional[Cell]: return None row = self.rows[row_idx] - if col_idx > len(row): return None cell = row[col_idx] @@ -114,8 +122,8 @@ def cell_at(self, row_idx: int, col_idx: int) -> Optional[Cell]: # ------------------------------- def step(self, row_idx: int, col_idx: int) -> bool: - """ turn cell at given posn (col_idx,row_idx) black, merge any clusters. - return whether true if percolation has occured in this step """ + """turn cell at given posn (col_idx,row_idx) black, merge any clusters. + return whether true if percolation has occured in this step""" cell = self.cell_at(row_idx, col_idx) if cell is None: @@ -129,14 +137,13 @@ def step(self, row_idx: int, col_idx: int) -> bool: cell.cluster = cluster self.clusters.add(cluster) - adjacent_cells = self.cells_adjacent_to(row_idx, col_idx) if adjacent_cells is None: return False for cell_a in adjacent_cells: if cell_a.is_black: - cluster_a = cell_a.cluster + cluster_a = cell_a.cluster self.merge_clusters(cluster, cluster_a) perc = cluster.percolates() @@ -148,14 +155,14 @@ def step(self, row_idx: int, col_idx: int) -> bool: # ------------------------------- def merge_clusters(self, cla: Cluster, clb: Optional[Cluster]): - """ merge any clusters. - return whether true if percolation has occurred in this step """ + """merge any clusters. + return whether true if percolation has occurred in this step""" if (clb is None) or (cla is clb): return cla.merge(clb) - if (not clb in self.clusters): + if not clb in self.clusters: halt = 1 self.clusters.remove(clb) - halt=1 + halt = 1 diff --git a/src/_grid_visual.py b/src/_grid_visual.py index 38d772f..1ab13aa 100644 --- a/src/_grid_visual.py +++ b/src/_grid_visual.py @@ -8,8 +8,10 @@ from typing import List, Tuple, Optional from src._grid import Grid from src._cell import Cell + + # ------------------------------------- -def visualize_grid_sequence(num_rows: int, num_cols: int, sequence: List[Tuple[int,int]]): +def visualize_grid_sequence(num_rows: int, num_cols: int, sequence: List[Tuple[int, int]]): """ Visualizes the order of cells in the sequence, using a color map. """ @@ -37,7 +39,6 @@ def visualize_grid_sequence(num_rows: int, num_cols: int, sequence: List[Tuple[i text_color = "white" if normalized[row, col] < 0.5 else "black" plt.text(col, row, str(order), color=text_color, ha="center", va="center") - # Optionally, add a colorbar to indicate the sequence order plt.colorbar(label='Sequence Order') @@ -46,9 +47,9 @@ def visualize_grid_sequence(num_rows: int, num_cols: int, sequence: List[Tuple[i plt.ylabel('Row Index') plt.show() -# ------------------------------------- -def plot_grid_with_adjacent(num_rows, num_cols, row_idx, col_idx, adjacent_cells : List[Tuple[int, int]]): +# ------------------------------------- +def plot_grid_with_adjacent(num_rows, num_cols, row_idx, col_idx, adjacent_cells: List[Tuple[int, int]]): """ Visualizes the grid of size (num_rows x num_cols) with cell at (row_idx, col_idx) and adjacent_cells using a color map. @@ -75,51 +76,55 @@ def plot_grid_with_adjacent(num_rows, num_cols, row_idx, col_idx, adjacent_cells plt.tick_params(axis='both', which='both', length=0, labelbottom=False, labelleft=False) plt.show() + + # ------------------------------------- def visualize_grid_clusters(grid: Optional[Grid]): - def color_cell(ax, cell: Cell, color): - # Assuming cell has row and col attributes - rect = patches.Rectangle((cell.col_idx, cell.row_idx), 1, 1, linewidth=0, edgecolor='black', facecolor=color) + def color_cell(ax, cell: Cell, color): + # Assuming cell has row and col attributes + rect = patches.Rectangle((cell.col_idx, cell.row_idx), 1, 1, linewidth=0, edgecolor='black', facecolor=color) + ax.add_patch(rect) + + if not grid: + return + + # Initialize a white grid + fig, ax = plt.subplots() + ax.set_xlim(0, grid.num_cols) + ax.set_ylim(0, grid.num_rows) + ax.invert_yaxis() # Invert y axis to have origin at top-left + + # Color mapping + for cluster in grid.clusters: + for cell in cluster.cells: + color = 'yellow' if cluster == grid.perc_cluster else 'blue' + if cell == grid.perc_cell: + color = 'green' + color_cell(ax, cell, color) + + # Non-cluster cells, assuming you have a way to determine these, are colored white by default + + # Draw grid lines + for x in range(grid.num_cols): + for y in range(grid.num_rows): + rect = patches.Rectangle((x, y), 1, 1, linewidth=1, edgecolor='black', facecolor='none') ax.add_patch(rect) - if not grid: - return - - # Initialize a white grid - fig, ax = plt.subplots() - ax.set_xlim(0, grid.num_cols) - ax.set_ylim(0, grid.num_rows) - ax.invert_yaxis() # Invert y axis to have origin at top-left - - # Color mapping - for cluster in grid.clusters: - for cell in cluster.cells: - color = 'yellow' if cluster == grid.perc_cluster else 'blue' - if cell == grid.perc_cell: - color = 'green' - color_cell(ax, cell, color) + # Show steps taken + plt.text(0, -1, f'Steps taken: {grid.steps_taken}', fontsize=12) - # Non-cluster cells, assuming you have a way to determine these, are colored white by default - - # Draw grid lines - for x in range(grid.num_cols): - for y in range(grid.num_rows): - rect = patches.Rectangle((x, y), 1, 1, linewidth=1, edgecolor='black', facecolor='none') - ax.add_patch(rect) + plt.axis('off') + plt.show() - # Show steps taken - plt.text(0, -1, f'Steps taken: {grid.steps_taken}', fontsize=12) - plt.axis('off') - plt.show() # ------------------------- -def visualize_as_histogram(ps:List[float], x_label: str = "Value", title: str = 'Histogram of p values'): - #counts, bins = np.histogram(ps) - #plt.stairs(counts, bins) +def visualize_as_histogram(ps: List[float], x_label: str = "Value", title: str = 'Histogram of p values'): + # counts, bins = np.histogram(ps) + # plt.stairs(counts, bins) plt.hist(ps, bins='auto') - #plt.hist(ps, bins=100) # 'auto' lets matplotlib decide the number of bins + # plt.hist(ps, bins=100) # 'auto' lets matplotlib decide the number of bins plt.title(title) plt.xlabel(x_label) plt.ylabel('Frequency') diff --git a/src/_stepper.py b/src/_stepper.py index 62ceef8..543cf3c 100644 --- a/src/_stepper.py +++ b/src/_stepper.py @@ -5,7 +5,7 @@ class Stepper: - """ Given dims of grid (num_rows x num_cols) and a sequences of cells, turn them black, merge any clusters. """ + """Given dims of grid (num_rows x num_cols) and a sequences of cells, turn them black, merge any clusters.""" num_rows: int = -1 num_cols: int = -1 @@ -23,7 +23,7 @@ def do_steps(self, indices: List[Tuple[int, int]]) -> bool: if (indices is None) or (self.grid is None): return False - for (row_idx, col_idx) in indices: + for row_idx, col_idx in indices: percolates = self.grid.step(row_idx, col_idx) if percolates: cluster = self.grid.perc_cluster diff --git a/src/main.py b/src/main.py index 20df84b..01963d8 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,3 @@ - from src._experiment import Experiment from typing import List import time @@ -6,22 +5,27 @@ from dataclasses import dataclass + # -------------------------------------------- @dataclass class PercResult: - """ Encapsulates all data in calculation """ + """Encapsulates all data in calculation""" + # in: - num_cols: float - num_rows: float + num_cols: float + num_rows: float batch_size: int # out: - ps: List[float] # p-values - p_av: float # average p-value - time_delta: float # num of secs required to perform calculation + ps: List[float] # p-values + p_av: float # average p-value + time_delta: float # num of secs required to perform calculation + # -------------------------------------------- -def calculate_p_av(num_rows: int = 30, num_cols: int =30, batch_size: int = 300, want_vis_clusters=False) -> PercResult : +def calculate_p_av( + num_rows: int = 30, num_cols: int = 30, batch_size: int = 300, want_vis_clusters=False +) -> PercResult: """ :return: PercResult with ps, p_av, time_delta calculated @@ -35,7 +39,7 @@ def calculate_p_av(num_rows: int = 30, num_cols: int =30, batch_size: int = 300, ps: List[float] = [] for i in range(batch_size): - p_i= Experiment().do_it(num_rows=num_rows, num_cols=num_cols, want_vis_clusters=want_vis_clusters) + p_i = Experiment().do_it(num_rows=num_rows, num_cols=num_cols, want_vis_clusters=want_vis_clusters) ps.append(float(p_i)) p_av = sum(ps) / float(len(ps)) @@ -43,18 +47,23 @@ def calculate_p_av(num_rows: int = 30, num_cols: int =30, batch_size: int = 300, time_delta = t1 - t0 - - result = PercResult(num_rows=num_rows, num_cols=num_cols, batch_size=batch_size, ps=ps, p_av=p_av, time_delta=round(time_delta,2)) + result = PercResult( + num_rows=num_rows, num_cols=num_cols, batch_size=batch_size, ps=ps, p_av=p_av, time_delta=round(time_delta, 2) + ) return result + + # ------------------------------------------------------------------ if __name__ == "__main__": num_rows = 50 num_cols = 50 - batch_size= 100 + batch_size = 100 res = calculate_p_av(num_rows=num_rows, num_cols=num_cols, batch_size=batch_size, want_vis_clusters=False) - print(f"...average p: {res.p_av} with ({num_rows}x{num_cols}) grid, {batch_size} iterations in {res.time_delta} secs ") + print( + f"...average p: {res.p_av} with ({num_rows}x{num_cols}) grid, {batch_size} iterations in {res.time_delta} secs " + ) - visualize_as_histogram(res.ps, x_label="p", title= f"Percolation in {batch_size} ({num_rows}x{num_cols}) grids") + visualize_as_histogram(res.ps, x_label="p", title=f"Percolation in {batch_size} ({num_rows}x{num_cols}) grids") diff --git a/src/tmp.py b/src/tmp.py new file mode 100644 index 0000000..7efc872 --- /dev/null +++ b/src/tmp.py @@ -0,0 +1,97 @@ +from src._experiment import Experiment +from typing import List +import time +from src._grid_visual import visualize_as_histogram + +from dataclasses import dataclass + + +# -------------------------------------------- +@dataclass +class PercResult: + """Encapsulates all data in calculation""" + + # in: + num_cols: float + num_rows: float + batch_size: int + + # out: + ps: List[float] # p-values + p_av: float # average p-value + time_delta: float # num of secs required to perform calculation + + +# -------------------------------------------- +def calculate_p_av( + num_rows: int = 30, num_cols: int = 30, batch_size: int = 300, want_vis_clusters=False +) -> PercResult: + """ + :return: PercResult with ps, p_av, time_delta calculated + + + :param num_rows: height of grid + :param num_cols: width of grid + :param batch_size: num of individual values of p used to calculate average + """ + + t0 = time.time() + + ps: List[float] = [] + for i in range(batch_size): + p_i = Experiment().do_it(num_rows=num_rows, num_cols=num_cols, want_vis_clusters=want_vis_clusters) + ps.append(float(p_i)) + + p_av = sum(ps) / float(len(ps)) + t1 = time.time() + + time_delta = t1 - t0 + + result = PercResult( + num_rows=num_rows, num_cols=num_cols, batch_size=batch_size, ps=ps, p_av=p_av, time_delta=round(time_delta, 2) + ) + return result + + +# ------------------------------------------------------------------ +file_path = "/Users/declan/Documents/zone/high/text/info/tmp.txt" +if __name__ == "__main__": + import re + + declan = 3449.60 + irina = 3184.34 + + combined = declan + irina + half = combined / 2.0 + declan_owe = half - declan + irina_owe = half - irina + print(f"declan_owe = {declan_owe}, irina_owe = {irina_owe}") + + entries = [] + current_entry = [] + total = 0.0 + + with open(file_path, 'r') as file: + for line in file: + line = line.strip() + if line: + if line in current_entry: + continue + if line == "Kartenzahlung": + continue + current_entry.append(line) + else: + if current_entry: + entries.append(current_entry) + match = re.search(r'\s*-\s*-(\d+[.,]\d+)', '\n'.join(current_entry)) + if match: + # print(f"found match: {match.group(1)}") + total += float(match.group(1).replace(',', '.')) + # else: + # print(f"no match on current_entry: {current_entry}") + current_entry = [] + + for entry in entries: + print('\n'.join(entry) + '\n') + + print(f"\ntotal = {total}") diff --git a/test/test__algorithm.py b/test/test__algorithm.py index 40b2f19..4076ac0 100644 --- a/test/test__algorithm.py +++ b/test/test__algorithm.py @@ -1,11 +1,14 @@ """ Algorithm tests """ + from src._config import Config from src._grid import Grid from src._cell_picker import CellPicker from src._grid_visual import visualize_grid_sequence + + # -------------------------------------------- def test_cell_picker_seq_random(want_visualize: bool = Config.want_plots()): - """ visualize cell picker sequence """ + """visualize cell picker sequence""" num_rows = 5 num_cols = 6 @@ -20,23 +23,25 @@ def test_cell_picker_seq_random(want_visualize: bool = Config.want_plots()): # Count the differences between the original and shuffled sequences num_differ = sum(1 for orig, shuffled in zip(seq, seq_orig) if orig != shuffled) - assert num_differ > 0 , "expect shuffled sequence to differ from original" + assert num_differ > 0, "expect shuffled sequence to differ from original" # plot the sequence in colors representing sequence order if want_visualize: visualize_grid_sequence(num_rows, num_cols, seq) + + # -------------------------------------------- def test_cell_stepper(): - """ turn cells black in random order """ + """turn cells black in random order""" num_rows = 5 num_cols = 6 grid = Grid(num_rows, num_cols) seq = CellPicker(num_rows, num_cols).seq_random() - for (row_idx, col_idx) in seq: + for row_idx, col_idx in seq: cell = grid.cell_at(row_idx, col_idx) if cell: cell.turn_black() diff --git a/test/test__cluster.py b/test/test__cluster.py index ff62a4f..996d9ac 100644 --- a/test/test__cluster.py +++ b/test/test__cluster.py @@ -2,13 +2,15 @@ from src._cluster import Cluster from src._cell import Cell + + # -------------------------------------------- def test_grid_create(): - """ test cluster creation() """ + """test cluster creation()""" cluster = Cluster(grid=None) - cell_1 = Cell(0,0, is_black=True) - cell_2 = Cell(1,0, is_black=True) + cell_1 = Cell(0, 0, is_black=True) + cell_2 = Cell(1, 0, is_black=True) cell_3 = Cell(2, 0, is_black=False) cluster.add_cell(cell_1) diff --git a/test/test__experiment.py b/test/test__experiment.py index 97d0a5d..687bd6d 100644 --- a/test/test__experiment.py +++ b/test/test__experiment.py @@ -2,22 +2,23 @@ from src._experiment import Experiment + # -------------------------------------------- def test_experiment(): - """ Run an experiment """ + """Run an experiment""" import time t0 = time.time() - num_rows=5 - num_cols=4 + num_rows = 5 + num_cols = 4 p = Experiment().do_it(num_rows=num_rows, num_cols=num_cols) - assert 0