-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtestMathf.py
More file actions
42 lines (34 loc) · 1.29 KB
/
testMathf.py
File metadata and controls
42 lines (34 loc) · 1.29 KB
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
## Copyright (c) 2020-2023 The PyUnity Team
## This file is licensed under the MIT License.
## See https://docs.pyunity.x10.bz/en/latest/license.html
from pyunity import Mathf
from . import TestCase, almostEqual
import math
class TestFunctions(TestCase):
def testClamp(self):
assert Mathf.Clamp(0.5, 0, 1) == 0.5
assert Mathf.Clamp(0, 0, 1) == 0
assert Mathf.Clamp(2, 0, 1) == 1
assert Mathf.Clamp01(3) == 1
assert Mathf.Clamp01(-3) == 0
assert Mathf.Clamp01(0.25) == 0.25
def testDeltaAngle(self):
assert Mathf.DeltaAngle(-50, 365) == 55
def testInverseLerp(self):
assert Mathf.InverseLerp(0.5, 0, 2) == 0.25
assert Mathf.InverseLerp(-1, 2, 3) == 0
def testLerp(self):
assert Mathf.Lerp(0.5, 0, 2) == 1
assert Mathf.Lerp(2, 2, 3) == 3
assert Mathf.LerpUnclamped(2, 2, 3) == 4
def testSign(self):
assert Mathf.Sign(-2) == -1
assert Mathf.Sign(6) == 1
assert Mathf.Sign(0) == 0
def testSmoothStep(self):
assert almostEqual(Mathf.SmoothStep(0.5), 0.5)
assert Mathf.SmoothStep(0) == 0
assert Mathf.SmoothStep(1) == 1
def testSmoothDamp(self):
damper = Mathf.SmoothDamper(0.1)
damper.SmoothDamp(0, 10, 3, 0.1) # only for coverage