Fix: 1.16.5 is erroneously marked as unsupported
[pyCraft.git] / tests / test_utility_types.py
blob3f8cc357fe2ccaaedaffbe13a7de74e3d338e93e
1 import unittest
3 from minecraft.networking.types import (
4 Enum, BitFieldEnum, Vector, Position, PositionAndLook
8 class EnumTest(unittest.TestCase):
9 def test_enum(self):
10 class Example(Enum):
11 ONE = 1
12 TWO = 2
13 THREE = 3
15 self.assertEqual(
16 list(map(Example.name_from_value, range(5))),
17 [None, 'ONE', 'TWO', 'THREE', None])
20 class BitFieldEnumTest(unittest.TestCase):
21 def test_name_from_value(self):
22 class Example1(BitFieldEnum):
23 ONE = 1
24 TWO = 2
25 FOUR = 4
26 ALL = 7
27 NONE = 0
29 self.assertEqual(
30 list(map(Example1.name_from_value, range(9))),
31 ['NONE', 'ONE', 'TWO', 'ONE|TWO', 'FOUR',
32 'ONE|FOUR', 'TWO|FOUR', 'ALL', None])
34 class Example2(BitFieldEnum):
35 ONE = 1
36 TWO = 2
37 FOUR = 4
39 self.assertEqual(
40 list(map(Example2.name_from_value, range(9))),
41 ['0', 'ONE', 'TWO', 'ONE|TWO', 'FOUR',
42 'ONE|FOUR', 'TWO|FOUR', 'ONE|TWO|FOUR', None])
45 class VectorTest(unittest.TestCase):
46 def test_operators(self):
47 self.assertEqual(Vector(1, -2, 0) + Vector(0, 1, 2), Vector(1, -1, 2))
48 self.assertEqual(Vector(1, -2, 0) - Vector(0, 1, 2), Vector(1, -3, -2))
49 self.assertEqual(-Vector(1, -2, 0), Vector(-1, 2, 0))
50 self.assertEqual(Vector(1, -2, 0) * 2, Vector(2, -4, 0))
51 self.assertEqual(2 * Vector(1, -2, 0), Vector(2, -4, 0))
52 self.assertEqual(Vector(1, -2, 0) / 2, Vector(1/2, -2/2, 0/2))
53 self.assertEqual(Vector(1, -2, 0) // 2, Vector(0, -1, 0))
55 def test_repr(self):
56 self.assertEqual(str(Vector(1, 2, 3)), 'Vector(1, 2, 3)')
57 self.assertEqual(str(Position(1, 2, 3)), 'Position(1, 2, 3)')
60 class PositionAndLookTest(unittest.TestCase):
61 """ This also tests the MutableRecord base type. """
62 def test_properties(self):
63 pos_look_1 = PositionAndLook(position=(1, 2, 3), look=(4, 5))
64 pos_look_2 = PositionAndLook(x=1, y=2, z=3, yaw=4, pitch=5)
65 string_repr = 'PositionAndLook(x=1, y=2, z=3, yaw=4, pitch=5)'
67 self.assertEqual(pos_look_1, pos_look_2)
68 self.assertEqual(pos_look_1.position, pos_look_1.position)
69 self.assertEqual(pos_look_1.look, pos_look_2.look)
70 self.assertEqual(hash(pos_look_1), hash(pos_look_2))
71 self.assertEqual(str(pos_look_1), string_repr)
73 self.assertFalse(pos_look_1 != pos_look_2)
74 pos_look_1.position += Vector(1, 1, 1)
75 self.assertTrue(pos_look_1 != pos_look_2)