Merge pull request #119 from zhs628/bufan's_test

Bufan's test
This commit is contained in:
BLUELOVETH 2023-07-29 17:00:55 +08:00 committed by GitHub
commit f724b5ef31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 2 deletions

15
build.ps1 Normal file
View File

@ -0,0 +1,15 @@
mkdir -p output/windows/x86_64
cd dylib
xmake f -p windows -a x64
xmake
cp build/windows/x64/release/test.dll ../output/windows/x86_64
cd ..
mkdir -p output/windows/x86_64
mkdir build
cd build
cmake ..
cmake --build . --config Release
cp Release/main.exe ../output/windows/x86_64
cp Release/pocketpy.dll ../output/windows/x86_64
cp Release/main.exe ../
cp Release/pocketpy.dll ../

View File

@ -1,4 +1,4 @@
from linalg import mat3x3, vec2 from linalg import mat3x3, vec2, vec3
import random import random
import sys import sys
@ -45,6 +45,29 @@ test_mat = mat3x3([[random.uniform(min_num, max_num) for _ in range(3)] for _ in
# [7, 8, 9]] # [7, 8, 9]]
# ) # )
# test incorrect number of parameters is passed
for i in range(20):
if i in [0, 9]:
continue
try:
test_mat_copy = mat3x3(*tuple([e+0.1 for e in range(i)]))
# 既然参数数量不是合法的0个或9个,并且这里也没有触发TypeError,那么引发测试失败
print(f'When there are {i} arguments, no TypeError is triggered')
exit(1)
except TypeError:
pass
# test 9 floating parameters is passed
test_mat_copy = test_mat.copy()
element_name_list = [e for e in dir(test_mat_copy) if e[:2] != '__' and e[0] == '_']
element_value_list = [getattr(test_mat, attr) for attr in element_name_list]
assert mat3x3(*tuple(element_value_list)) == test_mat
# test copy # test copy
test_mat_copy = test_mat.copy() test_mat_copy = test_mat.copy()
assert test_mat is not test_mat_copy assert test_mat is not test_mat_copy
@ -127,4 +150,9 @@ assert result_mat == correct_result_mat
test_mat_copy = test_mat.copy() test_mat_copy = test_mat.copy()
for i in range(3): for i in range(3):
for j in range(3): for j in range(3):
test_mat_copy[i, j] = test_mat[j, i] test_mat_copy[i, j] = test_mat[j, i]
# test __repr__
test_mat_copy = test_mat.copy()
print(test_mat_copy[0,0])
assert test_mat_copy.__repr__() == f'mat3x3([[{test_mat_copy[0,0].round(4)}, {test_mat_copy[1,0].round(4)}, {test_mat_copy[2,0].round(4)}],\n [{test_mat_copy[0,1].round(4)}, {test_mat_copy[1,1].round(4)}, {test_mat_copy[2,1].round(4)}],\n [{test_mat_copy[0,2].round(4)}, {test_mat_copy[1,2].round(4)}, {test_mat_copy[2,2].round(4)}]])'