Merge branch 'master' into data_mean

This commit is contained in:
Luke Weiler
2020-10-17 14:53:14 -04:00
committed by GitHub
7 changed files with 403 additions and 309 deletions

View File

@@ -17,5 +17,7 @@ jobs:
run: | run: |
python -m pip install -U pip python -m pip install -U pip
python -m pip install -r dev-requirements.txt python -m pip install -r dev-requirements.txt
- name: Linter
run: make lint
- name: Test - name: Test
run: make test run: make test

View File

@@ -1,2 +1,7 @@
FLAKE_FLAGS = --ignore=E501,F401,F403,F405
lint:
python -m flake8 $(FLAKE_FLAGS)
test: test:
python -m pytest --verbose -s tests python -m pytest --verbose -s tests

View File

@@ -78,5 +78,5 @@ problem, solution = mathgen.genById(0)
| 45 | Simple Interest | Simple interest for a principle amount of 6128 dollars, 5% rate of interest and for a time period of 5 years is = | 1532.0 | simpleInterest | | 45 | Simple Interest | Simple interest for a principle amount of 6128 dollars, 5% rate of interest and for a time period of 5 years is = | 1532.0 | simpleInterest |
| 46 | Multiplication of two matrices | Multiply [[-20, -14, -88, -62, 39, 94, 21, 75, 26], [89, -67, -80, -60, 32, -23, -79, 11, -69], [13, -75, -66, 3, 67, -79, -49, 6, 36], [-44, -84, 68, -27, -86, -95, -71, -77, -62], [45, 58, 89, 82, 30, -83, -23, 51, 95], [11, 46, 100, -15, 60, -34, 85, 50, -44], [93, -100, -62, 63, -73, -64, 90, -15, 23], [-8, 91, -22, 53, -42, 25, 32, -26, 31], [-60, 90, 75, -42, 19, 33, -30, 74, 13]] and [[-80, 54, -39, 37, -99], [31, -28, -31, 64, 73], [-21, -34, -28, -21, -76], [-94, 55, 66, 0, 17], [-28, 25, -65, -74, 100], [76, 74, -96, -98, -5], [-90, -70, -66, -71, -35], [65, 49, -100, 72, -23], [-95, -97, -31, -84, -86]] | [[15409, 6508, -21665, -10161, 5326], [9859, 17962, 3267, 12768, 3119], [-8761, 1272, 8611, 738, 3881], [4489, -5790, 29652, 11947, -5940], [-22167, -8208, -1142, 6747, -10714], [-4628, -5167, -15527, 1404, 243], [-29240, -2432, 11103, 615, -22487], [-5498, -5038, 1462, -100, 2495], [18214, -3238, -15548, 3691, 6061]] | matrixMultiplication | | 46 | Multiplication of two matrices | Multiply [[-20, -14, -88, -62, 39, 94, 21, 75, 26], [89, -67, -80, -60, 32, -23, -79, 11, -69], [13, -75, -66, 3, 67, -79, -49, 6, 36], [-44, -84, 68, -27, -86, -95, -71, -77, -62], [45, 58, 89, 82, 30, -83, -23, 51, 95], [11, 46, 100, -15, 60, -34, 85, 50, -44], [93, -100, -62, 63, -73, -64, 90, -15, 23], [-8, 91, -22, 53, -42, 25, 32, -26, 31], [-60, 90, 75, -42, 19, 33, -30, 74, 13]] and [[-80, 54, -39, 37, -99], [31, -28, -31, 64, 73], [-21, -34, -28, -21, -76], [-94, 55, 66, 0, 17], [-28, 25, -65, -74, 100], [76, 74, -96, -98, -5], [-90, -70, -66, -71, -35], [65, 49, -100, 72, -23], [-95, -97, -31, -84, -86]] | [[15409, 6508, -21665, -10161, 5326], [9859, 17962, 3267, 12768, 3119], [-8761, 1272, 8611, 738, 3881], [4489, -5790, 29652, 11947, -5940], [-22167, -8208, -1142, 6747, -10714], [-4628, -5167, -15527, 1404, 243], [-29240, -2432, 11103, 615, -22487], [-5498, -5038, 1462, -100, 2495], [18214, -3238, -15548, 3691, 6061]] | matrixMultiplication |
| 47 | Cube Root | cuberoot of 711 upto 2 decimal places is: | 8.93 | CubeRoot | | 47 | Cube Root | cuberoot of 711 upto 2 decimal places is: | 8.93 | CubeRoot |
| 48 | Power Rule Integration | 3x^1 | (3/1)x^2 + c | powerRuleIntegration | | 48 | Power Rule Integration | 3x^1 | (3/2)x^2 + c | powerRuleIntegration |
| 49 | Fourth Angle of Quadrilateral | Fourth angle of quadrilateral with angles 94 , 101, 102 = | 63 | fourthAngleOfQuadrilateral | | 49 | Fourth Angle of Quadrilateral | Fourth angle of quadrilateral with angles 94 , 101, 102 = | 63 | fourthAngleOfQuadrilateral |

View File

@@ -1,2 +1,3 @@
pytest pytest
hypothesis hypothesis
flake8

25
makeReadme.py Normal file
View File

@@ -0,0 +1,25 @@
#To use, paste at bottom of mathgen.py code, change line variable and remove all table rows in README.md except for the top 2 and run mathgen.py
wList = getGenList()
allRows = []
f=open('mathgen.py')
lines=f.readlines()
line = 720 #This has to be changed depending on which line the first generator appears on
for item in wList:
myGen = item[2]
prob, sol = myGen()
prob = str(prob).rstrip("\n")
sol = str(sol).rstrip("\n")
instName = lines[line]
def_name = instName[:instName.find('=')].strip()
row = [myGen.id, myGen.title, prob, sol, def_name]
line+=1
allRows.append(row)
g=open('../README.md', "a")
for row in allRows:
tableLine = "| " + str(row[0]) + " | " + str(row[1]) + " | " + str(row[2]) + " | " + str(row[3]) + " | " + str(row[4]) + " |\n"
g.write(tableLine)
g.close()
print("New README.md table generated")

View File

@@ -4,6 +4,7 @@ import fractions
genList = [] genList = []
# || Generator class # || Generator class
class Generator: class Generator:
def __init__(self, title, id, generalProb, generalSol, func): def __init__(self, title, id, generalProb, generalSol, func):
@@ -20,16 +21,19 @@ class Generator:
def __call__(self, **kwargs): def __call__(self, **kwargs):
return self.func(**kwargs) return self.func(**kwargs)
# || Non-generator Functions # || Non-generator Functions
def genById(id): def genById(id):
generator = genList[id][2] generator = genList[id][2]
return(generator()) return(generator())
def getGenList(): def getGenList():
return(genList) return(genList)
# || Generator Functions # || Generator Functions
def additionFunc(maxSum=99, maxAddend=50): def additionFunc(maxSum=99, maxAddend=50):
a = random.randint(0, maxAddend) a = random.randint(0, maxAddend)
b = random.randint(0, min((maxSum - a), maxAddend)) # The highest value of b will be no higher than the maxsum minus the first number and no higher than the maxAddend as well b = random.randint(0, min((maxSum - a), maxAddend)) # The highest value of b will be no higher than the maxsum minus the first number and no higher than the maxAddend as well
@@ -38,6 +42,7 @@ def additionFunc(maxSum = 99, maxAddend = 50):
solution = str(c) solution = str(c)
return problem, solution return problem, solution
def subtractionFunc(maxMinuend=99, maxDiff=99): def subtractionFunc(maxMinuend=99, maxDiff=99):
a = random.randint(0, maxMinuend) a = random.randint(0, maxMinuend)
b = random.randint(max(0, (a - maxDiff)), a) b = random.randint(max(0, (a - maxDiff)), a)
@@ -46,6 +51,7 @@ def subtractionFunc(maxMinuend = 99, maxDiff = 99):
solution = str(c) solution = str(c)
return problem, solution return problem, solution
def multiplicationFunc(maxRes=99, maxMulti=99): def multiplicationFunc(maxRes=99, maxMulti=99):
a = random.randint(0, maxMulti) a = random.randint(0, maxMulti)
b = random.randint(0, min(int(maxMulti / a), maxRes)) b = random.randint(0, min(int(maxMulti / a), maxRes))
@@ -54,6 +60,7 @@ def multiplicationFunc(maxRes = 99, maxMulti = 99):
solution = str(c) solution = str(c)
return problem, solution return problem, solution
def divisionFunc(maxRes=99, maxDivid=99): def divisionFunc(maxRes=99, maxDivid=99):
a = random.randint(0, maxDivid) a = random.randint(0, maxDivid)
b = random.randint(0, min(maxRes, maxDivid)) b = random.randint(0, min(maxRes, maxDivid))
@@ -62,6 +69,7 @@ def divisionFunc(maxRes = 99, maxDivid = 99):
solution = str(c) solution = str(c)
return problem, solution return problem, solution
def binaryComplement1sFunc(maxDigits=10): def binaryComplement1sFunc(maxDigits=10):
question = '' question = ''
answer = '' answer = ''
@@ -74,6 +82,7 @@ def binaryComplement1sFunc(maxDigits = 10):
solution = answer solution = answer
return problem, solution return problem, solution
def moduloFunc(maxRes=99, maxModulo=99): def moduloFunc(maxRes=99, maxModulo=99):
a = random.randint(0, maxModulo) a = random.randint(0, maxModulo)
b = random.randint(0, min(maxRes, maxModulo)) b = random.randint(0, min(maxRes, maxModulo))
@@ -82,6 +91,7 @@ def moduloFunc(maxRes = 99, maxModulo= 99):
solution = str(c) solution = str(c)
return problem, solution return problem, solution
def squareRootFunc(minNo=1, maxNo=12): def squareRootFunc(minNo=1, maxNo=12):
b = random.randint(minNo, maxNo) b = random.randint(minNo, maxNo)
a = b * b a = b * b
@@ -89,6 +99,7 @@ def squareRootFunc(minNo = 1, maxNo = 12):
solution = str(b) solution = str(b)
return problem, solution return problem, solution
def powerRuleDifferentiationFunc(maxCoef=10, maxExp=10, maxTerms=5): def powerRuleDifferentiationFunc(maxCoef=10, maxExp=10, maxTerms=5):
numTerms = random.randint(1, maxTerms) numTerms = random.randint(1, maxTerms)
problem = "" problem = ""
@@ -103,6 +114,7 @@ def powerRuleDifferentiationFunc(maxCoef = 10, maxExp = 10, maxTerms = 5):
solution += str(coefficient * exponent) + "x^" + str(exponent - 1) solution += str(coefficient * exponent) + "x^" + str(exponent - 1)
return problem, solution return problem, solution
def squareFunc(maxSquareNum=20): def squareFunc(maxSquareNum=20):
a = random.randint(1, maxSquareNum) a = random.randint(1, maxSquareNum)
b = a * a b = a * a
@@ -110,6 +122,7 @@ def squareFunc(maxSquareNum = 20):
solution = str(b) solution = str(b)
return problem, solution return problem, solution
def gcdFunc(maxVal=20): def gcdFunc(maxVal=20):
a = random.randint(1, maxVal) a = random.randint(1, maxVal)
b = random.randint(1, maxVal) b = random.randint(1, maxVal)
@@ -120,6 +133,7 @@ def gcdFunc(maxVal=20):
solution = str(x) solution = str(x)
return problem, solution return problem, solution
def lcmFunc(maxVal=20): def lcmFunc(maxVal=20):
a = random.randint(1, maxVal) a = random.randint(1, maxVal)
b = random.randint(1, maxVal) b = random.randint(1, maxVal)
@@ -132,11 +146,13 @@ def lcmFunc(maxVal=20):
solution = str(d) solution = str(d)
return problem, solution return problem, solution
def basicAlgebraFunc(maxVariable=10): def basicAlgebraFunc(maxVariable=10):
a = random.randint(1, maxVariable) a = random.randint(1, maxVariable)
b = random.randint(1, maxVariable) b = random.randint(1, maxVariable)
c = random.randint(b, maxVariable) c = random.randint(b, maxVariable)
# calculate gcd # calculate gcd
def calculate_gcd(x, y): def calculate_gcd(x, y):
while(y): while(y):
x, y = y, x % y x, y = y, x % y
@@ -151,6 +167,7 @@ def basicAlgebraFunc(maxVariable = 10):
solution = x solution = x
return problem, solution return problem, solution
def logFunc(maxBase=3, maxVal=8): def logFunc(maxBase=3, maxVal=8):
a = random.randint(1, maxVal) a = random.randint(1, maxVal)
b = random.randint(2, maxBase) b = random.randint(2, maxBase)
@@ -159,6 +176,7 @@ def logFunc(maxBase=3, maxVal=8):
solution = str(a) solution = str(a)
return problem, solution return problem, solution
def divisionToIntFunc(maxA=25, maxB=25): def divisionToIntFunc(maxA=25, maxB=25):
a = random.randint(1, maxA) a = random.randint(1, maxA)
b = random.randint(1, maxB) b = random.randint(1, maxB)
@@ -168,6 +186,7 @@ def divisionToIntFunc(maxA=25, maxB=25):
solution = int(divisor / dividend) solution = int(divisor / dividend)
return problem, solution return problem, solution
def DecimalToBinaryFunc(max_dec=99): def DecimalToBinaryFunc(max_dec=99):
a = random.randint(1, max_dec) a = random.randint(1, max_dec)
b = bin(a).replace("0b", "") b = bin(a).replace("0b", "")
@@ -175,15 +194,17 @@ def DecimalToBinaryFunc(max_dec=99):
solution = str(b) solution = str(b)
return problem, solution return problem, solution
def BinaryToDecimalFunc(max_dig=10): def BinaryToDecimalFunc(max_dig=10):
problem = '' problem = ''
for i in range(random.randint(1, max_dig)): for i in range(random.randint(1, max_dig)):
temp = str(random.randint(0, 1)) temp = str(random.randint(0, 1))
problem += temp problem += temp
solution=int(problem, 2); solution = int(problem, 2)
return problem, solution return problem, solution
def divideFractionsFunc(maxVal=10): def divideFractionsFunc(maxVal=10):
a = random.randint(1, maxVal) a = random.randint(1, maxVal)
b = random.randint(1, maxVal) b = random.randint(1, maxVal)
@@ -193,6 +214,7 @@ def divideFractionsFunc(maxVal=10):
d = random.randint(1, maxVal) d = random.randint(1, maxVal)
while (c == d): while (c == d):
d = random.randint(1, maxVal) d = random.randint(1, maxVal)
def calculate_gcd(x, y): def calculate_gcd(x, y):
while(y): while(y):
x, y = y, x % y x, y = y, x % y
@@ -208,6 +230,7 @@ def divideFractionsFunc(maxVal=10):
solution = x solution = x
return problem, solution return problem, solution
def multiplyIntToMatrix22(maxMatrixVal=10, maxRes=100): def multiplyIntToMatrix22(maxMatrixVal=10, maxRes=100):
a = random.randint(0, maxMatrixVal) a = random.randint(0, maxMatrixVal)
b = random.randint(0, maxMatrixVal) b = random.randint(0, maxMatrixVal)
@@ -218,6 +241,7 @@ def multiplyIntToMatrix22(maxMatrixVal = 10, maxRes = 100):
solution = f"[[{a*constant},{b*constant}],[{c*constant},{d*constant}]]" solution = f"[[{a*constant},{b*constant}],[{c*constant},{d*constant}]]"
return problem, solution return problem, solution
def areaOfTriangleFunc(maxA=20, maxB=20, maxC=20): def areaOfTriangleFunc(maxA=20, maxB=20, maxC=20):
a = random.randint(1, maxA) a = random.randint(1, maxA)
b = random.randint(1, maxB) b = random.randint(1, maxB)
@@ -228,6 +252,7 @@ def areaOfTriangleFunc(maxA=20, maxB=20, maxC=20):
solution = area solution = area
return problem, solution return problem, solution
def isTriangleValidFunc(maxSideLength=50): def isTriangleValidFunc(maxSideLength=50):
sideA = random.randint(1, maxSideLength) sideA = random.randint(1, maxSideLength)
sideB = random.randint(1, maxSideLength) sideB = random.randint(1, maxSideLength)
@@ -242,6 +267,7 @@ def isTriangleValidFunc(maxSideLength = 50):
solution = "No" solution = "No"
return problem, solution return problem, solution
def MidPointOfTwoPointFunc(maxValue=20): def MidPointOfTwoPointFunc(maxValue=20):
x1 = random.randint(-20, maxValue) x1 = random.randint(-20, maxValue)
y1 = random.randint(-20, maxValue) y1 = random.randint(-20, maxValue)
@@ -251,9 +277,11 @@ def MidPointOfTwoPointFunc(maxValue=20):
solution = f"({(x1+x2)/2},{(y1+y2)/2})" solution = f"({(x1+x2)/2},{(y1+y2)/2})"
return problem, solution return problem, solution
def factoringFunc(range_x1=10, range_x2=10): def factoringFunc(range_x1=10, range_x2=10):
x1 = random.randint(-range_x1, range_x1) x1 = random.randint(-range_x1, range_x1)
x2 = random.randint(-range_x2, range_x2) x2 = random.randint(-range_x2, range_x2)
def intParser(z): def intParser(z):
if (z == 0): if (z == 0):
return "" return ""
@@ -278,6 +306,7 @@ def factoringFunc(range_x1 = 10, range_x2 = 10):
solution = f"(x{x1})(x{x2})" solution = f"(x{x1})(x{x2})"
return problem, solution return problem, solution
def thirdAngleOfTriangleFunc(maxAngle=89): def thirdAngleOfTriangleFunc(maxAngle=89):
angle1 = random.randint(1, maxAngle) angle1 = random.randint(1, maxAngle)
angle2 = random.randint(1, maxAngle) angle2 = random.randint(1, maxAngle)
@@ -286,6 +315,7 @@ def thirdAngleOfTriangleFunc(maxAngle=89):
solution = angle3 solution = angle3
return problem, solution return problem, solution
def systemOfEquationsFunc(range_x=10, range_y=10, coeff_mult_range=10): def systemOfEquationsFunc(range_x=10, range_y=10, coeff_mult_range=10):
# Generate solution point first # Generate solution point first
x = random.randint(-range_x, range_x) x = random.randint(-range_x, range_x)
@@ -331,6 +361,7 @@ def systemOfEquationsFunc(range_x = 10, range_y = 10, coeff_mult_range=10):
# Add random (non-zero) multiple of equations to each other # Add random (non-zero) multiple of equations to each other
def distanceTwoPointsFunc(maxValXY=20, minValXY=-20): def distanceTwoPointsFunc(maxValXY=20, minValXY=-20):
point1X = random.randint(minValXY, maxValXY + 1) point1X = random.randint(minValXY, maxValXY + 1)
point1Y = random.randint(minValXY, maxValXY + 1) point1Y = random.randint(minValXY, maxValXY + 1)
@@ -341,6 +372,7 @@ def distanceTwoPointsFunc(maxValXY = 20, minValXY=-20):
problem = f"Find the distance between ({point1X}, {point1Y}) and ({point2X}, {point2Y})" problem = f"Find the distance between ({point1X}, {point1Y}) and ({point2X}, {point2Y})"
return problem, solution return problem, solution
def pythagoreanTheoremFunc(maxLength=20): def pythagoreanTheoremFunc(maxLength=20):
a = random.randint(1, maxLength) a = random.randint(1, maxLength)
b = random.randint(1, maxLength) b = random.randint(1, maxLength)
@@ -349,6 +381,7 @@ def pythagoreanTheoremFunc(maxLength = 20):
solution = f"{c:.0f}" if c.is_integer() else f"{c:.2f}" solution = f"{c:.0f}" if c.is_integer() else f"{c:.2f}"
return problem, solution return problem, solution
def linearEquationsFunc(n=2, varRange=20, coeffRange=20): def linearEquationsFunc(n=2, varRange=20, coeffRange=20):
if n > 10: if n > 10:
print("[!] n cannot be greater than 10") print("[!] n cannot be greater than 10")
@@ -372,6 +405,7 @@ def linearEquationsFunc(n = 2, varRange = 20, coeffRange = 20):
problem = "\n".join(problem) problem = "\n".join(problem)
return problem, solution return problem, solution
def primeFactorsFunc(minVal=1, maxVal=200): def primeFactorsFunc(minVal=1, maxVal=200):
a = random.randint(minVal, maxVal) a = random.randint(minVal, maxVal)
n = a n = a
@@ -389,6 +423,7 @@ def primeFactorsFunc(minVal=1, maxVal=200):
solution = f"{factors}" solution = f"{factors}"
return problem, solution return problem, solution
def multiplyFractionsFunc(maxVal=10): def multiplyFractionsFunc(maxVal=10):
a = random.randint(1, maxVal) a = random.randint(1, maxVal)
b = random.randint(1, maxVal) b = random.randint(1, maxVal)
@@ -398,6 +433,7 @@ def multiplyFractionsFunc(maxVal=10):
b = random.randint(1, maxVal) b = random.randint(1, maxVal)
while (c == d): while (c == d):
d = random.randint(1, maxVal) d = random.randint(1, maxVal)
def calculate_gcd(x, y): def calculate_gcd(x, y):
while(y): while(y):
x, y = y, x % y x, y = y, x % y
@@ -412,6 +448,7 @@ def multiplyFractionsFunc(maxVal=10):
solution = x solution = x
return problem, solution return problem, solution
def regularPolygonAngleFunc(minVal=3, maxVal=20): def regularPolygonAngleFunc(minVal=3, maxVal=20):
sideNum = random.randint(minVal, maxVal) sideNum = random.randint(minVal, maxVal)
problem = f"Find the angle of a regular polygon with {sideNum} sides" problem = f"Find the angle of a regular polygon with {sideNum} sides"
@@ -419,6 +456,7 @@ def regularPolygonAngleFunc(minVal = 3,maxVal = 20):
solution = 180 - exteriorAngle solution = 180 - exteriorAngle
return problem, solution return problem, solution
def combinationsFunc(maxlength=20): def combinationsFunc(maxlength=20):
def factorial(a): def factorial(a):
@@ -430,13 +468,12 @@ def combinationsFunc(maxlength=20):
a = random.randint(10, maxlength) a = random.randint(10, maxlength)
b = random.randint(0, 9) b = random.randint(0, 9)
solution = int(factorial(a) / (factorial(b) * factorial(a - b))) solution = int(factorial(a) / (factorial(b) * factorial(a - b)))
problem = "Number of combinations from {} objects picked {} at a time ".format(a, b) problem = "Number of combinations from {} objects picked {} at a time ".format(a, b)
return problem, solution return problem, solution
def factorialFunc(maxInput=6): def factorialFunc(maxInput=6):
a = random.randint(0, maxInput) a = random.randint(0, maxInput)
n = a n = a
@@ -452,6 +489,7 @@ def factorialFunc(maxInput = 6):
solution = str(b) solution = str(b)
return problem, solution return problem, solution
def surfaceAreaCube(maxSide=20, unit='m'): def surfaceAreaCube(maxSide=20, unit='m'):
a = random.randint(1, maxSide) a = random.randint(1, maxSide)
problem = f"Surface area of cube with side = {a}{unit} is" problem = f"Surface area of cube with side = {a}{unit} is"
@@ -459,6 +497,7 @@ def surfaceAreaCube(maxSide = 20, unit = 'm'):
solution = f"{ans} {unit}^2" solution = f"{ans} {unit}^2"
return problem, solution return problem, solution
def volumeCube(maxSide=20, unit='m'): def volumeCube(maxSide=20, unit='m'):
a = random.randint(1, maxSide) a = random.randint(1, maxSide)
problem = f"Volume of cube with side = {a}{unit} is" problem = f"Volume of cube with side = {a}{unit} is"
@@ -466,6 +505,7 @@ def volumeCube(maxSide = 20, unit = 'm'):
solution = f"{ans} {unit}^3" solution = f"{ans} {unit}^3"
return problem, solution return problem, solution
def surfaceAreaCuboid(maxSide=20, unit='m'): def surfaceAreaCuboid(maxSide=20, unit='m'):
a = random.randint(1, maxSide) a = random.randint(1, maxSide)
b = random.randint(1, maxSide) b = random.randint(1, maxSide)
@@ -476,6 +516,7 @@ def surfaceAreaCuboid(maxSide = 20, unit = 'm'):
solution = f"{ans} {unit}^2" solution = f"{ans} {unit}^2"
return problem, solution return problem, solution
def volumeCuboid(maxSide=20, unit='m'): def volumeCuboid(maxSide=20, unit='m'):
a = random.randint(1, maxSide) a = random.randint(1, maxSide)
b = random.randint(1, maxSide) b = random.randint(1, maxSide)
@@ -485,6 +526,7 @@ def volumeCuboid(maxSide = 20, unit = 'm'):
solution = f"{ans} {unit}^3" solution = f"{ans} {unit}^3"
return problem, solution return problem, solution
def surfaceAreaCylinder(maxRadius=20, maxHeight=50, unit='m'): def surfaceAreaCylinder(maxRadius=20, maxHeight=50, unit='m'):
a = random.randint(1, maxHeight) a = random.randint(1, maxHeight)
b = random.randint(1, maxRadius) b = random.randint(1, maxRadius)
@@ -493,6 +535,7 @@ def surfaceAreaCylinder(maxRadius = 20, maxHeight = 50,unit = 'm'):
solution = f"{ans} {unit}^2" solution = f"{ans} {unit}^2"
return problem, solution return problem, solution
def volumeCylinder(maxRadius=20, maxHeight=50, unit='m'): def volumeCylinder(maxRadius=20, maxHeight=50, unit='m'):
a = random.randint(1, maxHeight) a = random.randint(1, maxHeight)
b = random.randint(1, maxRadius) b = random.randint(1, maxRadius)
@@ -501,6 +544,7 @@ def volumeCylinder(maxRadius = 20, maxHeight = 50, unit = 'm'):
solution = f"{ans} {unit}^3" solution = f"{ans} {unit}^3"
return problem, solution return problem, solution
def surfaceAreaCone(maxRadius=20, maxHeight=50, unit='m'): def surfaceAreaCone(maxRadius=20, maxHeight=50, unit='m'):
a = random.randint(1, maxHeight) a = random.randint(1, maxHeight)
b = random.randint(1, maxRadius) b = random.randint(1, maxRadius)
@@ -510,6 +554,7 @@ def surfaceAreaCone(maxRadius = 20, maxHeight = 50,unit = 'm'):
solution = f"{ans} {unit}^2" solution = f"{ans} {unit}^2"
return problem, solution return problem, solution
def volumeCone(maxRadius=20, maxHeight=50, unit='m'): def volumeCone(maxRadius=20, maxHeight=50, unit='m'):
a = random.randint(1, maxHeight) a = random.randint(1, maxHeight)
b = random.randint(1, maxRadius) b = random.randint(1, maxRadius)
@@ -518,6 +563,7 @@ def volumeCone(maxRadius = 20, maxHeight = 50, unit = 'm'):
solution = f"{ans} {unit}^3" solution = f"{ans} {unit}^3"
return problem, solution return problem, solution
def commonFactorsFunc(maxVal=100): def commonFactorsFunc(maxVal=100):
a = random.randint(1, maxVal) a = random.randint(1, maxVal)
b = random.randint(1, maxVal) b = random.randint(1, maxVal)
@@ -537,6 +583,7 @@ def commonFactorsFunc(maxVal=100):
solution = arr solution = arr
return problem, solution return problem, solution
def intersectionOfTwoLinesFunc( def intersectionOfTwoLinesFunc(
minM=-10, maxM=10, minB=-10, maxB=10, minDenominator=1, maxDenominator=6 minM=-10, maxM=10, minB=-10, maxB=10, minDenominator=1, maxDenominator=6
): ):
@@ -590,6 +637,7 @@ def intersectionOfTwoLinesFunc(
solution = f"({fractionToString(intersection_x)}, {fractionToString(intersection_y)})" solution = f"({fractionToString(intersection_x)}, {fractionToString(intersection_y)})"
return problem, solution return problem, solution
def permutationFunc(maxlength=20): def permutationFunc(maxlength=20):
a = random.randint(10, maxlength) a = random.randint(10, maxlength)
b = random.randint(0, 9) b = random.randint(0, 9)
@@ -597,6 +645,7 @@ def permutationFunc(maxlength=20):
problem = "Number of Permutations from {} objects picked {} at a time = ".format(a, b) problem = "Number of Permutations from {} objects picked {} at a time = ".format(a, b)
return problem, solution return problem, solution
def vectorCrossFunc(minVal=-20, maxVal=20): def vectorCrossFunc(minVal=-20, maxVal=20):
a = [random.randint(minVal, maxVal) for i in range(3)] a = [random.randint(minVal, maxVal) for i in range(3)]
b = [random.randint(minVal, maxVal) for i in range(3)] b = [random.randint(minVal, maxVal) for i in range(3)]
@@ -605,6 +654,7 @@ def vectorCrossFunc(minVal=-20, maxVal=20):
a[0] * b[1] - a[1] * b[0]] a[0] * b[1] - a[1] * b[0]]
return str(a) + " X " + str(b) + " = ", str(c) return str(a) + " X " + str(b) + " = ", str(c)
def compareFractionsFunc(maxVal=10): def compareFractionsFunc(maxVal=10):
a = random.randint(1, maxVal) a = random.randint(1, maxVal)
b = random.randint(1, maxVal) b = random.randint(1, maxVal)
@@ -629,6 +679,7 @@ def compareFractionsFunc(maxVal=10):
problem = f"Which symbol represents the comparison between {a}/{b} and {c}/{d}?" problem = f"Which symbol represents the comparison between {a}/{b} and {c}/{d}?"
return problem, solution return problem, solution
def simpleInterestFunc(maxPrinciple=10000, maxRate=10, maxTime=10): def simpleInterestFunc(maxPrinciple=10000, maxRate=10, maxTime=10):
a = random.randint(1000, maxPrinciple) a = random.randint(1000, maxPrinciple)
b = random.randint(1, maxRate) b = random.randint(1, maxRate)
@@ -638,6 +689,7 @@ def simpleInterestFunc(maxPrinciple = 10000, maxRate = 10, maxTime = 10):
solution = round(d, 2) solution = round(d, 2)
return problem, solution return problem, solution
def matrixMultiplicationFunc(maxVal=100): def matrixMultiplicationFunc(maxVal=100):
m = random.randint(2, 10) m = random.randint(2, 10)
n = random.randint(2, 10) n = random.randint(2, 10)
@@ -670,6 +722,7 @@ def matrixMultiplicationFunc(maxVal=100):
solution = matrixMultiplicationFuncHelper(res) solution = matrixMultiplicationFuncHelper(res)
return problem, solution return problem, solution
def matrixMultiplicationFuncHelper(inp): def matrixMultiplicationFuncHelper(inp):
m = len(inp) m = len(inp)
n = len(inp[0]) n = len(inp[0])
@@ -681,6 +734,7 @@ def matrixMultiplicationFuncHelper(inp):
string += "\n" string += "\n"
return string return string
def cubeRootFunc(minNo=1, maxNo=1000): def cubeRootFunc(minNo=1, maxNo=1000):
b = random.randint(minNo, maxNo) b = random.randint(minNo, maxNo)
a = b**(1 / 3) a = b**(1 / 3)
@@ -688,6 +742,7 @@ def cubeRootFunc(minNo = 1, maxNo = 1000):
solution = str(round(a, 2)) solution = str(round(a, 2))
return problem, solution return problem, solution
def powerRuleIntegrationFunc(maxCoef=10, maxExp=10, maxTerms=5): def powerRuleIntegrationFunc(maxCoef=10, maxExp=10, maxTerms=5):
numTerms = random.randint(1, maxTerms) numTerms = random.randint(1, maxTerms)
problem = "" problem = ""
@@ -699,7 +754,7 @@ def powerRuleIntegrationFunc(maxCoef = 10, maxExp = 10, maxTerms = 5):
coefficient = random.randint(1, maxCoef) coefficient = random.randint(1, maxCoef)
exponent = random.randint(1, maxExp) exponent = random.randint(1, maxExp)
problem += str(coefficient) + "x^" + str(exponent) problem += str(coefficient) + "x^" + str(exponent)
solution += "("+str(coefficient) +"/"+str(exponent + 1) +")x^" + str(exponent +1) solution += "(" + str(coefficient) + "/" + str(exponent) + ")x^" + str(exponent + 1)
solution = solution + " + c" solution = solution + " + c"
return problem, solution return problem, solution
@@ -714,6 +769,7 @@ def fourthAngleOfQuadriFunc(maxAngle = 180):
solution = angle4 solution = angle4
return problem, solution return problem, solution
def quadraticEquation(maxVal=100): def quadraticEquation(maxVal=100):
a = random.randint(1, maxVal) a = random.randint(1, maxVal)
c = random.randint(1, maxVal) c = random.randint(1, maxVal)
@@ -826,8 +882,14 @@ def basicTrigonometryFunc(angles=[0,30,45,60,90],functions=["sin","cos","tan"]):
return problem,solution return problem,solution
def sumOfAnglesOfPolygonFunc(maxSides = 12):
side = random.randint(3, maxSides)
sum = (side - 2) * 180
problem = f"Sum of angles of polygon with {side} sides = "
solution = sum
return problem, solution
def data_desc(number_values=15,minval=5,maxval=50): def dataSummaryFunc(number_values=15,minval=5,maxval=50):
random_list=[] random_list=[]
for i in range(number_values): for i in range(number_values):
n=random.randint(minval,maxval) n=random.randint(minval,maxval)
@@ -845,14 +907,12 @@ def data_desc(number_values=15,minval=5,maxval=50):
solution="The Mean is {} , Standard Deviation is {}, Variance is {}".format(mean,var/number_values,(var/number_values)**0.5) solution="The Mean is {} , Standard Deviation is {}, Variance is {}".format(mean,var/number_values,(var/number_values)**0.5)
return problem,solution return problem,solution
# || Class Instances # || Class Instances
# Format is: # Format is:
# <title> = Generator("<Title>", <id>, <generalized problem>, <generalized solution>, <function name>) # <title> = Generator("<Title>", <id>, <generalized problem>, <generalized solution>, <function name>)
addition = Generator("Addition", 0, "a+b=", "c", additionFunc) addition = Generator("Addition", 0, "a+b=", "c", additionFunc)
subtraction = Generator("Subtraction", 1, "a-b=", "c", subtractionFunc) subtraction = Generator("Subtraction", 1, "a-b=", "c", subtractionFunc)
multiplication = Generator("Multiplication", 2, "a*b=", "c", multiplicationFunc) multiplication = Generator("Multiplication", 2, "a*b=", "c", multiplicationFunc)
@@ -902,7 +962,7 @@ compareFractions=Generator("Compare Fractions",44,"Which symbol represents the c
simpleInterest = Generator("Simple Interest", 45, "Simple interest for a principle amount of a dollars, b% rate of interest and for a time period of c years is = ", "d dollars", simpleInterestFunc) simpleInterest = Generator("Simple Interest", 45, "Simple interest for a principle amount of a dollars, b% rate of interest and for a time period of c years is = ", "d dollars", simpleInterestFunc)
matrixMultiplication = Generator("Multiplication of two matrices", 46, "Multiply two matrices A and B", "C", matrixMultiplicationFunc) matrixMultiplication = Generator("Multiplication of two matrices", 46, "Multiply two matrices A and B", "C", matrixMultiplicationFunc)
CubeRoot = Generator("Cube Root", 47, "Cuberoot of a upto 2 decimal places is", "b", cubeRootFunc) CubeRoot = Generator("Cube Root", 47, "Cuberoot of a upto 2 decimal places is", "b", cubeRootFunc)
powerRuleIntegration = Generator("Power Rule Integration", 48, "nx^m=", "(n/m+1)x^(m+1)", powerRuleIntegrationFunc) powerRuleIntegration = Generator("Power Rule Integration", 48, "nx^m=", "(n/m)x^(m+1)", powerRuleIntegrationFunc)
fourthAngleOfQuadrilateral = Generator("Fourth Angle of Quadrilateral", 49, "Fourth angle of Quadrilateral with angles a,b,c =", "angle4", fourthAngleOfQuadriFunc) fourthAngleOfQuadrilateral = Generator("Fourth Angle of Quadrilateral", 49, "Fourth angle of Quadrilateral with angles a,b,c =", "angle4", fourthAngleOfQuadriFunc)
quadraticEquationSolve = Generator("Quadratic Equation", 50, "Find the zeros {x1,x2} of the quadratic equation ax^2+bx+c=0", "x1,x2", quadraticEquation) quadraticEquationSolve = Generator("Quadratic Equation", 50, "Find the zeros {x1,x2} of the quadratic equation ax^2+bx+c=0", "x1,x2", quadraticEquation)
hcf = Generator("HCF (Highest Common Factor)", 51, "HCF of a and b = ", "c", hcfFunc) hcf = Generator("HCF (Highest Common Factor)", 51, "HCF of a and b = ", "c", hcfFunc)
@@ -912,4 +972,5 @@ confidenceInterval = Generator("Confidence interval For sample S", 54, "With X%
surdsComparison = Generator("Comparing surds", 55, "Fill in the blanks a^(1/b) _ c^(1/d)", "</>/=", surdsComparisonFunc) surdsComparison = Generator("Comparing surds", 55, "Fill in the blanks a^(1/b) _ c^(1/d)", "</>/=", surdsComparisonFunc)
fibonacciSeries = Generator("Fibonacci Series",56,"fibonacci series of first a numbers","prints the fibonacci series starting from 0 to a",fibonacciSeriesFunc) fibonacciSeries = Generator("Fibonacci Series",56,"fibonacci series of first a numbers","prints the fibonacci series starting from 0 to a",fibonacciSeriesFunc)
basicTrigonometry=Generator("Trigonometric Values",57,"What is sin(X)?","ans",basicTrigonometryFunc) basicTrigonometry=Generator("Trigonometric Values",57,"What is sin(X)?","ans",basicTrigonometryFunc)
data_summary=Generator("Mean,Standard Deviation,Variance",58,"a,b,c","Mean:a+b+c/3,Std,Var",data_desc) sumOfAnglesOfPolygon = Generator("Sum of Angles of Polygon", 58, "Sum of angles of polygon with n sides = ", "sum", sumOfAnglesOfPolygonFunc)
dataSummary = Generator("Mean,Standard Deviation,Variance", 59, "a,b,c", "Mean:a+b+c/3,Std,Var", dataSummaryFunc)

View File

@@ -5,42 +5,42 @@ from hypothesis import strategies as st, given, assume
@given(maxSum=st.integers(min_value=1), maxAddend=st.integers(min_value=1)) @given(maxSum=st.integers(min_value=1), maxAddend=st.integers(min_value=1))
def test_additionFunc(maxSum, maxAddend): def test_addition(maxSum, maxAddend):
assume(maxSum > maxAddend) assume(maxSum > maxAddend)
problem, solution = additionFunc(maxSum, maxAddend) problem, solution = addition.func(maxSum, maxAddend)
assert eval(problem[:-1]) == int(solution) assert eval(problem[:-1]) == int(solution)
@given(maxMinuend=st.integers(min_value=1), maxDiff=st.integers(min_value=1)) @given(maxMinuend=st.integers(min_value=1), maxDiff=st.integers(min_value=1))
def test_subtractionFunc(maxMinuend, maxDiff): def test_subtraction(maxMinuend, maxDiff):
assume(maxMinuend > maxDiff) assume(maxMinuend > maxDiff)
problem, solution = subtractionFunc(maxMinuend, maxDiff) problem, solution = subtraction.func(maxMinuend, maxDiff)
assert eval(problem[:-1]) == int(solution) assert eval(problem[:-1]) == int(solution)
@given(maxRes=st.integers(min_value=1), maxMulti=st.integers(min_value=1)) @given(maxRes=st.integers(min_value=1), maxMulti=st.integers(min_value=1))
def test_multiplicationFunc(maxRes, maxMulti): def test_multiplication(maxRes, maxMulti):
assume(maxRes > maxMulti) assume(maxRes > maxMulti)
problem, solution = multiplicationFunc(maxRes, maxMulti) problem, solution = multiplication.func(maxRes, maxMulti)
assert eval(problem[:-1]) == int(solution) assert eval(problem[:-1]) == int(solution)
@given(maxRes=st.integers(min_value=1), maxDivid=st.integers(min_value=1)) @given(maxRes=st.integers(min_value=1), maxDivid=st.integers(min_value=1))
def test_divisionFunc(maxRes, maxDivid): def test_division(maxRes, maxDivid):
assume(maxRes > maxDivid) assume(maxRes > maxDivid)
problem, solution = divisionFunc(maxRes, maxDivid) problem, solution = division.func(maxRes, maxDivid)
assert eval(problem[:-1]) == float(solution) assert eval(problem[:-1]) == float(solution)
@given(maxRes=st.integers(min_value=1), maxModulo=st.integers(min_value=1)) @given(maxRes=st.integers(min_value=1), maxModulo=st.integers(min_value=1))
def test_moduloFunc(maxRes, maxModulo): def test_moduloDivision(maxRes, maxModulo):
assume(maxRes > maxModulo) assume(maxRes > maxModulo)
problem, solution = moduloFunc(maxRes, maxModulo) problem, solution = moduloDivision.func(maxRes, maxModulo)
assert eval(problem[:-1]) == int(solution) assert eval(problem[:-1]) == int(solution)
@given(minNo=st.integers(min_value=1), maxNo=st.integers(min_value=1, max_value=2 ** 50)) @given(minNo=st.integers(min_value=1), maxNo=st.integers(min_value=1, max_value=2 ** 50))
def test_squareRootFunc(minNo, maxNo): def test_squareRoot(minNo, maxNo):
assume(maxNo > minNo) assume(maxNo > minNo)
problem, solution = squareRootFunc(minNo, maxNo) problem, solution = squareRoot.func(minNo, maxNo)
assert eval(problem[:-1]) == float(solution) assert eval(problem[:-1]) == float(solution)