<s> from __future__ import division <EOL> from sympy . physics . unitsystems . units import Unit <EOL> from sympy . physics . unitsystems . systems . mks import length , time <EOL> from sympy . physics . unitsystems . prefixes import PREFIXES <EOL> from sympy . utilities . pytest import raises <EOL> k = PREFIXES [ '<STR_LIT:k>' ] <EOL> def test_definition ( ) : <EOL> u = Unit ( length , factor = <NUM_LIT:10> , abbrev = "<STR_LIT>" ) <EOL> assert u . dim == length <EOL> assert u . _factor == <NUM_LIT:10> <EOL> assert u . _abbrev == "<STR_LIT>" <EOL> assert u . prefix is None <EOL> km = Unit ( length , prefix = k ) <EOL> assert km . prefix == k <EOL> v = Unit ( u , factor = <NUM_LIT:5> ) <EOL> assert v . dim == length <EOL> assert v . _factor == <NUM_LIT:5> * <NUM_LIT:10> <EOL> def test_error_definition ( ) : <EOL> raises ( TypeError , lambda : Unit ( "<STR_LIT:m>" ) ) <EOL> def test_factor ( ) : <EOL> u = Unit ( length , factor = <NUM_LIT:10> , abbrev = "<STR_LIT>" ) <EOL> assert u . factor == <NUM_LIT:10> <EOL> u = Unit ( length , factor = <NUM_LIT:5> , prefix = k ) <EOL> assert u . factor == <NUM_LIT> <EOL> def test_abbrev ( ) : <EOL> u = Unit ( length ) <EOL> assert u . abbrev == "<STR_LIT>" <EOL> u = Unit ( length , abbrev = "<STR_LIT:m>" ) <EOL> assert u . abbrev == "<STR_LIT:m>" <EOL> u = Unit ( length , abbrev = "<STR_LIT:m>" , prefix = k ) <EOL> assert u . abbrev == "<STR_LIT>" <EOL> def test_abbrev_dim ( ) : <EOL> u = Unit ( length , factor = <NUM_LIT:10> ) <EOL> assert u . abbrev_dim == "<STR_LIT>" <EOL> def test_str ( ) : <EOL> u = Unit ( length , factor = <NUM_LIT:10> ) <EOL> assert str ( u ) == u . abbrev_dim <EOL> u = Unit ( length , factor = <NUM_LIT:10> , abbrev = "<STR_LIT:m>" ) <EOL> assert str ( u ) == "<STR_LIT:m>" <EOL> def test_repr ( ) : <EOL> u = Unit ( length , factor = <NUM_LIT:10> , abbrev = "<STR_LIT:m>" ) <EOL> assert repr ( u ) == u . abbrev_dim <EOL> def test_eq ( ) : <EOL> u = Unit ( length , factor = <NUM_LIT:10> , abbrev = "<STR_LIT>" ) <EOL> v = Unit ( length , factor = <NUM_LIT:10> ) <EOL> assert ( u == v ) is True <EOL> v = Unit ( time , factor = <NUM_LIT:10> , abbrev = "<STR_LIT>" ) <EOL> assert ( u == v ) is False <EOL> v = Unit ( length , factor = <NUM_LIT:1> , abbrev = "<STR_LIT>" ) <EOL> assert ( u == v ) is False <EOL> def test_add_sub ( ) : <EOL> u = Unit ( length , factor = <NUM_LIT:10> ) <EOL> v = Unit ( length , factor = <NUM_LIT:5> ) <EOL> w = Unit ( time , factor = <NUM_LIT:2> ) <EOL> assert u . add ( v ) == Unit ( length , factor = <NUM_LIT:15> ) <EOL> assert u . sub ( v ) == Unit ( length , factor = <NUM_LIT:5> ) <EOL> raises ( ValueError , lambda : u . add ( w ) ) <EOL> raises ( ValueError , lambda : u . sub ( w ) ) <EOL> raises ( TypeError , lambda : u . add ( <NUM_LIT:1> ) ) <EOL> raises ( TypeError , lambda : u . sub ( <NUM_LIT:1> ) ) <EOL> def test_pow ( ) : <EOL> u = Unit ( length , factor = <NUM_LIT:10> ) <EOL> assert u . pow ( <NUM_LIT:0> ) == <NUM_LIT:1> <EOL> assert u . pow ( <NUM_LIT:1> ) == u <EOL> assert u . pow ( <NUM_LIT:2> ) == Unit ( length . pow ( <NUM_LIT:2> ) , factor = <NUM_LIT:100> ) <EOL> assert u . pow ( - <NUM_LIT:1> ) == Unit ( length . pow ( - <NUM_LIT:1> ) , factor = <NUM_LIT:0.1> ) <EOL> def test_mul ( ) : <EOL> u = Unit ( length , factor = <NUM_LIT:10> ) <EOL> assert u . mul ( <NUM_LIT:1> ) == u <EOL> assert u . mul ( Unit ( time , factor = <NUM_LIT:2> ) ) == Unit ( length . mul ( time ) , factor = <NUM_LIT:20> ) <EOL> assert u . mul ( Unit ( length . pow ( - <NUM_LIT:1> ) , factor = <NUM_LIT:2> ) ) == <NUM_LIT:20> <EOL> def test_div ( ) : <EOL> u = Unit ( length , factor = <NUM_LIT:10> ) <EOL> assert u . rdiv ( <NUM_LIT:1> ) == u . pow ( - <NUM_LIT:1> ) <EOL> assert u . div ( <NUM_LIT:1> ) == u <EOL> assert u . div ( Unit ( time , factor = <NUM_LIT:2> ) ) == Unit ( length . div ( time ) , factor = <NUM_LIT:5> ) <EOL> assert u . div ( Unit ( length , factor = <NUM_LIT:2> ) ) == <NUM_LIT:5> <EOL> def test_is_compatible ( ) : <EOL> u = Unit ( length , factor = <NUM_LIT:10> ) <EOL> assert u . is_compatible ( Unit ( length ) ) is True <EOL> assert u . is_compatible ( Unit ( time ) ) is False <EOL> assert u . is_compatible ( <NUM_LIT:2> ) is False <EOL> def test_as_quantity ( ) : <EOL> from sympy . physics . unitsystems . quantities import Quantity <EOL> u = Unit ( length , factor = <NUM_LIT:10> ) <EOL> q = Quantity ( <NUM_LIT:10> , Unit ( length ) ) <EOL> assert u . as_quantity == q </s>
