Feat: Remove references to random in API
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Bertrand Benjamin 2021-10-26 19:20:22 +02:00
parent 86d66e8b1b
commit 5fa3682f73
3 changed files with 0 additions and 132 deletions

View File

@ -13,10 +13,8 @@ Tokens representing interger and decimal
from decimal import Decimal as _Decimal
from .token import Token
from ...core.arithmetic import gcd
#from ...core.random.int_gene import filter_random
from ...core.MO import MO, MOnumber
from ...core.MO.fraction import MOFraction
from random import random
__all__ = ["Integer", "Decimal", "Fraction"]
@ -54,23 +52,6 @@ class Integer(Token):
return cls(mo, name, ancestor)
@classmethod
def random(
cls, name="", min_value=-10, max_value=10, rejected=[0, 1], accept_callbacks=[]
):
""" Generate a random Integer
:param name: name of the Integer
:param min_value: minimum value
:param max_value: maximum value
:param rejected: rejected values
:param accept_callbacks: list of function for value acceptation
"""
candidate = filter_random(min_value, max_value, rejected, accept_callbacks)
return Integer(candidate, name)
class Decimal(Token):
@ -108,36 +89,6 @@ class Decimal(Token):
return cls(mo, name, ancestor)
@classmethod
def random(
cls,
name="",
min_value=-10,
max_value=10,
digits=2,
rejected=[0, 1],
reject_callbacks=[],
):
""" Generate a random Decimal
:param name: name of the Integer
:param min_value: minimum value
:param max_value: maximum value
:param digits: digits after comas
:param rejected: rejected values
:param reject_callbacks: list of function for value rejection
"""
conditions = [lambda x: x in rejected] + reject_callbacks
float_cand = (max_value - min_value) * random() + min_value
candidate = _Decimal(f"{float_cand:.{digits}f}")
while any(c(candidate) for c in conditions):
float_cand = (max_value - min_value) * random() + min_value
candidate = _Decimal(f"{float_cand:.{digits}f}")
return Decimal(candidate, name)
class Fraction(Token):
@ -172,69 +123,6 @@ class Fraction(Token):
return cls(mo, name, ancestor)
@classmethod
def random(
cls,
name="",
fix_num="",
min_num=-10,
max_num=10,
rejected_num=[0],
accept_num_callbacks=[],
fix_denom="",
min_denom=-10,
max_denom=10,
rejected_denom=[0, 1, -1],
accept_denom_callbacks=[],
irreductible=False,
not_integer=True,
):
""" Generate a random Fraction
:param name: Name of the fraction
:param fix_num: if set, the numerator will get this value
:param min_num: minimum value for the numerator
:param max_num: maximum value for the numerator
:param rejected_num: rejected values for the numerator
:param accept_num_callbacks: list of function for numerator rejection
:param fix_denom: if set, the denomerator will get this value
:param min_denom: minimum value for the denominator
:param max_denom: maximum value for the denominator
:param rejected_denom: rejected values for the denominator
:param accept_denom_callbacks: list of function for denomerator rejection
:param irreductible: is the generated fraction necessary irreductible
:param not_integer: can the generated fraction be egal to an interger
"""
if fix_num == "":
num = filter_random(min_num, max_num, rejected_num, accept_num_callbacks)
else:
num = fix_num
if fix_denom == "":
accept_callbacks = accept_denom_callbacks
if irreductible:
def prime_with_num(denom):
return gcd(num, denom) == 1
accept_callbacks.append(prime_with_num)
if not_integer:
def not_divise_num(denom):
return num % denom != 0
accept_callbacks.append(not_divise_num)
denom = filter_random(
min_denom, max_denom, rejected_denom, accept_callbacks
)
else:
denom = fix_denom
frac = MOFraction(num, denom)
return cls(frac, name)
@property
def numerator(self):
""" Get numerator of the fraction

View File

@ -61,10 +61,6 @@ class Polynomial(Token):
"""
return cls(MOpolynomial(variable_name, coefficients), name)
@classmethod
def random(cls):
raise NotImplementedError
@property
def raw(self):
raise NotImplementedError("Polynomial does not exists in python")
@ -171,10 +167,6 @@ class Linear(Polynomial):
Polynomial.__init__(self, mo, name, ancestor)
self._mathtype = "affine"
@classmethod
def random(cls):
raise NotImplementedError
@property
@to_be_token
def a(self):
@ -258,10 +250,6 @@ class Quadratic(Polynomial):
Polynomial.__init__(self, mo, name, ancestor)
self._mathtype = "polynome du 2nd degré"
@classmethod
def random(cls):
raise NotImplementedError
@property
@to_be_token
def a(self):

View File

@ -24,14 +24,6 @@ class Token(object):
self._mathtype = None
self._ancestor = ancestor
@classmethod
def random(
cls,
family="integer",
**kwds
):
raise NotImplemented
def explain(self):
""" Yield every calculus step which have lead to self