From d634ec98290d9a9dc44347f61d2d11ffb0331d2d Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 21 Apr 2024 21:04:42 +0800 Subject: [PATCH] fix names --- include/typings/array2d.pyi | 4 ++-- src/array2d.cpp | 6 +++--- tests/83_array2d.py | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/typings/array2d.pyi b/include/typings/array2d.pyi index 8af47eed..4c37a093 100644 --- a/include/typings/array2d.pyi +++ b/include/typings/array2d.pyi @@ -2,7 +2,7 @@ from typing import Callable, Any, Generic, TypeVar, Literal, overload T = TypeVar('T') -Neighborhood = Literal['moore', 'von_neumann'] +Neighborhood = Literal['Moore', 'von Neumann'] class array2d(Generic[T]): def __init__(self, n_cols: int, n_rows: int, default=None): ... @@ -44,7 +44,7 @@ class array2d(Generic[T]): def count(self, value: T) -> int: """Counts the number of cells with the given value.""" - def count_neighbors(self, value: T, neighborhood: Neighborhood = 'moore') -> 'array2d[int]': + def count_neighbors(self, value: T, neighborhood: Neighborhood = 'Moore') -> 'array2d[int]': """Counts the number of neighbors with the given value for each cell.""" def find_bounding_rect(self, value: T) -> tuple[int, int, int, int] | None: diff --git a/src/array2d.cpp b/src/array2d.cpp index 501d4c82..d60b93a4 100644 --- a/src/array2d.cpp +++ b/src/array2d.cpp @@ -264,14 +264,14 @@ struct Array2d{ return vm->True; }); - vm->bind(type, "count_neighbors(self, value, neighborhood='moore') -> array2d[int]", [](VM* vm, ArgsView args){ + vm->bind(type, "count_neighbors(self, value, neighborhood='Moore') -> array2d[int]", [](VM* vm, ArgsView args){ Array2d& self = PK_OBJ_GET(Array2d, args[0]); PyObject* new_array_obj = vm->heap.gcnew(Array2d::_type(vm)); Array2d& new_array = PK_OBJ_GET(Array2d, new_array_obj); new_array.init(self.n_cols, self.n_rows); PyObject* value = args[1]; const Str& neighborhood = CAST(Str&, args[2]); - if(neighborhood == "moore"){ + if(neighborhood == "Moore"){ for(int j = 0; j < new_array.n_rows; j++){ for(int i = 0; i < new_array.n_cols; i++){ int count = 0; @@ -298,7 +298,7 @@ struct Array2d{ } } }else{ - vm->ValueError("neighborhood must be 'moore' or 'von_neumann'"); + vm->ValueError("neighborhood must be 'Moore' or 'von Neumann'"); } return new_array_obj; }); diff --git a/tests/83_array2d.py b/tests/83_array2d.py index 9c1825e5..a35cf3da 100644 --- a/tests/83_array2d.py +++ b/tests/83_array2d.py @@ -108,7 +108,7 @@ assert A().get(0, 0, default=2) == 0 # test alive_neighbors a = array2d(3, 3, default=0) a[1, 1] = 1 -""" moore von_neumann +""" Moore von Neumann 0 0 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 0 1 1 1 0 1 0 @@ -118,8 +118,8 @@ moore_result[1, 1] = 0 von_neumann_result = array2d(3, 3, default=0) von_neumann_result[0, 1] = von_neumann_result[1, 0] = von_neumann_result[1, 2] = von_neumann_result[2, 1] = 1 -a.count_neighbors(0, 'moore') == moore_result -a.count_neighbors(0, 'von_neumann') == von_neumann_result +a.count_neighbors(0, 'Moore') == moore_result +a.count_neighbors(0, 'von Neumann') == von_neumann_result # test slice get a = array2d(5, 5, default=0)