Browse Source

fix names

blueloveTH 1 year ago
parent
commit
d634ec9829
3 changed files with 8 additions and 8 deletions
  1. 2 2
      include/typings/array2d.pyi
  2. 3 3
      src/array2d.cpp
  3. 3 3
      tests/83_array2d.py

+ 2 - 2
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:

+ 3 - 3
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>(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; 
         });

+ 3 - 3
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)