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