From 5938cc7875904b0fc801063f8d8162d7d3f842cb Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Fri, 7 Dec 2018 08:10:15 +0100 Subject: [PATCH] Feat(API): throw basis of api maht object (token) --- mapytex/calculus/API/tokens/number.py | 84 +++++++++++++++++++++++ mapytex/calculus/API/tokens/polynomial.py | 50 ++++++++++++++ mapytex/calculus/API/tokens/token.py | 32 +++++++++ 3 files changed, 166 insertions(+) create mode 100644 mapytex/calculus/API/tokens/number.py create mode 100644 mapytex/calculus/API/tokens/polynomial.py create mode 100644 mapytex/calculus/API/tokens/token.py diff --git a/mapytex/calculus/API/tokens/number.py b/mapytex/calculus/API/tokens/number.py new file mode 100644 index 0000000..b3b212b --- /dev/null +++ b/mapytex/calculus/API/tokens/number.py @@ -0,0 +1,84 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 +# +# Copyright © 2017 lafrite +# +# Distributed under terms of the MIT license. + +""" +Tokens representing interger and decimal + +""" +from .token import Token +from ...core.MO import MOnumber, MOFraction +from decimal import Decimal as _Decimal + +__all__ = ["Integer", "Decimal"] + +class Integer(Token): + + """ Token representing a integer """ + + def __init__(self, mo, name=""): + if not isinstance(mo, MOnumber): + raise TypeError + if not isinstance(mo.value, int): + raise TypeError + + Token.__init__(self, mo, name) + self._mathtype = 'entier' + + @classmethod + def random(cls): + raise NotImplemented + +class Decimal(Token): + + """ Token representing a decimal """ + + def __init__(self, mo, name=""): + if not isinstance(mo, MOnumber): + raise TypeError + if not isinstance(mo.value, _Decimal): + raise TypeError + + Token.__init__(self, mo, name) + self._mathtype = 'décimal' + + @classmethod + def random(cls): + raise NotImplemented + +class Fraction(Token): + + """ Token representing a fraction """ + + def __init__(self, mo, name=""): + if not isinstance(mo, MOFraction): + raise TypeError + if not isinstance(mo._numerator, MOnumber): + raise TypeError + if not isinstance(mo._denominator, MOnumber): + raise TypeError + + Token.__init__(self, mo, name) + self._mathtype = 'fraction' + + @classmethod + def random(cls): + raise NotImplemented + + @property + def numerator(self): + return self._mo.numerator + + @property + def denominator(self): + return self._mo.denominator + + +# ----------------------------- +# Reglages pour 'vim' +# vim:set autoindent expandtab tabstop=4 shiftwidth=4: +# cursor: 16 del diff --git a/mapytex/calculus/API/tokens/polynomial.py b/mapytex/calculus/API/tokens/polynomial.py new file mode 100644 index 0000000..e1764ff --- /dev/null +++ b/mapytex/calculus/API/tokens/polynomial.py @@ -0,0 +1,50 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 +# +# Copyright © 2017 lafrite +# +# Distributed under terms of the MIT license. + +""" +Tokens representing interger and decimal + +""" +from .token import Token + +__all__ = ["Polynomial", "Quadratic", "Linear"] + +class Polynomial(Token): + + """ Token representing a polynomial """ + + def __init__(self, mo, name=""): + if not isinstance(mo, MOpolynomial): + raise TypeError + if not isinstance(mo.value, int): + raise TypeError + + Token.__init__(self, mo, name) + self._mathtype = 'polynome' + + @classmethod + def random(cls): + raise NotImplemented + + def __setitem__(self, key, item): + """ Use Polynomial like if they were a dictionnary to set coefficients """ + pass + + def __getitem__(self, key): + """ Use Polynomial like if they were a dictionnary to get coefficients """ + pass + + def __call__(self, value): + """ Call a Polynomial to evaluate itself on value """ + pass + + +# ----------------------------- +# Reglages pour 'vim' +# vim:set autoindent expandtab tabstop=4 shiftwidth=4: +# cursor: 16 del diff --git a/mapytex/calculus/API/tokens/token.py b/mapytex/calculus/API/tokens/token.py new file mode 100644 index 0000000..7eda189 --- /dev/null +++ b/mapytex/calculus/API/tokens/token.py @@ -0,0 +1,32 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 +# +# Copyright © 2017 lafrite +# +# Distributed under terms of the MIT license. + +""" +Tokens: practical envelop of math object + +""" + +class Token(object): + + """ Token: practical envelop of an math object """ + + def __init__(self, mo, name=""): + self._mo = mo + self.name = name + self._mathtype = None + + @classmethod + def random(cls): + raise NotImplemented + + + +# ----------------------------- +# Reglages pour 'vim' +# vim:set autoindent expandtab tabstop=4 shiftwidth=4: +# cursor: 16 del