Skip to content

Commit

Permalink
add Quantity.parse function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mayya-bondarevskaya committed Jul 10, 2017
1 parent c4a2046 commit 06866cd
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pyqn/tests/test_quantity.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import unittest
from ..quantity import Quantity, QuantityError
from ..dimensions import Dimensions, d_energy
from ..units import UnitsError
from ..units import UnitsError, Units

class QuantityManipulations(unittest.TestCase):
def test_quantity_init(self):
pass

def test_quantity_parse(self):
q1 = Quantity.parse("a = 10 m/s")
q2 = Quantity.parse("lambda = 300.15(10) nm")
q3 = Quantity.parse("1e5 J")

self.assertEqual(q1.name, 'a')
self.assertEqual(q1.value, 10)
self.assertEqual(q1.units, Units('m.s-1'))

self.assertEqual(q2.name, 'lambda')
self.assertEqual(q2.value, 300.15)
self.assertEqual(q2.sd, 0.1)
self.assertEqual(q2.units, Units('nm'))

self.assertEqual(q3.value, 1e5)
self.assertEqual(q3.units, Units('J'))

def test_quantity_multiplication(self):
q1 = Quantity(value=22.4,units='m/s')
q2 = Quantity(value=2,units='s')
Expand Down Expand Up @@ -88,4 +105,4 @@ def test_quantity_html(self):
self.assertEqual(q4.html_str, '22.4 m s<sup>-1</sup>')

if __name__ == '__main__':
unittest.main()
unittest.main()

0 comments on commit 06866cd

Please sign in to comment.