-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for submodule
animation.controllers
- Loading branch information
1 parent
ea353ba
commit 8cdc365
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# pylint: disable=missing-module-docstring | ||
# pylint: disable=missing-class-docstring | ||
# pylint: disable=missing-function-docstring | ||
|
||
import math | ||
import unittest | ||
|
||
from tkintertools.animation import controllers | ||
|
||
|
||
class Test(unittest.TestCase): | ||
|
||
def test_flat(self) -> None: | ||
self.assertEqual(controllers.flat(0), 0) | ||
self.assertEqual(controllers.flat(0.618), 0.618) | ||
self.assertEqual(controllers.flat(1), 1) | ||
|
||
def test_smooth(self) -> None: | ||
self.assertEqual(controllers.smooth(0), 0) | ||
self.assertEqual(controllers.smooth(1), 1) | ||
self.assertAlmostEqual(controllers.smooth(1/4), 1/2 - math.sqrt(2)/4) | ||
self.assertAlmostEqual(controllers.smooth(2/4), 1/2) | ||
self.assertAlmostEqual(controllers.smooth(3/4), 1/2 + math.sqrt(2)/4) | ||
|
||
def test_rebound(self) -> None: | ||
self.assertEqual(controllers.rebound(0), 0) | ||
self.assertEqual(controllers.rebound(1), 1) | ||
self.assertAlmostEqual(controllers.rebound(1/4), 0.5639150830548166) | ||
self.assertAlmostEqual(controllers.rebound(2/4), 0.9800394839160321) | ||
self.assertAlmostEqual(controllers.rebound(3/4), 1.1393154544781496) | ||
|
||
def test_controller_generator(self) -> None: | ||
func_1 = controllers.controller_generator( | ||
lambda x: x, 233, 666, map_y=False) | ||
self.assertEqual(func_1(0), 233) | ||
self.assertEqual(func_1(1), 666) | ||
|
||
func_2 = controllers.controller_generator( | ||
math.sin, 0, math.pi, map_y=False) | ||
self.assertAlmostEqual(func_2(0), 0) | ||
self.assertAlmostEqual(func_2(1), 0) | ||
self.assertAlmostEqual(func_2(1/2), 1) | ||
self.assertAlmostEqual(func_2(2), 0) | ||
|
||
func_3 = controllers.controller_generator(lambda x: x, 233, 666) | ||
self.assertAlmostEqual(func_3(0), 233/666) | ||
self.assertAlmostEqual(func_3(0.618), (233 + 0.618*(666-233)) / 666) | ||
self.assertAlmostEqual(func_3(1), 1) | ||
|
||
self.assertWarns(UserWarning, controllers.controller_generator, | ||
math.sin, math.pi, math.tau) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |