~cnx/palace

ref: 708f23b35a7e232273ba0a63a65b3ef778a84540 palace/tests/unit/test_listener.py -rw-r--r-- 2.6 KiB
708f23b3 — Ngô Ngọc Đức Huy Write tutorial for source effect 1 year, 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Listener pytest module
# Copyright (C) 2020  Ngô Xuân Minh
# Copyright (C) 2020  Nguyễn Gia Phong
#
# This file is part of palace.
#
# palace is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# palace is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with palace.  If not, see <https://www.gnu.org/licenses/>.

"""This pytest module tries to test the correctness of the class Listener."""

from pytest import mark, raises

from math import inf


def test_gain(context):
    """Test write-only property gain."""
    context.listener.gain = 5/7
    context.listener.gain = 7/5
    context.listener.gain = 0
    context.listener.gain = inf
    with raises(ValueError): context.listener.gain = -1
    with raises(AttributeError): context.listener.gain


@mark.parametrize('position', [(1, 0, 1), (1, 0, -1), (1, -1, 0),
                               (1, 1, 0), (0, 0, 0), (1, 1, 1)])
def test_position(context, position):
    """Test write-only property position."""
    context.listener.position = position
    with raises(AttributeError): context.listener.position


@mark.parametrize('velocity', [(420, 0, 69), (69, 0, -420), (0, 420, -69),
                               (0, 0, 42), (0, 0, 0), (420, 69, 420)])
def test_velocity(context, velocity):
    """Test write-only property velocity."""
    context.listener.velocity = velocity
    with raises(AttributeError): context.listener.velocity


@mark.parametrize(('at', 'up'), [
    ((420, 0, 69), (0, 42, 0)), ((69, 0, -420), (0, -69, 420)),
    ((0, 420, -69), (420, -69, 69)), ((0, 0, 42), (-420, -420, 0)),
    ((0, 0, 0), (-420, -69, -69)), ((420, 69, 420), (69, -420, 0))])
def test_orientaion(context, at, up):
    """Test write-only property orientation."""
    context.listener.orientation = at, up
    with raises(AttributeError): context.listener.orientation


def test_meters_per_unit(context):
    """Test write-only property meters_per_unit."""
    context.listener.meters_per_unit = 4/9
    context.listener.meters_per_unit = 9/4
    with raises(ValueError): context.listener.meters_per_unit = 0
    context.listener.meters_per_unit = inf
    with raises(ValueError): context.listener.meters_per_unit = -1
    with raises(AttributeError): context.listener.meters_per_unit