def test_core_numbers(): for c in (Catalan, Catalan(), ComplexInfinity, ComplexInfinity(), EulerGamma, EulerGamma(), Exp1, Exp1(), GoldenRatio, GoldenRatio(), Half, Half(), ImaginaryUnit, ImaginaryUnit(), Infinity, Infinity(), Integer, Integer(2), NaN, NaN(), NegativeInfinity, NegativeInfinity(), NegativeOne, NegativeOne(), Number, Number(15), NumberSymbol, NumberSymbol(), One, One(), Pi, Pi(), Rational, Rational(1,2), Real, Real("1.2"), Zero, Zero()): check(c)
def _maybe_add_plusses(as_text): """ >>> Kalkylation._maybe_add_plusses("1 2.0\\n3") '1+2.0+3' >>> Kalkylation._maybe_add_plusses("1 + 2\\n3") '1 + 2 3' """ parts = as_text.split() try: [Number(part) for part in parts] as_text = "+".join(parts) except SympifyError: as_text = ' '.join(parts) return as_text
def map_answer_expr(questions, question_id, answer): """ Map an answer value to a sympy expression. Depending on the the question class we return an appropriate sympy expression. This will be a Number, True, False, or a symbol. If the answer was empty, we do not return a sympy expression, but None, or if the question_type is 'Number', then 0. """ question_type = get_question_type(question_id, questions) if question_type == 'Boolean': return True if answer == 'Y' else False if question_type == 'Number' and answer == '': return 0 try: number = float(answer) return Number(number) except: # text answer if answer == '' or answer is None: return None else: return sympy.symbols(str(answer))
def test_sympy__core__numbers__Number(): from sympy.core.numbers import Number assert _test_args(Number(1, 7))