Fix: fraction rendering
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
cbcead48f7
commit
78ce8f767a
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from .calculus import Expression, Integer, Decimal, random_list, render, Polynomial
|
||||
from .calculus import Expression, Integer, Decimal, random_list, render, Polynomial, Fraction
|
||||
|
||||
# Expression.set_render('tex')
|
||||
|
||||
|
@ -123,11 +123,11 @@ x^7
|
||||
- 2x^2 + 7x - 6
|
||||
"""
|
||||
|
||||
from .renders import render
|
||||
from .expression import Expression
|
||||
from .tokens import Token
|
||||
from .tokens.polynomial import Polynomial
|
||||
from .tokens.number import Integer, Decimal, Fraction
|
||||
from .renders import render
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -29,6 +29,10 @@ class Render(object):
|
||||
else:
|
||||
raise ValueError("This render name already exists")
|
||||
|
||||
@property
|
||||
def render_name(self):
|
||||
return self._render
|
||||
|
||||
@property
|
||||
def render(self):
|
||||
return self.renders[self._render]
|
||||
|
@ -141,7 +141,7 @@ class Decimal(Token):
|
||||
|
||||
class Fraction(Token):
|
||||
|
||||
""" Token representing a fraction
|
||||
""" Token representing a fraction of numbers
|
||||
|
||||
:example:
|
||||
>>> Fraction("3/4")
|
||||
|
@ -54,10 +54,16 @@ class Token(object):
|
||||
yield self
|
||||
|
||||
def __repr__(self):
|
||||
return f"<{self.__class__.__name__} {render(self._mo, 'txt')}>"
|
||||
try:
|
||||
return f"<{self.__class__.__name__} {render(self._mo._tree, 'txt')}>"
|
||||
except AttributeError:
|
||||
return f"<{self.__class__.__name__} {render(self._mo, 'txt')}>"
|
||||
|
||||
def __str__(self):
|
||||
return render(self._mo)
|
||||
try:
|
||||
return render(self._mo._tree)
|
||||
except AttributeError:
|
||||
return render(self._mo)
|
||||
|
||||
@property
|
||||
def raw(self):
|
||||
|
@ -30,7 +30,7 @@ Expression is the classe wich handle all calculus. It can randomly generate or i
|
||||
|
||||
"""
|
||||
|
||||
from .API import Expression, Integer, Decimal, render, Polynomial
|
||||
from .API import Expression, Integer, Decimal, render, Polynomial, Fraction
|
||||
from .core import random_list
|
||||
from decimal import getcontext
|
||||
#getcontext().prec = 2
|
||||
|
0
test/__init__.py
Normal file
0
test/__init__.py
Normal file
31
test/calculus/core/test_render.py
Normal file
31
test/calculus/core/test_render.py
Normal file
@ -0,0 +1,31 @@
|
||||
import mapytex
|
||||
|
||||
def test_default_render():
|
||||
assert mapytex.render.render_name == "txt"
|
||||
|
||||
def test_default_rending():
|
||||
e = mapytex.Expression("2*3")
|
||||
assert str(e) == "2*3"
|
||||
|
||||
def test_changing_render():
|
||||
assert mapytex.render.render_name == "txt"
|
||||
mapytex.render.set_render("tex")
|
||||
assert mapytex.render.render_name == "tex"
|
||||
mapytex.render.set_render("txt")
|
||||
assert mapytex.render.render_name == "txt"
|
||||
|
||||
|
||||
def test_changing_rending():
|
||||
e = mapytex.Expression.from_str("2*3")
|
||||
f = mapytex.Fraction("2/3")
|
||||
assert str(e) == "2 * 3"
|
||||
assert str(f) == "2 / 3"
|
||||
mapytex.render.set_render("tex")
|
||||
assert str(e) == "2 \\times 3"
|
||||
assert str(f) == "\\dfrac{2}{3}"
|
||||
mapytex.render.set_render("txt")
|
||||
assert str(e) == "2 * 3"
|
||||
assert str(f) == "2 / 3"
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user