mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
update test cases
... ...
This commit is contained in:
parent
9b10a574b3
commit
c912f665f7
@ -130,7 +130,7 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, PyVec2& currentVelocity, float
|
||||
return VAR_T(PyVec2, self.rotate(radian));
|
||||
});
|
||||
|
||||
vm->bind_method<0>(type, "rotate_", [](VM* vm, ArgsView args){
|
||||
vm->bind_method<1>(type, "rotate_", [](VM* vm, ArgsView args){
|
||||
PyVec2& self = _CAST(PyVec2&, args[0]);
|
||||
float radian = CAST(f64, args[1]);
|
||||
self = self.rotate(radian);
|
||||
@ -250,7 +250,7 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, PyVec2& currentVelocity, float
|
||||
return vm->heap.gcnew<PyMat3x3>(PK_OBJ_GET(Type, args[0]), mat);
|
||||
}
|
||||
vm->TypeError(fmt("Mat3x3.__new__ takes 0 or 1 or 9 arguments, got ", args.size()-1));
|
||||
return vm->None;
|
||||
PK_UNREACHABLE();
|
||||
});
|
||||
|
||||
vm->bind_method<1>(type, "copy_", [](VM* vm, ArgsView args){
|
||||
@ -275,13 +275,11 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, PyVec2& currentVelocity, float
|
||||
Tuple& t = CAST(Tuple&, index);
|
||||
if(t.size() != 2){
|
||||
vm->TypeError("Mat3x3.__getitem__ takes a tuple of 2 integers");
|
||||
return vm->None;
|
||||
}
|
||||
i64 i = CAST(i64, t[0]);
|
||||
i64 j = CAST(i64, t[1]);
|
||||
if(i < 0 || i >= 3 || j < 0 || j >= 3){
|
||||
vm->IndexError("index out of range");
|
||||
return vm->None;
|
||||
}
|
||||
return VAR(self.m[i][j]);
|
||||
});
|
||||
@ -291,13 +289,11 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, PyVec2& currentVelocity, float
|
||||
const Tuple& t = CAST(Tuple&, index);
|
||||
if(t.size() != 2){
|
||||
vm->TypeError("Mat3x3.__setitem__ takes a tuple of 2 integers");
|
||||
return;
|
||||
}
|
||||
i64 i = CAST(i64, t[0]);
|
||||
i64 j = CAST(i64, t[1]);
|
||||
if(i < 0 || i >= 3 || j < 0 || j >= 3){
|
||||
vm->IndexError("index out of range");
|
||||
return;
|
||||
}
|
||||
self.m[i][j] = CAST_F(value);
|
||||
});
|
||||
@ -361,7 +357,7 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, PyVec2& currentVelocity, float
|
||||
if(args[2] == vm->None){
|
||||
return VAR_T(PyMat3x3, self.matmul(other));
|
||||
}else{
|
||||
PyMat3x3& out = _CAST(PyMat3x3&, args[2]);
|
||||
PyMat3x3& out = CAST(PyMat3x3&, args[2]);
|
||||
out = self.matmul(other);
|
||||
return vm->None;
|
||||
}
|
||||
|
@ -38,11 +38,13 @@ assert element_value_list == copy_element_value_list
|
||||
test_vec2_copy = test_vec2.copy()
|
||||
radians = random.uniform(-10*math.pi, 10*math.pi)
|
||||
test_vec2_copy = rotated_vec2(test_vec2_copy, radians)
|
||||
assert test_vec2.rotate(radians).__dict__ == test_vec2_copy.__dict__
|
||||
assert test_vec2.rotate(radians) == test_vec2_copy
|
||||
test_vec2.rotate_(radians)
|
||||
assert test_vec2 == test_vec2_copy
|
||||
|
||||
# test smooth_damp
|
||||
vel = vec2(0, 0)
|
||||
ret = vec2.smooth_damp(vec2(1, 2), vec2(3, 4), vel, 7, 8, 9)
|
||||
ret = vec2.smooth_damp(vec2(1, 2), vec2(3, 4), vel, 0.2, 0.001, 0.05)
|
||||
assert isinstance(ret, vec2)
|
||||
assert vel.length() > 0
|
||||
|
||||
@ -342,10 +344,12 @@ except:
|
||||
|
||||
# test transpose
|
||||
test_mat_copy = test_mat.copy()
|
||||
assert test_mat_copy.transpose_() is None
|
||||
assert test_mat_copy == test_mat.transpose()
|
||||
assert test_mat_copy.transpose() == test_mat_copy.transpose().transpose().transpose()
|
||||
|
||||
# test inverse
|
||||
assert ~static_test_mat_float == static_test_mat_float_inv
|
||||
assert ~static_test_mat_float == static_test_mat_float_inv == static_test_mat_float.invert()
|
||||
assert static_test_mat_float.invert_() is None
|
||||
assert static_test_mat_float == static_test_mat_float_inv
|
||||
|
||||
@ -467,3 +471,14 @@ d = mat3x3.identity()
|
||||
assert d.copy_(mat3x3.zeros()) is None
|
||||
assert d == mat3x3.zeros()
|
||||
|
||||
d = mat3x3.identity()
|
||||
assert d.matmul(mat3x3.zeros()) == mat3x3.zeros()
|
||||
assert d == mat3x3.identity()
|
||||
assert d.matmul(mat3x3.zeros(), out=d) is None
|
||||
assert d == mat3x3.zeros()
|
||||
|
||||
try:
|
||||
assert d[6, 6]
|
||||
exit(1)
|
||||
except IndexError:
|
||||
pass
|
Loading…
x
Reference in New Issue
Block a user