From 954b47fecdae7366802af7b6a4a5c7a1edce2ba1 Mon Sep 17 00:00:00 2001 From: D-T-666 Date: Sat, 17 Oct 2020 22:53:55 +0400 Subject: [PATCH] added 4 test and an "=" in binaryComplement1sFunc --- mathgenerator/mathgen.py | 2 +- tests/test_mathgen.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 02b4c1d..b1ce210 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -70,7 +70,7 @@ def binaryComplement1sFunc(maxDigits = 10): question += temp answer += "0" if temp == "1" else "1" - problem = question + problem = question+"=" solution = answer return problem, solution diff --git a/tests/test_mathgen.py b/tests/test_mathgen.py index ace72a5..2d6e590 100644 --- a/tests/test_mathgen.py +++ b/tests/test_mathgen.py @@ -39,8 +39,42 @@ def test_moduloFunc(maxRes, maxModulo): assert eval(problem[:-1]) == int(solution) +@given(maxDigits=st.integers(min_value=1, max_value=16)) +def test_binaryComplement1sFunc(maxDigits): + assume(maxDigits > 1) + problem, solution = binaryComplement1sFunc(maxDigits) + assert "".join('1' if i == '0' else '0' for i in problem[:-1]) == solution + + @given(minNo=st.integers(min_value=1), maxNo=st.integers(min_value=1, max_value=2 ** 50)) def test_squareRootFunc(minNo, maxNo): assume(maxNo > minNo) problem, solution = squareRootFunc(minNo, maxNo) assert eval(problem[:-1]) == float(solution) + + +@given(maxSquareNum=st.integers(min_value=1)) +def test_squareFunc(maxSquareNum): + assume(maxSquareNum > 1) + problem, solution = squareFunc(maxSquareNum) + assert pow(int(problem[:-3]), 2) == int(solution) + + +@given(maxVal=st.integers(min_value=1)) +def test_lcmFunc(maxVal): + assume(maxVal > 1) + problem, solution = lcmFunc(maxVal) + split_arr = problem.split(' ') + mult = int(split_arr[2])*int(split_arr[4]) + assert mult if mult != pow(int(split_arr[2]), 2) else int( + split_arr[2]) == int(solution) + + +@given(maxVal=st.integers(min_value=1)) +def test_gcdFunc(maxVal): + assume(maxVal > 1) + problem, solution = gcdFunc(maxVal) + split_arr = problem.split(' ') + mult = int(split_arr[2])*int(split_arr[4]) + assert mult if mult != pow(int(split_arr[2]), 2) else int( + split_arr[2]) == int(solution) \ No newline at end of file