58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
import unittest
|
|
|
|
from munch import Munch
|
|
|
|
from mosfet.bot import look_direction_from_eye, update_pitch
|
|
from mosfet.vector import Point3D
|
|
|
|
|
|
class LookDirection:
|
|
def __init__(self, angle):
|
|
self.angle = angle
|
|
|
|
def length(self):
|
|
return 2.0
|
|
|
|
def normalized(self):
|
|
return self
|
|
|
|
def angleDeg(self, _direction):
|
|
return self.angle
|
|
|
|
|
|
class TestFarmingPitch(unittest.TestCase):
|
|
def test_aiming_at_a_same_level_crop_uses_eye_height_and_looks_down(self):
|
|
player = Point3D((0.5, 64.0, 0.5))
|
|
crop_center = Point3D((1.5, 64.5, 1.5))
|
|
direction = look_direction_from_eye(player, crop_center)
|
|
|
|
self.assertGreater(direction.y, 0)
|
|
state = Munch(pitch=0.0)
|
|
update_pitch(state, direction)
|
|
self.assertGreater(state.pitch, 0.0)
|
|
|
|
def test_pitch_never_looks_more_than_45_degrees_down(self):
|
|
state = Munch(pitch=0.0)
|
|
directly_below = LookDirection(0.0)
|
|
for _ in range(8):
|
|
update_pitch(state, directly_below)
|
|
self.assertEqual(state.pitch, 45.0)
|
|
|
|
def test_pitch_tracks_look_target_instead_of_a_fixed_farming_angle(self):
|
|
state = Munch(pitch=0.0)
|
|
direction_to_crop = LookDirection(45.0)
|
|
for _ in range(5):
|
|
update_pitch(state, direction_to_crop)
|
|
self.assertEqual(state.pitch, 45.0)
|
|
|
|
# Looking level at another target pulls the pitch back toward zero.
|
|
update_pitch(state, LookDirection(90.0))
|
|
self.assertEqual(state.pitch, 35.0)
|
|
|
|
update_pitch(state, None)
|
|
self.assertEqual(state.pitch, 25.0)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|