mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
backup
This commit is contained in:
parent
7e9fd338b7
commit
d744e654cc
@ -361,8 +361,9 @@ static bool array2d_like__getitem__(int argc, py_Ref argv) {
|
||||
for(int j = 0; j < self->n_rows; j++) {
|
||||
for(int i = 0; i < self->n_cols; i++) {
|
||||
py_Ref item = self->f_get(self, i, j);
|
||||
if(!py_checkbool(item)) return false;
|
||||
if(py_tobool(item)) py_list_append(py_retval(), item);
|
||||
py_Ref cond = mask->f_get(mask, i, j);
|
||||
if(!py_checkbool(cond)) return false;
|
||||
if(py_tobool(cond)) py_list_append(py_retval(), item);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -410,9 +411,9 @@ static bool array2d_like__setitem__(int argc, py_Ref argv) {
|
||||
if(!_array2d_like_check_same_shape(self, mask)) return false;
|
||||
for(int j = 0; j < self->n_rows; j++) {
|
||||
for(int i = 0; i < self->n_cols; i++) {
|
||||
py_Ref item = self->f_get(self, i, j);
|
||||
if(!py_checkbool(item)) return false;
|
||||
if(py_tobool(item)) {
|
||||
py_Ref cond = mask->f_get(mask, i, j);
|
||||
if(!py_checkbool(cond)) return false;
|
||||
if(py_tobool(cond)) {
|
||||
bool ok = self->f_set(self, i, j, value);
|
||||
if(!ok) return false;
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
from array2d import array2d
|
||||
from linalg import vec2i
|
||||
|
||||
def exit_on_error():
|
||||
raise KeyboardInterrupt
|
||||
|
||||
# test error args for __init__
|
||||
try:
|
||||
a = array2d(0, 0)
|
||||
exit(0)
|
||||
exit_on_error()
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
@ -39,7 +42,7 @@ assert a[0, 0] == (0, 0)
|
||||
assert a[1, 3] == (1, 3)
|
||||
try:
|
||||
a[2, 0]
|
||||
exit(1)
|
||||
exit_on_error()
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
@ -51,7 +54,7 @@ a[1, 3] = 6
|
||||
assert a[1, 3] == 6
|
||||
try:
|
||||
a[0, -1] = 7
|
||||
exit(1)
|
||||
exit_on_error()
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
@ -146,7 +149,7 @@ assert a.get_bounding_rect(0) == (0, 0, 5, 5)
|
||||
|
||||
try:
|
||||
a.get_bounding_rect(2)
|
||||
exit(1)
|
||||
exit_on_error()
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
@ -163,16 +166,10 @@ assert a == array2d(3, 2, default=3)
|
||||
|
||||
try:
|
||||
a[:, :] = array2d(1, 1)
|
||||
exit(1)
|
||||
exit_on_error()
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
try:
|
||||
a[:, :] = ...
|
||||
exit(1)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
# test __iter__
|
||||
a = array2d(3, 4, default=1)
|
||||
for xy, val in a:
|
||||
|
Loading…
x
Reference in New Issue
Block a user