def check_unit_conversions2(): tu = get_types_universe() A = make_rcompunit('mph') B = make_rcompunit('m/s') assert not A == B tu.check_leq(A, B) tu.check_leq(B, A) assert not tu.equal(A, B) B_from_A, A_from_B = tu.get_embedding(A, B) print('B_from_A: %s' % B_from_A) print('A_from_B: %s' % A_from_B) tu.check_equal(B_from_A.dom, A) tu.check_equal(B_from_A.cod, B) tu.check_equal(A_from_B.dom, B) tu.check_equal(A_from_B.cod, A) print('B_from_A: %s a=1.0 B_from_A(1.0) = %s' % (B_from_A, B_from_A(1.0))) assert_allclose(B_from_A(1.0), ONE_MPH_IN_M_S) assert_allclose(A_from_B(ONE_MPH_IN_M_S), 1.0) ndp = parse_ndp(""" mcdp { provides a [m/s] provides b [mph] requires c [m/s] requires d [mph] c >= a + b d >= a + b } """) print ndp.repr_long() dp = ndp.get_dp() print dp.repr_long() cases = ( ((0.0, 1.0), (ONE_MPH_IN_M_S, 1.0)), ((1.0, 0.0), (1.0, 1.0 / ONE_MPH_IN_M_S)), ) for func, expected in cases: print('func: %s F = %s' % (str(func), dp.get_fun_space())) print('expected: %s' % str(expected)) r = dp.solve(func) print('obtained: %s %s' % (str(r), dp.get_res_space())) limit = list(r.minimals)[0] assert_allclose(limit, expected)
def eval_space_rcompunit(r, context): # @UnusedVariable check_isinstance(r, CDP.RcompUnit) from mcdp_posets.rcomp_units import make_rcompunit if r.pint_string == 'R': msg ='Please use "dimensionless" rather than "R".' warn_language(r, MCDPWarnings.LANGUAGE_CONSTRUCT_DEPRECATED, msg, context) return make_rcompunit(r.pint_string)
def eval_space_rcompunit(r, context): # @UnusedVariable check_isinstance(r, CDP.RcompUnit) from mcdp_posets.rcomp_units import make_rcompunit # # TODO: remove # if r.pint_string == 'R': # pragma: no cover # msg ='Please use "dimensionless" rather than "R".' # warn_language(r, MCDPWarnings.LANGUAGE_CONSTRUCT_DEPRECATED, msg, context) return make_rcompunit(r.pint_string)