mirror of
https://github.com/snowykami/mbcp.git
synced 2025-08-02 19:49:58 +00:00
🐛 fix ε accuracy
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
32
tests/answer.py
Normal file
32
tests/answer.py
Normal file
@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
||||
|
||||
@Time : 2024/8/27 下午1:03
|
||||
@Author : snowykami
|
||||
@Email : snowykami@outlook.com
|
||||
@File : .answer.py
|
||||
@Software: PyCharm
|
||||
"""
|
||||
from liteyuki.log import logger # type: ignore
|
||||
|
||||
|
||||
def output_answer(correct_ans, actual_ans, question: str = None):
|
||||
"""
|
||||
输出答案
|
||||
Args:
|
||||
correct_ans:
|
||||
actual_ans:
|
||||
question:
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
print("")
|
||||
if question is not None:
|
||||
logger.info(f"问题:{question}")
|
||||
r = correct_ans == actual_ans
|
||||
if r:
|
||||
logger.success(f"测试正确 正确答案:{correct_ans} 实际答案:{actual_ans}")
|
||||
else:
|
||||
logger.error(f"测试错误 正确答案:{correct_ans} 实际答案:{actual_ans}")
|
@ -13,21 +13,8 @@ import logging
|
||||
from mbcp.mp_math.point import Point3
|
||||
from mbcp.mp_math.vector import Vector3
|
||||
from mbcp.mp_math.line import Line3
|
||||
from tests.answer import output_answer
|
||||
|
||||
|
||||
class TestLine3:
|
||||
|
||||
def test_point_and_normal_factory(self):
|
||||
"""
|
||||
测试通过点和法向量构造直线
|
||||
"""
|
||||
correct_ans = Line3(1, -2, 3, -8)
|
||||
|
||||
p = Point3(2, -3, 0)
|
||||
n = Vector3(1, -2, 3)
|
||||
|
||||
actual_ans = Line3.from_point_and_direction(p, n)
|
||||
logging.info(f"正确答案:{correct_ans} 实际答案:{actual_ans}")
|
||||
assert actual_ans == correct_ans
|
||||
|
||||
|
||||
|
@ -12,6 +12,8 @@ import logging
|
||||
|
||||
from mbcp.mp_math.line import Line3
|
||||
from mbcp.mp_math.plane import Plane3
|
||||
from mbcp.mp_math.point import Point3
|
||||
from mbcp.mp_math.vector import Vector3
|
||||
|
||||
|
||||
class TestPlane3:
|
||||
@ -20,10 +22,10 @@ class TestPlane3:
|
||||
"""
|
||||
测试平面的交线
|
||||
"""
|
||||
correct_ans = Line3(4, 3, 1, 1)
|
||||
correct_ans = Line3(Point3(-3, 2, 5), Vector3(4, 3, 1))
|
||||
|
||||
pl1 = Plane3(1, 0, -4, 23)
|
||||
pl2 = Plane3(2, -1, -5, 33)
|
||||
actual_ans = pl1.cal_intersection_line3(pl2)
|
||||
actual_ans = pl1 & pl2 # 平面交线
|
||||
logging.info(f"正确答案:{correct_ans} 实际答案:{actual_ans}")
|
||||
assert actual_ans == correct_ans
|
||||
|
@ -12,6 +12,8 @@ import logging
|
||||
|
||||
from mbcp.mp_math.vector import Vector3
|
||||
|
||||
from tests.answer import output_answer
|
||||
|
||||
|
||||
class TestVector3:
|
||||
|
||||
@ -23,7 +25,7 @@ class TestVector3:
|
||||
"""
|
||||
v1 = Vector3(1, 2, 3)
|
||||
v2 = Vector3(3, 4, 5)
|
||||
actual_ans = v1 @ v2
|
||||
actual_ans = v1.cross(v2)
|
||||
correct_ans = Vector3(-2, 4, -2)
|
||||
logging.info(f"正确答案{correct_ans} 实际答案{v1 @ v2}")
|
||||
|
||||
@ -34,18 +36,20 @@ class TestVector3:
|
||||
测试判断向量是否平行
|
||||
Returns:
|
||||
"""
|
||||
"""小题1"""
|
||||
correct_ans = True
|
||||
v1 = Vector3(1, 2, 3)
|
||||
v2 = Vector3(3, 6, 9)
|
||||
actual_ans = v1.is_parallel(v2)
|
||||
correct_ans = True
|
||||
logging.info("v1和v2是否平行:%s", v1.is_parallel(v2))
|
||||
output_answer(correct_ans, actual_ans)
|
||||
assert correct_ans == actual_ans
|
||||
|
||||
"""小题2"""
|
||||
correct_ans = False
|
||||
v1 = Vector3(1, 2, 3)
|
||||
v2 = Vector3(3, 6, 8)
|
||||
actual_ans = v1.is_parallel(v2)
|
||||
correct_ans = False
|
||||
logging.info("v1和v2是否平行:%s", v1.is_parallel(v2))
|
||||
output_answer(correct_ans, actual_ans)
|
||||
assert correct_ans == actual_ans
|
||||
|
||||
|
||||
|
@ -2,11 +2,12 @@
|
||||
"""
|
||||
应用题测试集
|
||||
"""
|
||||
import logging
|
||||
|
||||
from liteyuki.log import logger # type: ignore
|
||||
from mbcp.mp_math.line import Line3
|
||||
from mbcp.mp_math.plane import Plane3
|
||||
from mbcp.mp_math.point import Point3
|
||||
from mbcp.mp_math.vector import Vector3
|
||||
from .answer import output_answer
|
||||
|
||||
|
||||
class TestWordProblem:
|
||||
@ -16,17 +17,17 @@ class TestWordProblem:
|
||||
同济大学《高等数学》第八版 下册 第八章第四节例4
|
||||
问题:求与两平面x-4z-3=0和2x-y-5z-1=0的交线平行且过点(-3, 2, 5)的直线方程。
|
||||
"""
|
||||
correct_ans = Line3(4, 3, 1, 1)
|
||||
|
||||
question = "求与两平面x-4z-3=0和2x-y-5z-1=0的交线平行且过点(-3, 2, 5)的直线方程。"
|
||||
correct_ans = Line3(Point3(-3, 2, 5), Vector3(4, 3, 1))
|
||||
pl1 = Plane3(1, 0, -4, -3)
|
||||
pl2 = Plane3(2, -1, -5, -1)
|
||||
p = Point3(-3, 2, 5)
|
||||
"""解法1"""
|
||||
# 求直线方向向量s
|
||||
s = pl1.normal @ pl2.normal
|
||||
actual_ans = Line3.from_point_and_direction(p, s)
|
||||
s = pl1.normal.cross(pl2.normal)
|
||||
actual_ans = Line3(p, s)
|
||||
|
||||
logging.info(f"正确答案:{correct_ans} 实际答案:{actual_ans}")
|
||||
output_answer(correct_ans, actual_ans, question)
|
||||
assert actual_ans == correct_ans
|
||||
|
||||
"""解法2"""
|
||||
@ -36,8 +37,40 @@ class TestWordProblem:
|
||||
pl4 = pl2.cal_parallel_plane3(p)
|
||||
# 求pl3和pl4的交线
|
||||
actual_ans = pl3.cal_intersection_line3(pl4)
|
||||
print(pl3, pl4, actual_ans)
|
||||
|
||||
logging.info(f"正确答案:{correct_ans} 实际答案:{actual_ans}")
|
||||
output_answer(correct_ans, actual_ans, question)
|
||||
assert actual_ans == correct_ans
|
||||
|
||||
def test_c8s4e5(self):
|
||||
"""
|
||||
同济大学《高等数学》第八版 下册 第八章第四节例5
|
||||
|
||||
求直线(x-2)/1=(y-3)/1=(z-4)/2与平面2x+y+z-6=0的交点。
|
||||
"""
|
||||
question = "求直线(x-2)/1=(y-3)/1=(z-4)/2与平面2x+y+z-6=0的交点。"
|
||||
"""正确答案"""
|
||||
correct_ans = Point3(1, 2, 2)
|
||||
"""题目已知量"""
|
||||
line = Line3(Point3(2, 3, 4), Vector3(1, 1, 2))
|
||||
plane = Plane3(2, 1, 1, -6)
|
||||
|
||||
"""解"""
|
||||
actual_ans = plane & line
|
||||
output_answer(correct_ans, actual_ans, question)
|
||||
|
||||
def test_c8s4e6(self):
|
||||
question = "求过点(2, 3, 1)且与直线(x+1)/3 = (y-1)/2 = z/-1垂直相交的直线的方程。"
|
||||
"""正确答案"""
|
||||
correct_ans = Line3(Point3(2, 1, 3), Vector3(2, -1, 4))
|
||||
"""题目已知量"""
|
||||
point = Point3(2, 3, 1)
|
||||
line = Line3(Point3(-1, 1, 0), Vector3(3, 2, -1))
|
||||
|
||||
"""解"""
|
||||
# 先作平面过点且垂直与已知直线
|
||||
pl = line.cal_perpendicular(point)
|
||||
logger.debug(line.get_point(1))
|
||||
|
||||
# output_answer(correct_ans, actual_ans, question)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user