-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from Nicks57/master
Improvement of percent calculation
- Loading branch information
Showing
2 changed files
with
36 additions
and
1 deletion.
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
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,34 @@ | ||
"""Test for Position class.""" | ||
import unittest | ||
|
||
from pyvlx import Parameter, Position | ||
|
||
|
||
class TestParameterPosition(unittest.TestCase): | ||
"""Test class for Position class.""" | ||
|
||
def test_to_percent(self): | ||
"""Test position percent output from position int input""" | ||
|
||
self.assertEqual(Position.to_percent(Parameter.from_int(0)), 0) | ||
self.assertEqual(Position.to_percent(Parameter.from_int(1)), 0) | ||
self.assertEqual(Position.to_percent(Parameter.from_int(3)), 0) | ||
self.assertEqual(Position.to_percent(Parameter.from_int(256)), 1) | ||
self.assertEqual(Position.to_percent(Parameter.from_int(512)), 1) | ||
self.assertEqual(Position.to_percent(Parameter.from_int(5120)), 10) | ||
self.assertEqual(Position.to_percent(Parameter.from_int(12800)), 25) | ||
self.assertEqual(Position.to_percent(Parameter.from_int(25600)), 50) | ||
self.assertEqual(Position.to_percent(Parameter.from_int(38400)), 75) | ||
self.assertEqual(Position.to_percent(Parameter.from_int(50688)), 99) | ||
self.assertEqual(Position.to_percent(Parameter.from_int(51050)), 100) | ||
self.assertEqual(Position.to_percent(Parameter.from_int(51200)), 100) | ||
|
||
def test_from_to_percent(self): | ||
"""Test position percent output from position percent input""" | ||
self.assertEqual(Position.to_percent(Position.from_percent(0)), 0) | ||
self.assertEqual(Position.to_percent(Position.from_percent(1)), 1) | ||
self.assertEqual(Position.to_percent(Position.from_percent(25)), 25) | ||
self.assertEqual(Position.to_percent(Position.from_percent(50)), 50) | ||
self.assertEqual(Position.to_percent(Position.from_percent(75)), 75) | ||
self.assertEqual(Position.to_percent(Position.from_percent(99)), 99) | ||
self.assertEqual(Position.to_percent(Position.from_percent(100)), 100) |