mbcp/tests/test_vector3.py

79 lines
1.9 KiB
Python
Raw Permalink Normal View History

2024-08-27 09:08:27 +08:00
# -*- coding: utf-8 -*-
"""
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
@Time : 2024/8/26 上午6:58
@Author : snowykami
@Email : snowykami@outlook.com
@File : test_question_1.py
@Software: PyCharm
"""
import logging
2024-08-28 04:22:22 +08:00
from mbcp.mp_math.angle import AnyAngle
from mbcp.mp_math.const import PI
2024-08-27 09:08:27 +08:00
from mbcp.mp_math.vector import Vector3
2024-08-28 01:26:59 +08:00
from tests.answer import output_ans
2024-08-27 21:39:36 +08:00
2024-08-27 09:08:27 +08:00
class TestVector3:
"""测试问题集"""
2024-08-28 04:22:22 +08:00
def test_cal_angle(self):
"""
测试计算两个向量的夹角
Returns:
"""
"""小题1"""
v1 = Vector3(0 ,1, 0)
v2 = Vector3(0, 0, 1)
correct_ans = AnyAngle(90)
actual_ans = v1.cal_angle(v2)
output_ans(correct_ans, actual_ans)
"""小题2"""
v1 = Vector3(0, 1, 0)
v2 = Vector3(1, 1, 0)
correct_ans = AnyAngle(45)
actual_ans = v1.cal_angle(v2)
output_ans(correct_ans, actual_ans)
2024-08-27 09:08:27 +08:00
def test_vector_cross_product(self):
"""
测试向量叉乘
Returns:
"""
v1 = Vector3(1, 2, 3)
v2 = Vector3(3, 4, 5)
2024-08-27 21:39:36 +08:00
actual_ans = v1.cross(v2)
2024-08-27 09:08:27 +08:00
correct_ans = Vector3(-2, 4, -2)
logging.info(f"正确答案{correct_ans} 实际答案{v1 @ v2}")
assert correct_ans == actual_ans
def test_determine_vector_parallel(self):
"""
测试判断向量是否平行
Returns:
"""
2024-08-27 21:39:36 +08:00
"""小题1"""
correct_ans = True
2024-08-27 09:08:27 +08:00
v1 = Vector3(1, 2, 3)
v2 = Vector3(3, 6, 9)
actual_ans = v1.is_parallel(v2)
2024-08-28 01:26:59 +08:00
output_ans(correct_ans, actual_ans)
2024-08-27 09:08:27 +08:00
assert correct_ans == actual_ans
2024-08-27 21:39:36 +08:00
"""小题2"""
correct_ans = False
2024-08-27 09:08:27 +08:00
v1 = Vector3(1, 2, 3)
v2 = Vector3(3, 6, 8)
actual_ans = v1.is_parallel(v2)
2024-08-28 01:26:59 +08:00
output_ans(correct_ans, actual_ans)
2024-08-27 09:08:27 +08:00
assert correct_ans == actual_ans