From 46725c8a57385e45a41b45450741c06996f3a3d5 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Thu, 24 Sep 2020 15:19:22 +0530 Subject: [PATCH 01/14] Add file for testing Project Euler solutions --- project_euler/solution_test.py | 97 ++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 project_euler/solution_test.py diff --git a/project_euler/solution_test.py b/project_euler/solution_test.py new file mode 100644 index 000000000000..0f83faf2c77d --- /dev/null +++ b/project_euler/solution_test.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +import importlib +import importlib.util +import logging +import pathlib + +LOG_FILENAME = "project_euler_test.log" + +# Keep the answer part in str for consistency as some problems could output in str +# Problem 329: 199740353/29386561536000 (Format for this answer is a/b) +# https://github.com/nayuki/Project-Euler-solutions/blob/master/Answers.txt#L191 +ANSWERS = { + 1: "233168", + 2: "4613732", + 3: "6857", + 4: "906609", + 5: "232792560", + 6: "25164150", + 7: "104743", + 8: "23514624000", + 9: "31875000", + 10: "142913828922", + 11: "70600674", + 12: "76576500", + 13: "5537376230", + 14: "837799", + 15: "137846528820", + 16: "1366", + 17: "21124", + 18: "1074", + 19: "171", +} + +WORKING_DIR = pathlib.Path.cwd() + +if WORKING_DIR.name == "Python": + PROJECT_EULER_PATH = WORKING_DIR.joinpath("project_euler") +# Below two checks are just in case something goes wrong +# Travis root dir = /home/travis/build/TheAlgorithms/Python +# https://travis-ci.com/github/TheAlgorithms/Python/builds/186187397#L398 +elif WORKING_DIR.name == "TheAlgorithms": + PROJECT_EULER_PATH = WORKING_DIR.joinpath("Python", "project_euler") +elif WORKING_DIR.name == "project_euler": + PROJECT_EULER_PATH = WORKING_DIR + +# Remove previous log file if present +pathlib.Path.unlink(WORKING_DIR.joinpath(LOG_FILENAME), missing_ok=True) + +# This should be after removing the log file if present +logging.basicConfig( + filename=LOG_FILENAME, format="%(levelname)s: %(message)s", level=logging.DEBUG, +) + + +def generate_solution_modules(dir_path: pathlib.Path): + # Iterating over every file or directory + for file_path in dir_path.iterdir(): + if ( + file_path.suffix != ".py" + or file_path.name.startswith("_") + or file_path.name.startswith("test") + ): + continue + else: + # Importing the source file through the given path + # https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly + spec = importlib.util.spec_from_file_location( + file_path.name, str(file_path) + ) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + yield module + + +def test_project_euler(): + for problem_number, expected in ANSWERS.items(): + problem_dir = PROJECT_EULER_PATH.joinpath(f"problem_{problem_number:02}") + # By checking if it's a directory we can write all the problem number and + # answer pair in ANSWERS variable and not worry whether it is actually + # present in the 'project_euler' directory + if problem_dir.is_dir(): + for solution_module in generate_solution_modules(problem_dir): + try: + answer = str(solution_module.solution()) + assert answer == expected, f"Expected: {expected} but got {answer}" + # TypeError: If solution() requires arguments + # AssertionError: If answer is incorrect + # AttributeError: If the module has no attribute called 'solution' + except (TypeError, AssertionError, AttributeError) as err: + logging.error( + f"{err} \nSource: Problem {problem_number}: " + f"{solution_module.__name__}\n" + ) + + +if __name__ == "__main__": + test_project_euler() From 25df46b9bf456b366c88127db45c2d0ed301deee Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 24 Sep 2020 15:38:35 +0530 Subject: [PATCH 02/14] Remove the importlib import --- project_euler/solution_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/project_euler/solution_test.py b/project_euler/solution_test.py index 0f83faf2c77d..f783e0b0f0fc 100644 --- a/project_euler/solution_test.py +++ b/project_euler/solution_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import importlib import importlib.util import logging import pathlib From 4f9a3c9c45550e3c3c53e865a37be40d27f38a91 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 24 Sep 2020 15:48:19 +0530 Subject: [PATCH 03/14] Update project_euler/solution_test.py Co-authored-by: Christian Clauss --- project_euler/solution_test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/project_euler/solution_test.py b/project_euler/solution_test.py index f783e0b0f0fc..851dc50894ce 100644 --- a/project_euler/solution_test.py +++ b/project_euler/solution_test.py @@ -56,8 +56,7 @@ def generate_solution_modules(dir_path: pathlib.Path): for file_path in dir_path.iterdir(): if ( file_path.suffix != ".py" - or file_path.name.startswith("_") - or file_path.name.startswith("test") + or file_path.name.startswith(("_", "test")) ): continue else: From 4283fe653693f9d4eb34db6241217b8f5d163855 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Thu, 24 Sep 2020 21:07:02 +0530 Subject: [PATCH 04/14] Small tweaks to project_euler/solution_test.py --- project_euler/solution_test.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/project_euler/solution_test.py b/project_euler/solution_test.py index 851dc50894ce..b68e933070df 100644 --- a/project_euler/solution_test.py +++ b/project_euler/solution_test.py @@ -54,20 +54,14 @@ def generate_solution_modules(dir_path: pathlib.Path): # Iterating over every file or directory for file_path in dir_path.iterdir(): - if ( - file_path.suffix != ".py" - or file_path.name.startswith(("_", "test")) - ): + if file_path.suffix != ".py" or file_path.name.startswith(("_", "test")): continue - else: - # Importing the source file through the given path - # https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly - spec = importlib.util.spec_from_file_location( - file_path.name, str(file_path) - ) - module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) - yield module + # Importing the source file through the given path + # https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly + spec = importlib.util.spec_from_file_location(file_path.name, str(file_path)) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + yield module def test_project_euler(): @@ -84,7 +78,7 @@ def test_project_euler(): # TypeError: If solution() requires arguments # AssertionError: If answer is incorrect # AttributeError: If the module has no attribute called 'solution' - except (TypeError, AssertionError, AttributeError) as err: + except (AssertionError, AttributeError, TypeError) as err: logging.error( f"{err} \nSource: Problem {problem_number}: " f"{solution_module.__name__}\n" From e9d123788ea97925f33d47958cfb711aa239f0d8 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Thu, 24 Sep 2020 23:09:42 +0530 Subject: [PATCH 05/14] Test Project Euler solutions through Travis --- .travis.yml | 1 + project_euler/solution_test.py | 0 2 files changed, 1 insertion(+) mode change 100644 => 100755 project_euler/solution_test.py diff --git a/.travis.yml b/.travis.yml index d2394b4097f3..9fe36efad84a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ jobs: - black --check . || true - flake8 --ignore=E203,W503 --max-complexity=25 --max-line-length=88 --statistics --count . - scripts/validate_filenames.py # no uppercase, no spaces, in a directory + - project_euler/solution_test.py # test project Euler solutions - pip install -r requirements.txt # fast fail on black, flake8, validate_filenames script: - mypy --ignore-missing-imports . || true # https://github.com/python/mypy/issues/7907 diff --git a/project_euler/solution_test.py b/project_euler/solution_test.py old mode 100644 new mode 100755 From ae1cb203fda8df87e3f67e4e9e58548aa45e6d7d Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Fri, 25 Sep 2020 02:52:01 +0530 Subject: [PATCH 06/14] Improved testing for Project Euler solutions: - Renamed file so that it isn't picked up by pytest - Fail fast on validating solutions through Travis CI --- .travis.yml | 2 +- ...solution_test.py => validate_solutions.py} | 41 ++++++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) rename project_euler/{solution_test.py => validate_solutions.py} (65%) diff --git a/.travis.yml b/.travis.yml index 9fe36efad84a..e88d89bd9308 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ jobs: - black --check . || true - flake8 --ignore=E203,W503 --max-complexity=25 --max-line-length=88 --statistics --count . - scripts/validate_filenames.py # no uppercase, no spaces, in a directory - - project_euler/solution_test.py # test project Euler solutions + - project_euler/validate_solutions.py # test project Euler solutions - pip install -r requirements.txt # fast fail on black, flake8, validate_filenames script: - mypy --ignore-missing-imports . || true # https://github.com/python/mypy/issues/7907 diff --git a/project_euler/solution_test.py b/project_euler/validate_solutions.py similarity index 65% rename from project_euler/solution_test.py rename to project_euler/validate_solutions.py index b68e933070df..f039647c576f 100755 --- a/project_euler/solution_test.py +++ b/project_euler/validate_solutions.py @@ -64,7 +64,8 @@ def generate_solution_modules(dir_path: pathlib.Path): yield module -def test_project_euler(): +def test_project_euler() -> int: + wrong_answer, no_solution, solution_args = [[] for _ in range(3)] for problem_number, expected in ANSWERS.items(): problem_dir = PROJECT_EULER_PATH.joinpath(f"problem_{problem_number:02}") # By checking if it's a directory we can write all the problem number and @@ -78,12 +79,40 @@ def test_project_euler(): # TypeError: If solution() requires arguments # AssertionError: If answer is incorrect # AttributeError: If the module has no attribute called 'solution' - except (AssertionError, AttributeError, TypeError) as err: - logging.error( - f"{err} \nSource: Problem {problem_number}: " - f"{solution_module.__name__}\n" + # except (AssertionError, AttributeError, TypeError) as err: + # logging.error( + # f"{err} \nSource: Problem {problem_number}: " + # f"{solution_module.__name__}\n" + # ) + except AssertionError as err: + wrong_answer.append( + f"problem_{problem_number}/{solution_module.__name__}: {err}" ) + except AttributeError as err: + no_solution.append( + f"problem_{problem_number}/{solution_module.__name__}: {err}" + ) + except TypeError as err: + solution_args.append( + f"problem_{problem_number}/{solution_module.__name__}: {err}" + ) + if wrong_answer: + print(f"{len(wrong_answer)} files contain wrong answers:\n") + print("\n".join(wrong_answer) + "\n") + if solution_args: + print( + f"{len(solution_args)} files require positional arguments for solution() function:\n" + ) + print("\n".join(solution_args) + "\n") + if no_solution: + print(f"{len(no_solution)} files have no solution() function:\n") + print("\n".join(no_solution) + "\n") + return len(wrong_answer + solution_args + no_solution) if __name__ == "__main__": - test_project_euler() + exit_code = test_project_euler() + if exit_code: + import sys + + sys.exit(exit_code) From 4af7812ae51f1a3c1f6ed8a16d244c3035af0ebf Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 25 Sep 2020 02:59:56 +0530 Subject: [PATCH 07/14] Update validate_solutions.py --- project_euler/validate_solutions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/project_euler/validate_solutions.py b/project_euler/validate_solutions.py index f039647c576f..4ab03e4c7496 100755 --- a/project_euler/validate_solutions.py +++ b/project_euler/validate_solutions.py @@ -101,7 +101,8 @@ def test_project_euler() -> int: print("\n".join(wrong_answer) + "\n") if solution_args: print( - f"{len(solution_args)} files require positional arguments for solution() function:\n" + f"{len(solution_args)} " + f"files require positional arguments for solution() function:\n" ) print("\n".join(solution_args) + "\n") if no_solution: From 4616f1cdfc98ede3dbb1907341f76fa6e6e3a3bc Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Fri, 25 Sep 2020 08:57:27 +0530 Subject: [PATCH 08/14] Use namedtuple for input parameters and answer - Remove logging - Remove unnecessary checks for PROJECT_EULER_PATH as Travis CI picks up the same path --- project_euler/validate_solutions.py | 224 +++++++++++++++++++++------- 1 file changed, 168 insertions(+), 56 deletions(-) diff --git a/project_euler/validate_solutions.py b/project_euler/validate_solutions.py index 4ab03e4c7496..98f17a7969d6 100755 --- a/project_euler/validate_solutions.py +++ b/project_euler/validate_solutions.py @@ -1,54 +1,163 @@ #!/usr/bin/env python3 import importlib.util -import logging import pathlib +from collections import namedtuple -LOG_FILENAME = "project_euler_test.log" +# CamelCase as this returns a class object +QuesAndAns = namedtuple("QuesAndAns", "question answer") + +ques_08 = ( + "73167176531330624919225119674426574742355349194934" + "96983520312774506326239578318016984801869478851843" + "85861560789112949495459501737958331952853208805511" + "12540698747158523863050715693290963295227443043557" + "66896648950445244523161731856403098711121722383113" + "62229893423380308135336276614282806444486645238749" + "30358907296290491560440772390713810515859307960866" + "70172427121883998797908792274921901699720888093776" + "65727333001053367881220235421809751254540594752243" + "52584907711670556013604839586446706324415722155397" + "53697817977846174064955149290862569321978468622482" + "83972241375657056057490261407972968652414535100474" + "82166370484403199890008895243450658541227588666881" + "16427171479924442928230863465674813919123162824586" + "17866458359124566529476545682848912883142607690042" + "24219022671055626321111109370544217506941658960408" + "07198403850962455444362981230987879927244284909188" + "84580156166097919133875499200524063689912560717606" + "05886116467109405077541002256983155200055935729725" + "71636269561882670428252483600823257530420752963450" +) + +ques_13 = [ + 37107287533902102798797998220837590246510135740250, + 46376937677490009712648124896970078050417018260538, + 74324986199524741059474233309513058123726617309629, + 91942213363574161572522430563301811072406154908250, + 23067588207539346171171980310421047513778063246676, + 89261670696623633820136378418383684178734361726757, + 28112879812849979408065481931592621691275889832738, + 44274228917432520321923589422876796487670272189318, + 47451445736001306439091167216856844588711603153276, + 70386486105843025439939619828917593665686757934951, + 62176457141856560629502157223196586755079324193331, + 64906352462741904929101432445813822663347944758178, + 92575867718337217661963751590579239728245598838407, + 58203565325359399008402633568948830189458628227828, + 80181199384826282014278194139940567587151170094390, + 35398664372827112653829987240784473053190104293586, + 86515506006295864861532075273371959191420517255829, + 71693888707715466499115593487603532921714970056938, + 54370070576826684624621495650076471787294438377604, + 53282654108756828443191190634694037855217779295145, + 36123272525000296071075082563815656710885258350721, + 45876576172410976447339110607218265236877223636045, + 17423706905851860660448207621209813287860733969412, + 81142660418086830619328460811191061556940512689692, + 51934325451728388641918047049293215058642563049483, + 62467221648435076201727918039944693004732956340691, + 15732444386908125794514089057706229429197107928209, + 55037687525678773091862540744969844508330393682126, + 18336384825330154686196124348767681297534375946515, + 80386287592878490201521685554828717201219257766954, + 78182833757993103614740356856449095527097864797581, + 16726320100436897842553539920931837441497806860984, + 48403098129077791799088218795327364475675590848030, + 87086987551392711854517078544161852424320693150332, + 59959406895756536782107074926966537676326235447210, + 69793950679652694742597709739166693763042633987085, + 41052684708299085211399427365734116182760315001271, + 65378607361501080857009149939512557028198746004375, + 35829035317434717326932123578154982629742552737307, + 94953759765105305946966067683156574377167401875275, + 88902802571733229619176668713819931811048770190271, + 25267680276078003013678680992525463401061632866526, + 36270218540497705585629946580636237993140746255962, + 24074486908231174977792365466257246923322810917141, + 91430288197103288597806669760892938638285025333403, + 34413065578016127815921815005561868836468420090470, + 23053081172816430487623791969842487255036638784583, + 11487696932154902810424020138335124462181441773470, + 63783299490636259666498587618221225225512486764533, + 67720186971698544312419572409913959008952310058822, + 95548255300263520781532296796249481641953868218774, + 76085327132285723110424803456124867697064507995236, + 37774242535411291684276865538926205024910326572967, + 23701913275725675285653248258265463092207058596522, + 29798860272258331913126375147341994889534765745501, + 18495701454879288984856827726077713721403798879715, + 38298203783031473527721580348144513491373226651381, + 34829543829199918180278916522431027392251122869539, + 40957953066405232632538044100059654939159879593635, + 29746152185502371307642255121183693803580388584903, + 41698116222072977186158236678424689157993532961922, + 62467957194401269043877107275048102390895523597457, + 23189706772547915061505504953922979530901129967519, + 86188088225875314529584099251203829009407770775672, + 11306739708304724483816533873502340845647058077308, + 82959174767140363198008187129011875491310547126581, + 97623331044818386269515456334926366572897563400500, + 42846280183517070527831839425882145521227251250327, + 55121603546981200581762165212827652751691296897789, + 32238195734329339946437501907836945765883352399886, + 75506164965184775180738168837861091527357929701337, + 62177842752192623401942399639168044983993173312731, + 32924185707147349566916674687634660915035914677504, + 99518671430235219628894890102423325116913619626622, + 73267460800591547471830798392868535206946944540724, + 76841822524674417161514036427982273348055556214818, + 97142617910342598647204516893989422179826088076852, + 87783646182799346313767754307809363333018982642090, + 10848802521674670883215120185883543223812876952786, + 71329612474782464538636993009049310363619763878039, + 62184073572399794223406235393808339651327408011116, + 66627891981488087797941876876144230030984490851411, + 60661826293682836764744779239180335110989069790714, + 85786944089552990653640447425576083659976645795096, + 66024396409905389607120198219976047599490197230297, + 64913982680032973156037120041377903785566085089252, + 16730939319872750275468906903707539413042652315011, + 94809377245048795150954100921645863754710598436791, + 78639167021187492431995700641917969777599028300699, + 15368713711936614952811305876380278410754449733078, + 40789923115535562561142322423255033685442488917353, + 44889911501440648020369068063960672322193204149535, + 41503128880339536053299340368006977710650566631954, + 81234880673210146739058568557934581403627822703280, + 82616570773948327592232845941706525094512325230608, + 22918802058777319719839450180888072429661980811197, + 77158542502016545090413245809786882778948721859617, + 72107838435069186155435662884062257473692284509516, + 20849603980134001723930671666823555245252804609722, + 53503534226472524250874054075591789781264330331690, +] # Keep the answer part in str for consistency as some problems could output in str # Problem 329: 199740353/29386561536000 (Format for this answer is a/b) # https://github.com/nayuki/Project-Euler-solutions/blob/master/Answers.txt#L191 ANSWERS = { - 1: "233168", - 2: "4613732", - 3: "6857", - 4: "906609", - 5: "232792560", - 6: "25164150", - 7: "104743", - 8: "23514624000", - 9: "31875000", - 10: "142913828922", - 11: "70600674", - 12: "76576500", - 13: "5537376230", - 14: "837799", - 15: "137846528820", - 16: "1366", - 17: "21124", - 18: "1074", - 19: "171", + 1: QuesAndAns(1000, "233168"), + 2: QuesAndAns(4_000_000, "4613732"), + 3: QuesAndAns(600851475143, "6857"), + 4: QuesAndAns(None, "906609"), + 5: QuesAndAns(20, "232792560"), + 6: QuesAndAns(100, "25164150"), + 7: QuesAndAns(10001, "104743"), + 8: QuesAndAns(ques_08, "23514624000"), + 9: QuesAndAns(1000, "31875000"), + 10: QuesAndAns(2_000_000, "142913828922"), + 11: QuesAndAns(None, "70600674"), + 12: QuesAndAns(None, "76576500"), + 13: QuesAndAns(ques_13, "5537376230"), + 14: QuesAndAns(1_000_000, "837799"), + 15: QuesAndAns(None, "137846528820"), + 16: QuesAndAns(1000, "1366"), + 17: QuesAndAns(1000, "21124"), + 18: QuesAndAns(None, "1074"), + 19: QuesAndAns(None, "171"), } -WORKING_DIR = pathlib.Path.cwd() - -if WORKING_DIR.name == "Python": - PROJECT_EULER_PATH = WORKING_DIR.joinpath("project_euler") -# Below two checks are just in case something goes wrong -# Travis root dir = /home/travis/build/TheAlgorithms/Python -# https://travis-ci.com/github/TheAlgorithms/Python/builds/186187397#L398 -elif WORKING_DIR.name == "TheAlgorithms": - PROJECT_EULER_PATH = WORKING_DIR.joinpath("Python", "project_euler") -elif WORKING_DIR.name == "project_euler": - PROJECT_EULER_PATH = WORKING_DIR - -# Remove previous log file if present -pathlib.Path.unlink(WORKING_DIR.joinpath(LOG_FILENAME), missing_ok=True) - -# This should be after removing the log file if present -logging.basicConfig( - filename=LOG_FILENAME, format="%(levelname)s: %(message)s", level=logging.DEBUG, -) +PROJECT_EULER_PATH = pathlib.Path.cwd().joinpath("project_euler") def generate_solution_modules(dir_path: pathlib.Path): @@ -66,7 +175,8 @@ def generate_solution_modules(dir_path: pathlib.Path): def test_project_euler() -> int: wrong_answer, no_solution, solution_args = [[] for _ in range(3)] - for problem_number, expected in ANSWERS.items(): + for problem_number, ques_ans in ANSWERS.items(): + parameter, expected = ques_ans.question, ques_ans.answer problem_dir = PROJECT_EULER_PATH.joinpath(f"problem_{problem_number:02}") # By checking if it's a directory we can write all the problem number and # answer pair in ANSWERS variable and not worry whether it is actually @@ -75,27 +185,29 @@ def test_project_euler() -> int: for solution_module in generate_solution_modules(problem_dir): try: answer = str(solution_module.solution()) - assert answer == expected, f"Expected: {expected} but got {answer}" + if answer != expected: + wrong_answer.append( + f"problem_{problem_number:02}/{solution_module.__name__}: " + f"Expected {expected} but got {answer}" + ) # TypeError: If solution() requires arguments - # AssertionError: If answer is incorrect # AttributeError: If the module has no attribute called 'solution' - # except (AssertionError, AttributeError, TypeError) as err: - # logging.error( - # f"{err} \nSource: Problem {problem_number}: " - # f"{solution_module.__name__}\n" - # ) - except AssertionError as err: - wrong_answer.append( - f"problem_{problem_number}/{solution_module.__name__}: {err}" - ) except AttributeError as err: no_solution.append( - f"problem_{problem_number}/{solution_module.__name__}: {err}" + f"problem_{problem_number:02}/{solution_module.__name__}: {err}" ) except TypeError as err: - solution_args.append( - f"problem_{problem_number}/{solution_module.__name__}: {err}" - ) + if parameter: + answer = str(solution_module.solution(parameter)) + if answer != expected: + wrong_answer.append( + f"problem_{problem_number:02}/{solution_module.__name__}: " + f"Expected {expected} but got {answer}" + ) + else: + solution_args.append( + f"problem_{problem_number:02}/{solution_module.__name__}: {err}" + ) if wrong_answer: print(f"{len(wrong_answer)} files contain wrong answers:\n") print("\n".join(wrong_answer) + "\n") From d5117b4d57a35e5154820da0cffb854d050d3b8a Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Fri, 25 Sep 2020 09:04:35 +0530 Subject: [PATCH 09/14] Fix flake8 errors: line too long --- project_euler/validate_solutions.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/project_euler/validate_solutions.py b/project_euler/validate_solutions.py index 98f17a7969d6..31ac8cb00c8d 100755 --- a/project_euler/validate_solutions.py +++ b/project_euler/validate_solutions.py @@ -201,12 +201,14 @@ def test_project_euler() -> int: answer = str(solution_module.solution(parameter)) if answer != expected: wrong_answer.append( - f"problem_{problem_number:02}/{solution_module.__name__}: " + f"problem_{problem_number:02}/" + f"{solution_module.__name__}: " f"Expected {expected} but got {answer}" ) else: solution_args.append( - f"problem_{problem_number:02}/{solution_module.__name__}: {err}" + f"problem_{problem_number:02}/" + f"{solution_module.__name__}: {err}" ) if wrong_answer: print(f"{len(wrong_answer)} files contain wrong answers:\n") From c1b69b2db0a703dea413d8ab8aa04f2e3d809ca4 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Fri, 25 Sep 2020 13:14:38 +0530 Subject: [PATCH 10/14] Small tweaks to validate_solutions.py --- project_euler/validate_solutions.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/project_euler/validate_solutions.py b/project_euler/validate_solutions.py index 31ac8cb00c8d..5891d281211c 100755 --- a/project_euler/validate_solutions.py +++ b/project_euler/validate_solutions.py @@ -6,7 +6,7 @@ # CamelCase as this returns a class object QuesAndAns = namedtuple("QuesAndAns", "question answer") -ques_08 = ( +QUES_08 = ( "73167176531330624919225119674426574742355349194934" "96983520312774506326239578318016984801869478851843" "85861560789112949495459501737958331952853208805511" @@ -29,7 +29,7 @@ "71636269561882670428252483600823257530420752963450" ) -ques_13 = [ +QUES_13 = ( 37107287533902102798797998220837590246510135740250, 46376937677490009712648124896970078050417018260538, 74324986199524741059474233309513058123726617309629, @@ -130,7 +130,7 @@ 72107838435069186155435662884062257473692284509516, 20849603980134001723930671666823555245252804609722, 53503534226472524250874054075591789781264330331690, -] +) # Keep the answer part in str for consistency as some problems could output in str # Problem 329: 199740353/29386561536000 (Format for this answer is a/b) @@ -143,12 +143,12 @@ 5: QuesAndAns(20, "232792560"), 6: QuesAndAns(100, "25164150"), 7: QuesAndAns(10001, "104743"), - 8: QuesAndAns(ques_08, "23514624000"), + 8: QuesAndAns(QUES_08, "23514624000"), 9: QuesAndAns(1000, "31875000"), 10: QuesAndAns(2_000_000, "142913828922"), 11: QuesAndAns(None, "70600674"), 12: QuesAndAns(None, "76576500"), - 13: QuesAndAns(ques_13, "5537376230"), + 13: QuesAndAns(QUES_13, "5537376230"), 14: QuesAndAns(1_000_000, "837799"), 15: QuesAndAns(None, "137846528820"), 16: QuesAndAns(1000, "1366"), @@ -176,7 +176,7 @@ def generate_solution_modules(dir_path: pathlib.Path): def test_project_euler() -> int: wrong_answer, no_solution, solution_args = [[] for _ in range(3)] for problem_number, ques_ans in ANSWERS.items(): - parameter, expected = ques_ans.question, ques_ans.answer + parameter, expected = ques_ans problem_dir = PROJECT_EULER_PATH.joinpath(f"problem_{problem_number:02}") # By checking if it's a directory we can write all the problem number and # answer pair in ANSWERS variable and not worry whether it is actually From f1d60aca9e8c6cba013e5e5571d180f062bb3452 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Sat, 26 Sep 2020 16:22:00 +0530 Subject: [PATCH 11/14] Add all answers & back to using dictionary --- project_euler/validate_solutions.py | 929 ++++++++++++++++++++++------ 1 file changed, 750 insertions(+), 179 deletions(-) diff --git a/project_euler/validate_solutions.py b/project_euler/validate_solutions.py index 5891d281211c..624aceda4308 100755 --- a/project_euler/validate_solutions.py +++ b/project_euler/validate_solutions.py @@ -1,166 +1,15 @@ #!/usr/bin/env python3 import importlib.util import pathlib -from collections import namedtuple - -# CamelCase as this returns a class object -QuesAndAns = namedtuple("QuesAndAns", "question answer") - -QUES_08 = ( - "73167176531330624919225119674426574742355349194934" - "96983520312774506326239578318016984801869478851843" - "85861560789112949495459501737958331952853208805511" - "12540698747158523863050715693290963295227443043557" - "66896648950445244523161731856403098711121722383113" - "62229893423380308135336276614282806444486645238749" - "30358907296290491560440772390713810515859307960866" - "70172427121883998797908792274921901699720888093776" - "65727333001053367881220235421809751254540594752243" - "52584907711670556013604839586446706324415722155397" - "53697817977846174064955149290862569321978468622482" - "83972241375657056057490261407972968652414535100474" - "82166370484403199890008895243450658541227588666881" - "16427171479924442928230863465674813919123162824586" - "17866458359124566529476545682848912883142607690042" - "24219022671055626321111109370544217506941658960408" - "07198403850962455444362981230987879927244284909188" - "84580156166097919133875499200524063689912560717606" - "05886116467109405077541002256983155200055935729725" - "71636269561882670428252483600823257530420752963450" -) - -QUES_13 = ( - 37107287533902102798797998220837590246510135740250, - 46376937677490009712648124896970078050417018260538, - 74324986199524741059474233309513058123726617309629, - 91942213363574161572522430563301811072406154908250, - 23067588207539346171171980310421047513778063246676, - 89261670696623633820136378418383684178734361726757, - 28112879812849979408065481931592621691275889832738, - 44274228917432520321923589422876796487670272189318, - 47451445736001306439091167216856844588711603153276, - 70386486105843025439939619828917593665686757934951, - 62176457141856560629502157223196586755079324193331, - 64906352462741904929101432445813822663347944758178, - 92575867718337217661963751590579239728245598838407, - 58203565325359399008402633568948830189458628227828, - 80181199384826282014278194139940567587151170094390, - 35398664372827112653829987240784473053190104293586, - 86515506006295864861532075273371959191420517255829, - 71693888707715466499115593487603532921714970056938, - 54370070576826684624621495650076471787294438377604, - 53282654108756828443191190634694037855217779295145, - 36123272525000296071075082563815656710885258350721, - 45876576172410976447339110607218265236877223636045, - 17423706905851860660448207621209813287860733969412, - 81142660418086830619328460811191061556940512689692, - 51934325451728388641918047049293215058642563049483, - 62467221648435076201727918039944693004732956340691, - 15732444386908125794514089057706229429197107928209, - 55037687525678773091862540744969844508330393682126, - 18336384825330154686196124348767681297534375946515, - 80386287592878490201521685554828717201219257766954, - 78182833757993103614740356856449095527097864797581, - 16726320100436897842553539920931837441497806860984, - 48403098129077791799088218795327364475675590848030, - 87086987551392711854517078544161852424320693150332, - 59959406895756536782107074926966537676326235447210, - 69793950679652694742597709739166693763042633987085, - 41052684708299085211399427365734116182760315001271, - 65378607361501080857009149939512557028198746004375, - 35829035317434717326932123578154982629742552737307, - 94953759765105305946966067683156574377167401875275, - 88902802571733229619176668713819931811048770190271, - 25267680276078003013678680992525463401061632866526, - 36270218540497705585629946580636237993140746255962, - 24074486908231174977792365466257246923322810917141, - 91430288197103288597806669760892938638285025333403, - 34413065578016127815921815005561868836468420090470, - 23053081172816430487623791969842487255036638784583, - 11487696932154902810424020138335124462181441773470, - 63783299490636259666498587618221225225512486764533, - 67720186971698544312419572409913959008952310058822, - 95548255300263520781532296796249481641953868218774, - 76085327132285723110424803456124867697064507995236, - 37774242535411291684276865538926205024910326572967, - 23701913275725675285653248258265463092207058596522, - 29798860272258331913126375147341994889534765745501, - 18495701454879288984856827726077713721403798879715, - 38298203783031473527721580348144513491373226651381, - 34829543829199918180278916522431027392251122869539, - 40957953066405232632538044100059654939159879593635, - 29746152185502371307642255121183693803580388584903, - 41698116222072977186158236678424689157993532961922, - 62467957194401269043877107275048102390895523597457, - 23189706772547915061505504953922979530901129967519, - 86188088225875314529584099251203829009407770775672, - 11306739708304724483816533873502340845647058077308, - 82959174767140363198008187129011875491310547126581, - 97623331044818386269515456334926366572897563400500, - 42846280183517070527831839425882145521227251250327, - 55121603546981200581762165212827652751691296897789, - 32238195734329339946437501907836945765883352399886, - 75506164965184775180738168837861091527357929701337, - 62177842752192623401942399639168044983993173312731, - 32924185707147349566916674687634660915035914677504, - 99518671430235219628894890102423325116913619626622, - 73267460800591547471830798392868535206946944540724, - 76841822524674417161514036427982273348055556214818, - 97142617910342598647204516893989422179826088076852, - 87783646182799346313767754307809363333018982642090, - 10848802521674670883215120185883543223812876952786, - 71329612474782464538636993009049310363619763878039, - 62184073572399794223406235393808339651327408011116, - 66627891981488087797941876876144230030984490851411, - 60661826293682836764744779239180335110989069790714, - 85786944089552990653640447425576083659976645795096, - 66024396409905389607120198219976047599490197230297, - 64913982680032973156037120041377903785566085089252, - 16730939319872750275468906903707539413042652315011, - 94809377245048795150954100921645863754710598436791, - 78639167021187492431995700641917969777599028300699, - 15368713711936614952811305876380278410754449733078, - 40789923115535562561142322423255033685442488917353, - 44889911501440648020369068063960672322193204149535, - 41503128880339536053299340368006977710650566631954, - 81234880673210146739058568557934581403627822703280, - 82616570773948327592232845941706525094512325230608, - 22918802058777319719839450180888072429661980811197, - 77158542502016545090413245809786882778948721859617, - 72107838435069186155435662884062257473692284509516, - 20849603980134001723930671666823555245252804609722, - 53503534226472524250874054075591789781264330331690, -) - -# Keep the answer part in str for consistency as some problems could output in str -# Problem 329: 199740353/29386561536000 (Format for this answer is a/b) -# https://github.com/nayuki/Project-Euler-solutions/blob/master/Answers.txt#L191 -ANSWERS = { - 1: QuesAndAns(1000, "233168"), - 2: QuesAndAns(4_000_000, "4613732"), - 3: QuesAndAns(600851475143, "6857"), - 4: QuesAndAns(None, "906609"), - 5: QuesAndAns(20, "232792560"), - 6: QuesAndAns(100, "25164150"), - 7: QuesAndAns(10001, "104743"), - 8: QuesAndAns(QUES_08, "23514624000"), - 9: QuesAndAns(1000, "31875000"), - 10: QuesAndAns(2_000_000, "142913828922"), - 11: QuesAndAns(None, "70600674"), - 12: QuesAndAns(None, "76576500"), - 13: QuesAndAns(QUES_13, "5537376230"), - 14: QuesAndAns(1_000_000, "837799"), - 15: QuesAndAns(None, "137846528820"), - 16: QuesAndAns(1000, "1366"), - 17: QuesAndAns(1000, "21124"), - 18: QuesAndAns(None, "1074"), - 19: QuesAndAns(None, "171"), -} +from typing import Generator, Dict +from types import ModuleType PROJECT_EULER_PATH = pathlib.Path.cwd().joinpath("project_euler") -def generate_solution_modules(dir_path: pathlib.Path): +def generate_solution_modules( + dir_path: pathlib.Path, +) -> Generator[ModuleType, None, None]: # Iterating over every file or directory for file_path in dir_path.iterdir(): if file_path.suffix != ".py" or file_path.name.startswith(("_", "test")): @@ -175,8 +24,7 @@ def generate_solution_modules(dir_path: pathlib.Path): def test_project_euler() -> int: wrong_answer, no_solution, solution_args = [[] for _ in range(3)] - for problem_number, ques_ans in ANSWERS.items(): - parameter, expected = ques_ans + for problem_number, expected in ANSWERS.items(): problem_dir = PROJECT_EULER_PATH.joinpath(f"problem_{problem_number:02}") # By checking if it's a directory we can write all the problem number and # answer pair in ANSWERS variable and not worry whether it is actually @@ -185,31 +33,25 @@ def test_project_euler() -> int: for solution_module in generate_solution_modules(problem_dir): try: answer = str(solution_module.solution()) - if answer != expected: - wrong_answer.append( - f"problem_{problem_number:02}/{solution_module.__name__}: " - f"Expected {expected} but got {answer}" - ) - # TypeError: If solution() requires arguments - # AttributeError: If the module has no attribute called 'solution' + assert answer == expected, f"Expected {expected} but got {answer}" + # If the answer is incorrect + except AssertionError as err: + wrong_answer.append( + f"problem_{problem_number:02}/" + f"{solution_module.__name__}: {err}" + ) + # If the module has no attribute called 'solution' except AttributeError as err: no_solution.append( - f"problem_{problem_number:02}/{solution_module.__name__}: {err}" + f"problem_{problem_number:02}/" + f"{solution_module.__name__}: {err}" ) + # If solution() requires arguments except TypeError as err: - if parameter: - answer = str(solution_module.solution(parameter)) - if answer != expected: - wrong_answer.append( - f"problem_{problem_number:02}/" - f"{solution_module.__name__}: " - f"Expected {expected} but got {answer}" - ) - else: - solution_args.append( - f"problem_{problem_number:02}/" - f"{solution_module.__name__}: {err}" - ) + solution_args.append( + f"problem_{problem_number:02}/" + f"{solution_module.__name__}: {err}" + ) if wrong_answer: print(f"{len(wrong_answer)} files contain wrong answers:\n") print("\n".join(wrong_answer) + "\n") @@ -225,6 +67,735 @@ def test_project_euler() -> int: return len(wrong_answer + solution_args + no_solution) +# https://github.com/luckytoilet/projecteuler-solutions/blob/master/Solutions.md +ANSWERS: Dict[int, str] = { + 1: "233168", + 2: "4613732", + 3: "6857", + 4: "906609", + 5: "232792560", + 6: "25164150", + 7: "104743", + 8: "23514624000", + 9: "31875000", + 10: "142913828922", + 11: "70600674", + 12: "76576500", + 13: "5537376230", + 14: "837799", + 15: "137846528820", + 16: "1366", + 17: "21124", + 18: "1074", + 19: "171", + 20: "648", + 21: "31626", + 22: "871198282", + 23: "4179871", + 24: "2783915460", + 25: "4782", + 26: "983", + 27: "-59231", + 28: "669171001", + 29: "9183", + 30: "443839", + 31: "73682", + 32: "45228", + 33: "100", + 34: "40730", + 35: "55", + 36: "872187", + 37: "748317", + 38: "932718654", + 39: "840", + 40: "210", + 41: "7652413", + 42: "162", + 43: "16695334890", + 44: "5482660", + 45: "1533776805", + 46: "5777", + 47: "134043", + 48: "9110846700", + 49: "296962999629", + 50: "997651", + 51: "121313", + 52: "142857", + 53: "4075", + 54: "376", + 55: "249", + 56: "972", + 57: "153", + 58: "26241", + 59: "129448", + 60: "26033", + 61: "28684", + 62: "127035954683", + 63: "49", + 64: "1322", + 65: "272", + 66: "661", + 67: "7273", + 68: "6531031914842725", + 69: "510510", + 70: "8319823", + 71: "428570", + 72: "303963552391", + 73: "7295372", + 74: "402", + 75: "161667", + 76: "190569291", + 77: "71", + 78: "55374", + 79: "73162890", + 80: "40886", + 81: "427337", + 82: "260324", + 83: "425185", + 84: "101524", + 85: "2772", + 86: "1818", + 87: "1097343", + 88: "7587457", + 89: "743", + 90: "1217", + 91: "14234", + 92: "8581146", + 93: "1258", + 94: "518408346", + 95: "14316", + 96: "24702", + 97: "8739992577", + 98: "18769", + 99: "709", + 100: "756872327473", + 101: "37076114526", + 102: "228", + 103: "20313839404245", + 104: "329468", + 105: "73702", + 106: "21384", + 107: "259679", + 108: "180180", + 109: "38182", + 110: "9350130049860600", + 111: "612407567715", + 112: "1587000", + 113: "51161058134250", + 114: "16475640049", + 115: "168", + 116: "20492570929", + 117: "100808458960497", + 118: "44680", + 119: "248155780267521", + 120: "333082500", + 121: "2269", + 122: "1582", + 123: "21035", + 124: "21417", + 125: "2906969179", + 126: "18522", + 127: "18407904", + 128: "14516824220", + 129: "1000023", + 130: "149253", + 131: "173", + 132: "843296", + 133: "453647705", + 134: "18613426663617118", + 135: "4989", + 136: "2544559", + 137: "1120149658760", + 138: "1118049290473932", + 139: "10057761", + 140: "5673835352990", + 141: "878454337159", + 142: "1006193", + 143: "30758397", + 144: "354", + 145: "608720", + 146: "676333270", + 147: "846910284", + 148: "2129970655314432", + 149: "52852124", + 150: "-271248680", + 151: "0.464399", + 152: "301", + 153: "17971254122360635", + 154: "479742450", + 155: "3857447", + 156: "21295121502550", + 157: "53490", + 158: "409511334375", + 159: "14489159", + 160: "16576", + 161: "20574308184277971", + 162: "3D58725572C62302", + 163: "343047", + 164: "378158756814587", + 165: "2868868", + 166: "7130034", + 167: "3916160068885", + 168: "59206", + 169: "178653872807", + 170: "9857164023", + 171: "142989277", + 172: "227485267000992000", + 173: "1572729", + 174: "209566", + 175: "1,13717420,8", + 176: "96818198400000", + 177: "129325", + 178: "126461847755", + 179: "986262", + 180: "285196020571078987", + 181: "83735848679360680", + 182: "399788195976", + 183: "48861552", + 184: "1725323624056", + 185: "4640261571849533", + 186: "2325629", + 187: "17427258", + 188: "95962097", + 189: "10834893628237824", + 190: "371048281", + 191: "1918080160", + 192: "57060635927998347", + 193: "684465067343069", + 194: "61190912", + 195: "75085391", + 196: "322303240771079935", + 197: "1.710637717", + 198: "52374425", + 199: "0.00396087", + 200: "229161792008", + 201: "115039000", + 202: "1209002624", + 203: "34029210557338", + 204: "2944730", + 205: "0.5731441", + 206: "1389019170", + 207: "44043947822", + 208: "331951449665644800", + 209: "15964587728784", + 210: "1598174770174689458", + 211: "1922364685", + 212: "328968937309", + 213: "330.721154", + 214: "1677366278943", + 215: "806844323190414", + 216: "5437849", + 217: "6273134", + 218: "0", + 219: "64564225042", + 220: "139776,963904", + 221: "1884161251122450", + 222: "1590933", + 223: "61614848", + 224: "4137330", + 225: "2009", + 226: "0.11316017", + 227: "3780.618622", + 228: "86226", + 229: "11325263", + 230: "850481152593119296", + 231: "7526965179680", + 232: "0.83648556", + 233: "271204031455541309", + 234: "1259187438574927161", + 235: "1.002322108633", + 236: "123/59", + 237: "15836928", + 238: "9922545104535661", + 239: "0.001887854841", + 240: "7448717393364181966", + 241: "482316491800641154", + 242: "997104142249036713", + 243: "892371480", + 244: "96356848", + 245: "288084712410001", + 246: "810834388", + 247: "782252", + 248: "23507044290", + 249: "9275262564250418", + 250: "1425480602091519", + 251: "18946051", + 252: "104924.0", + 253: "11.492847", + 254: "8184523820510", + 255: "4.4474011180", + 256: "85765680", + 257: "139012411", + 258: "12747994", + 259: "20101196798", + 260: "167542057", + 261: "238890850232021", + 262: "2531.205", + 263: "2039506520", + 264: "2816417.1055", + 265: "209110240768", + 266: "1096883702440585", + 267: "0.999992836187", + 268: "785478606870985", + 269: "1311109198529286", + 270: "82282080", + 271: "4617456485273129588", + 272: "8495585919506151122", + 273: "2032447591196869022", + 274: "1601912348822", + 275: "15030564", + 276: "5777137137739632912", + 277: "1125977393124310", + 278: "1228215747273908452", + 279: "416577688", + 280: "430.088247", + 281: "1485776387445623", + 282: "1098988351", + 283: "28038042525570324", + 284: "5a411d7b", + 285: "157055.80999", + 286: "52.6494571953", + 287: "313135496", + 288: "605857431263981935", + 289: "6567944538", + 290: "20444710234716473", + 291: "4037526", + 292: "3600060866", + 293: "2209", + 294: "789184709", + 295: "4884650818", + 296: "1137208419", + 297: "2252639041804718029", + 298: "1.76882294", + 299: "549936643", + 300: "8.0540771484375", + 301: "2178309", + 302: "1170060", + 303: "1111981904675169", + 304: "283988410192", + 305: "18174995535140", + 306: "852938", + 307: "0.7311720251", + 308: "1539669807660924", + 309: "210139", + 310: "2586528661783", + 311: "2466018557", + 312: "324681947", + 313: "2057774861813004", + 314: "132.52756426", + 315: "13625242", + 316: "542934735751917735", + 317: "1856532.8455", + 318: "709313889", + 319: "268457129", + 320: "278157919195482643", + 321: "2470433131948040", + 322: "999998760323313995", + 323: "6.3551758451", + 324: "96972774", + 325: "54672965", + 326: "1966666166408794329", + 327: "34315549139516", + 328: "260511850222", + 329: "199740353/29386561536000", + 330: "15955822", + 331: "467178235146843549", + 332: "2717.751525", + 333: "3053105", + 334: "150320021261690835", + 335: "5032316", + 336: "CAGBIHEFJDK", + 337: "85068035", + 338: "15614292", + 339: "19823.542204", + 340: "291504964", + 341: "56098610614277014", + 342: "5943040885644", + 343: "269533451410884183", + 344: "65579304332", + 345: "13938", + 346: "336108797689259276", + 347: "11109800204052", + 348: "1004195061", + 349: "115384615384614952", + 350: "84664213", + 351: "11762187201804552", + 352: "378563.260589", + 353: "1.2759860331", + 354: "58065134", + 355: "1726545007", + 356: "28010159", + 357: "1739023853137", + 358: "3284144505", + 359: "40632119", + 360: "878825614395267072", + 361: "178476944", + 362: "457895958010", + 363: "0.0000372091", + 364: "44855254", + 365: "162619462356610313", + 366: "88351299", + 367: "48271207", + 368: "253.6135092068", + 369: "862400558448", + 370: "41791929448408", + 371: "40.66368097", + 372: "301450082318807027", + 373: "727227472448913", + 374: "334420941", + 375: "7435327983715286168", + 376: "973059630185670", + 377: "732385277", + 378: "147534623725724718", + 379: "132314136838185", + 380: "6.3202e25093", + 381: "139602943319822", + 382: "697003956", + 383: "22173624649806", + 384: "3354706415856332783", + 385: "3776957309612153700", + 386: "528755790", + 387: "696067597313468", + 388: "831907372805129931", + 389: "2406376.3623", + 390: "2919133642971", + 391: "61029882288", + 392: "3.1486734435", + 393: "112398351350823112", + 394: "3.2370342194", + 395: "28.2453753155", + 396: "173214653", + 397: "141630459461893728", + 398: "2010.59096", + 399: "1508395636674243,6.5e27330467", + 400: "438505383468410633", + 401: "281632621", + 402: "356019862", + 403: "18224771", + 404: "1199215615081353", + 405: "237696125", + 406: "36813.12757207", + 407: "39782849136421", + 408: "299742733", + 409: "253223948", + 410: "799999783589946560", + 411: "9936352", + 412: "38788800", + 413: "3079418648040719", + 414: "552506775824935461", + 415: "55859742", + 416: "898082747", + 417: "446572970925740", + 418: "1177163565297340320", + 419: "998567458,1046245404,43363922", + 420: "145159332", + 421: "2304215802083466198", + 422: "92060460", + 423: "653972374", + 424: "1059760019628", + 425: "46479497324", + 426: "31591886008", + 427: "97138867", + 428: "747215561862", + 429: "98792821", + 430: "5000624921.38", + 431: "23.386029052", + 432: "754862080", + 433: "326624372659664", + 434: "863253606", + 435: "252541322550", + 436: "0.5276662759", + 437: "74204709657207", + 438: "2046409616809", + 439: "968697378", + 440: "970746056", + 441: "5000088.8395", + 442: "1295552661530920149", + 443: "2744233049300770", + 444: "1.200856722e263", + 445: "659104042", + 446: "907803852", + 447: "530553372", + 448: "106467648", + 449: "103.37870096", + 450: "583333163984220940", + 451: "153651073760956", + 452: "345558983", + 453: "104354107", + 454: "5435004633092", + 455: "450186511399999", + 456: "333333208685971546", + 457: "2647787126797397063", + 458: "423341841", + 459: "3996390106631", + 460: "18.420738199", + 461: "159820276", + 462: "5.5350769703e1512", + 463: "808981553", + 464: "198775297232878", + 465: "585965659", + 466: "258381958195474745", + 467: "775181359", + 468: "852950321", + 469: "0.56766764161831", + 470: "147668794", + 471: "1.895093981e31", + 472: "73811586", + 473: "35856681704365", + 474: "9690646731515010", + 475: "75780067", + 476: "110242.87794", + 477: "25044905874565165", + 478: "59510340", + 479: "191541795", + 480: "turnthestarson", + 481: "729.12106947", + 482: "1400824879147", + 483: "4.993401567e22", + 484: "8907904768686152599", + 485: "51281274340", + 486: "11408450515", + 487: "106650212746", + 488: "216737278", + 489: "1791954757162", + 490: "777577686", + 491: "194505988824000", + 492: "242586962923928", + 493: "6.818741802", + 494: "2880067194446832666", + 495: "789107601", + 496: "2042473533769142717", + 497: "684901360", + 498: "472294837", + 499: "0.8660312", + 500: "35407281", + 501: "197912312715", + 502: "749485217", + 503: "3.8694550145", + 504: "694687", + 505: "714591308667615832", + 506: "18934502", + 507: "316558047002627270", + 508: "891874596", + 509: "151725678", + 510: "315306518862563689", + 511: "935247012", + 512: "50660591862310323", + 513: "2925619196", + 514: "8986.86698", + 515: "2422639000800", + 516: "939087315", + 517: "581468882", + 518: "100315739184392", + 519: "804739330", + 520: "238413705", + 521: "44389811", + 522: "96772715", + 523: "37125450.44", + 524: "2432925835413407847", + 525: "44.69921807", + 526: "49601160286750947", + 527: "11.92412011", + 528: "779027989", + 529: "23624465", + 530: "207366437157977206", + 531: "4515432351156203105", + 532: "827306.56", + 533: "789453601", + 534: "11726115562784664", + 535: "611778217", + 536: "3557005261906288", + 537: "779429131", + 538: "22472871503401097", + 539: "426334056", + 540: "500000000002845", + 541: "4580726482872451", + 542: "697586734240314852", + 543: "199007746081234640", + 544: "640432376", + 545: "921107572", + 546: "215656873", + 547: "11730879.0023", + 548: "12144044603581281", + 549: "476001479068717", + 550: "328104836", + 551: "73597483551591773", + 552: "326227335", + 553: "57717170", + 554: "89539872", + 555: "208517717451208352", + 556: "52126939292957", + 557: "2699929328", + 558: "226754889", + 559: "684724920", + 560: "994345168", + 561: "452480999988235494", + 562: "51208732914368", + 563: "27186308211734760", + 564: "12363.698850", + 565: "2992480851924313898", + 566: "329569369413585", + 567: "75.44817535", + 568: "4228020", + 569: "21025060", + 570: "271197444", + 571: "30510390701978", + 572: "19737656", + 573: "1252.9809", + 574: "5780447552057000454", + 575: "0.000989640561", + 576: "344457.5871", + 577: "265695031399260211", + 578: "9219696799346", + 579: "3805524", + 580: "2327213148095366", + 581: "2227616372734", + 582: "19903", + 583: "1174137929000", + 584: "32.83822408", + 585: "17714439395932", + 586: "82490213", + 587: "2240", + 588: "11651930052", + 589: "131776959.25", + 590: "834171904", + 591: "526007984625966", + 592: "13415DF2BE9C", + 593: "96632320042.0", + 594: "47067598", + 595: "54.17529329", + 596: "734582049", + 597: "0.5001817828", + 598: "543194779059", + 599: "12395526079546335", + 600: "2668608479740672", + 601: "1617243", + 602: "269496760", + 603: "879476477", + 604: "1398582231101", + 605: "59992576", + 606: "158452775", + 607: "13.1265108586", + 608: "439689828", + 609: "172023848", + 610: "319.30207833", + 611: "49283233900", + 612: "819963842", + 613: "0.3916721504", + 614: "130694090", + 615: "108424772", + 616: "310884668312456458", + 617: "1001133757", + 618: "634212216", + 619: "857810883", + 620: "1470337306", + 621: "11429712", + 622: "3010983666182123972", + 623: "3679796", + 624: "984524441", + 625: "551614306", + 626: "695577663", + 627: "220196142", + 628: "210286684", + 629: "626616617", + 630: "9669182880384", + 631: "869588692", + 632: "728378714", + 633: "1.0012e-10", + 634: "4019680944", + 635: "689294705", + 636: "888316", + 637: "49000634845039", + 638: "18423394", + 639: "797866893", + 640: "50.317928", + 641: "793525366", + 642: "631499044", + 643: "968274154", + 644: "20.11208767", + 645: "48894.2174", + 646: "845218467", + 647: "563132994232918611", + 648: "301483197", + 649: "924668016", + 650: "538319652", + 651: "448233151", + 652: "983924497", + 653: "1130658687", + 654: "815868280", + 655: "2000008332", + 656: "888873503555187", + 657: "219493139", + 658: "958280177", + 659: "238518915714422000", + 660: "474766783", + 661: "646231.2177", + 662: "860873428", + 663: "1884138010064752", + 664: "35295862", + 665: "11541685709674", + 666: "0.48023168", + 667: "1.5276527928", + 668: "2811077773", + 669: "56342087360542122", + 670: "551055065", + 671: "946106780", + 672: "91627537", + 673: "700325380", + 674: "416678753", + 675: "416146418", + 676: "3562668074339584", + 677: "984183023", + 678: "1986065", + 679: "644997092988678", + 680: "563917241", + 681: "2611227421428", + 682: "290872710", + 683: "2.38955315e11", + 684: "922058210", + 685: "662878999", + 686: "193060223", + 687: "0.3285320869", + 688: "110941813", + 689: "0.56565454", + 690: "415157690", + 691: "11570761", + 692: "842043391019219959", + 693: "699161", + 694: "1339784153569958487", + 695: "0.1017786859", + 696: "436944244", + 697: "4343871.06", + 698: "57808202", + 699: "37010438774467572", + 700: "1517926517777556", + 701: "13.51099836", + 702: "622305608172525546", + 703: "843437991", + 704: "501985601490518144", + 705: "480440153", + 706: "884837055", + 707: "652907799", + 708: "28874142998632109", + 709: "773479144", + 710: "1275000", + 711: "541510990", + 712: "413876461", + 713: "788626351539895", + 714: "2.452767775565e20", + 715: "883188017", + 716: "238948623", + 717: "1603036763131", + 718: "228579116", + 719: "128088830547982", + 720: "688081048", + 721: "700792959", + 722: "3.376792776502e132", + 723: "1395793419248", + 724: "18128250110", + 725: "4598797036650685", +} + if __name__ == "__main__": exit_code = test_project_euler() if exit_code: From f90db04d8559d012c74aa6a8e8fc302147dc36cc Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Sun, 27 Sep 2020 09:37:30 +0530 Subject: [PATCH 12/14] Using pytest for testing Project Euler solutions - As we want to fail fast on testing solutions, we need to test using this script first before we use tests written by the author. - As pytest stops testing as soon as it receives a traceback, we need to use pytest-subtests to tell pytest to test all the iterations for the function with given parameters. --- .travis.yml | 4 +- project_euler/validate_solutions.py | 1528 +++++++++++++-------------- 2 files changed, 749 insertions(+), 783 deletions(-) diff --git a/.travis.yml b/.travis.yml index e88d89bd9308..ddf204fc4b6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,14 +12,14 @@ jobs: - black --check . || true - flake8 --ignore=E203,W503 --max-complexity=25 --max-line-length=88 --statistics --count . - scripts/validate_filenames.py # no uppercase, no spaces, in a directory - - project_euler/validate_solutions.py # test project Euler solutions - pip install -r requirements.txt # fast fail on black, flake8, validate_filenames script: - mypy --ignore-missing-imports . || true # https://github.com/python/mypy/issues/7907 - pytest --doctest-modules --ignore=project_euler/ --durations=10 --cov-report=term-missing:skip-covered --cov=. . - name: Project Euler - before_script: pip install pytest-cov + before_script: pip install pytest-cov pytest-subtests script: + - pytest project_euler/validate_solutions.py # fail fast on wrong solution - pytest --doctest-modules --durations=10 --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/ after_success: - scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md diff --git a/project_euler/validate_solutions.py b/project_euler/validate_solutions.py index 624aceda4308..8cfd9644612a 100755 --- a/project_euler/validate_solutions.py +++ b/project_euler/validate_solutions.py @@ -1,11 +1,742 @@ #!/usr/bin/env python3 import importlib.util import pathlib -from typing import Generator, Dict +from typing import Generator, Tuple from types import ModuleType +import pytest + PROJECT_EULER_PATH = pathlib.Path.cwd().joinpath("project_euler") +# https://github.com/luckytoilet/projecteuler-solutions/blob/master/Solutions.md +ANSWERS: Tuple[Tuple[int, str], ...] = ( + (1, "233168"), + (2, "4613732"), + (3, "6857"), + (4, "906609"), + (5, "232792560"), + (6, "25164150"), + (7, "104743"), + (8, "23514624000"), + (9, "31875000"), + (10, "142913828922"), + (11, "70600674"), + (12, "76576500"), + (13, "5537376230"), + (14, "837799"), + (15, "137846528820"), + (16, "1366"), + (17, "21124"), + (18, "1074"), + (19, "171"), + (20, "648"), + (21, "31626"), + (22, "871198282"), + (23, "4179871"), + (24, "2783915460"), + (25, "4782"), + (26, "983"), + (27, "-59231"), + (28, "669171001"), + (29, "9183"), + (30, "443839"), + (31, "73682"), + (32, "45228"), + (33, "100"), + (34, "40730"), + (35, "55"), + (36, "872187"), + (37, "748317"), + (38, "932718654"), + (39, "840"), + (40, "210"), + (41, "7652413"), + (42, "162"), + (43, "16695334890"), + (44, "5482660"), + (45, "1533776805"), + (46, "5777"), + (47, "134043"), + (48, "9110846700"), + (49, "296962999629"), + (50, "997651"), + (51, "121313"), + (52, "142857"), + (53, "4075"), + (54, "376"), + (55, "249"), + (56, "972"), + (57, "153"), + (58, "26241"), + (59, "129448"), + (60, "26033"), + (61, "28684"), + (62, "127035954683"), + (63, "49"), + (64, "1322"), + (65, "272"), + (66, "661"), + (67, "7273"), + (68, "6531031914842725"), + (69, "510510"), + (70, "8319823"), + (71, "428570"), + (72, "303963552391"), + (73, "7295372"), + (74, "402"), + (75, "161667"), + (76, "190569291"), + (77, "71"), + (78, "55374"), + (79, "73162890"), + (80, "40886"), + (81, "427337"), + (82, "260324"), + (83, "425185"), + (84, "101524"), + (85, "2772"), + (86, "1818"), + (87, "1097343"), + (88, "7587457"), + (89, "743"), + (90, "1217"), + (91, "14234"), + (92, "8581146"), + (93, "1258"), + (94, "518408346"), + (95, "14316"), + (96, "24702"), + (97, "8739992577"), + (98, "18769"), + (99, "709"), + (100, "756872327473"), + (101, "37076114526"), + (102, "228"), + (103, "20313839404245"), + (104, "329468"), + (105, "73702"), + (106, "21384"), + (107, "259679"), + (108, "180180"), + (109, "38182"), + (110, "9350130049860600"), + (111, "612407567715"), + (112, "1587000"), + (113, "51161058134250"), + (114, "16475640049"), + (115, "168"), + (116, "20492570929"), + (117, "100808458960497"), + (118, "44680"), + (119, "248155780267521"), + (120, "333082500"), + (121, "2269"), + (122, "1582"), + (123, "21035"), + (124, "21417"), + (125, "2906969179"), + (126, "18522"), + (127, "18407904"), + (128, "14516824220"), + (129, "1000023"), + (130, "149253"), + (131, "173"), + (132, "843296"), + (133, "453647705"), + (134, "18613426663617118"), + (135, "4989"), + (136, "2544559"), + (137, "1120149658760"), + (138, "1118049290473932"), + (139, "10057761"), + (140, "5673835352990"), + (141, "878454337159"), + (142, "1006193"), + (143, "30758397"), + (144, "354"), + (145, "608720"), + (146, "676333270"), + (147, "846910284"), + (148, "2129970655314432"), + (149, "52852124"), + (150, "-271248680"), + (151, "0.464399"), + (152, "301"), + (153, "17971254122360635"), + (154, "479742450"), + (155, "3857447"), + (156, "21295121502550"), + (157, "53490"), + (158, "409511334375"), + (159, "14489159"), + (160, "16576"), + (161, "20574308184277971"), + (162, "3D58725572C62302"), + (163, "343047"), + (164, "378158756814587"), + (165, "2868868"), + (166, "7130034"), + (167, "3916160068885"), + (168, "59206"), + (169, "178653872807"), + (170, "9857164023"), + (171, "142989277"), + (172, "227485267000992000"), + (173, "1572729"), + (174, "209566"), + (175, "1,13717420,8"), + (176, "96818198400000"), + (177, "129325"), + (178, "126461847755"), + (179, "986262"), + (180, "285196020571078987"), + (181, "83735848679360680"), + (182, "399788195976"), + (183, "48861552"), + (184, "1725323624056"), + (185, "4640261571849533"), + (186, "2325629"), + (187, "17427258"), + (188, "95962097"), + (189, "10834893628237824"), + (190, "371048281"), + (191, "1918080160"), + (192, "57060635927998347"), + (193, "684465067343069"), + (194, "61190912"), + (195, "75085391"), + (196, "322303240771079935"), + (197, "1.710637717"), + (198, "52374425"), + (199, "0.00396087"), + (200, "229161792008"), + (201, "115039000"), + (202, "1209002624"), + (203, "34029210557338"), + (204, "2944730"), + (205, "0.5731441"), + (206, "1389019170"), + (207, "44043947822"), + (208, "331951449665644800"), + (209, "15964587728784"), + (210, "1598174770174689458"), + (211, "1922364685"), + (212, "328968937309"), + (213, "330.721154"), + (214, "1677366278943"), + (215, "806844323190414"), + (216, "5437849"), + (217, "6273134"), + (218, "0"), + (219, "64564225042"), + (220, "139776,963904"), + (221, "1884161251122450"), + (222, "1590933"), + (223, "61614848"), + (224, "4137330"), + (225, "2009"), + (226, "0.11316017"), + (227, "3780.618622"), + (228, "86226"), + (229, "11325263"), + (230, "850481152593119296"), + (231, "7526965179680"), + (232, "0.83648556"), + (233, "271204031455541309"), + (234, "1259187438574927161"), + (235, "1.002322108633"), + (236, "123/59"), + (237, "15836928"), + (238, "9922545104535661"), + (239, "0.001887854841"), + (240, "7448717393364181966"), + (241, "482316491800641154"), + (242, "997104142249036713"), + (243, "892371480"), + (244, "96356848"), + (245, "288084712410001"), + (246, "810834388"), + (247, "782252"), + (248, "23507044290"), + (249, "9275262564250418"), + (250, "1425480602091519"), + (251, "18946051"), + (252, "104924.0"), + (253, "11.492847"), + (254, "8184523820510"), + (255, "4.4474011180"), + (256, "85765680"), + (257, "139012411"), + (258, "12747994"), + (259, "20101196798"), + (260, "167542057"), + (261, "238890850232021"), + (262, "2531.205"), + (263, "2039506520"), + (264, "2816417.1055"), + (265, "209110240768"), + (266, "1096883702440585"), + (267, "0.999992836187"), + (268, "785478606870985"), + (269, "1311109198529286"), + (270, "82282080"), + (271, "4617456485273129588"), + (272, "8495585919506151122"), + (273, "2032447591196869022"), + (274, "1601912348822"), + (275, "15030564"), + (276, "5777137137739632912"), + (277, "1125977393124310"), + (278, "1228215747273908452"), + (279, "416577688"), + (280, "430.088247"), + (281, "1485776387445623"), + (282, "1098988351"), + (283, "28038042525570324"), + (284, "5a411d7b"), + (285, "157055.80999"), + (286, "52.6494571953"), + (287, "313135496"), + (288, "605857431263981935"), + (289, "6567944538"), + (290, "20444710234716473"), + (291, "4037526"), + (292, "3600060866"), + (293, "2209"), + (294, "789184709"), + (295, "4884650818"), + (296, "1137208419"), + (297, "2252639041804718029"), + (298, "1.76882294"), + (299, "549936643"), + (300, "8.0540771484375"), + (301, "2178309"), + (302, "1170060"), + (303, "1111981904675169"), + (304, "283988410192"), + (305, "18174995535140"), + (306, "852938"), + (307, "0.7311720251"), + (308, "1539669807660924"), + (309, "210139"), + (310, "2586528661783"), + (311, "2466018557"), + (312, "324681947"), + (313, "2057774861813004"), + (314, "132.52756426"), + (315, "13625242"), + (316, "542934735751917735"), + (317, "1856532.8455"), + (318, "709313889"), + (319, "268457129"), + (320, "278157919195482643"), + (321, "2470433131948040"), + (322, "999998760323313995"), + (323, "6.3551758451"), + (324, "96972774"), + (325, "54672965"), + (326, "1966666166408794329"), + (327, "34315549139516"), + (328, "260511850222"), + (329, "199740353/29386561536000"), + (330, "15955822"), + (331, "467178235146843549"), + (332, "2717.751525"), + (333, "3053105"), + (334, "150320021261690835"), + (335, "5032316"), + (336, "CAGBIHEFJDK"), + (337, "85068035"), + (338, "15614292"), + (339, "19823.542204"), + (340, "291504964"), + (341, "56098610614277014"), + (342, "5943040885644"), + (343, "269533451410884183"), + (344, "65579304332"), + (345, "13938"), + (346, "336108797689259276"), + (347, "11109800204052"), + (348, "1004195061"), + (349, "115384615384614952"), + (350, "84664213"), + (351, "11762187201804552"), + (352, "378563.260589"), + (353, "1.2759860331"), + (354, "58065134"), + (355, "1726545007"), + (356, "28010159"), + (357, "1739023853137"), + (358, "3284144505"), + (359, "40632119"), + (360, "878825614395267072"), + (361, "178476944"), + (362, "457895958010"), + (363, "0.0000372091"), + (364, "44855254"), + (365, "162619462356610313"), + (366, "88351299"), + (367, "48271207"), + (368, "253.6135092068"), + (369, "862400558448"), + (370, "41791929448408"), + (371, "40.66368097"), + (372, "301450082318807027"), + (373, "727227472448913"), + (374, "334420941"), + (375, "7435327983715286168"), + (376, "973059630185670"), + (377, "732385277"), + (378, "147534623725724718"), + (379, "132314136838185"), + (380, "6.3202e25093"), + (381, "139602943319822"), + (382, "697003956"), + (383, "22173624649806"), + (384, "3354706415856332783"), + (385, "3776957309612153700"), + (386, "528755790"), + (387, "696067597313468"), + (388, "831907372805129931"), + (389, "2406376.3623"), + (390, "2919133642971"), + (391, "61029882288"), + (392, "3.1486734435"), + (393, "112398351350823112"), + (394, "3.2370342194"), + (395, "28.2453753155"), + (396, "173214653"), + (397, "141630459461893728"), + (398, "2010.59096"), + (399, "1508395636674243,6.5e27330467"), + (400, "438505383468410633"), + (401, "281632621"), + (402, "356019862"), + (403, "18224771"), + (404, "1199215615081353"), + (405, "237696125"), + (406, "36813.12757207"), + (407, "39782849136421"), + (408, "299742733"), + (409, "253223948"), + (410, "799999783589946560"), + (411, "9936352"), + (412, "38788800"), + (413, "3079418648040719"), + (414, "552506775824935461"), + (415, "55859742"), + (416, "898082747"), + (417, "446572970925740"), + (418, "1177163565297340320"), + (419, "998567458,1046245404,43363922"), + (420, "145159332"), + (421, "2304215802083466198"), + (422, "92060460"), + (423, "653972374"), + (424, "1059760019628"), + (425, "46479497324"), + (426, "31591886008"), + (427, "97138867"), + (428, "747215561862"), + (429, "98792821"), + (430, "5000624921.38"), + (431, "23.386029052"), + (432, "754862080"), + (433, "326624372659664"), + (434, "863253606"), + (435, "252541322550"), + (436, "0.5276662759"), + (437, "74204709657207"), + (438, "2046409616809"), + (439, "968697378"), + (440, "970746056"), + (441, "5000088.8395"), + (442, "1295552661530920149"), + (443, "2744233049300770"), + (444, "1.200856722e263"), + (445, "659104042"), + (446, "907803852"), + (447, "530553372"), + (448, "106467648"), + (449, "103.37870096"), + (450, "583333163984220940"), + (451, "153651073760956"), + (452, "345558983"), + (453, "104354107"), + (454, "5435004633092"), + (455, "450186511399999"), + (456, "333333208685971546"), + (457, "2647787126797397063"), + (458, "423341841"), + (459, "3996390106631"), + (460, "18.420738199"), + (461, "159820276"), + (462, "5.5350769703e1512"), + (463, "808981553"), + (464, "198775297232878"), + (465, "585965659"), + (466, "258381958195474745"), + (467, "775181359"), + (468, "852950321"), + (469, "0.56766764161831"), + (470, "147668794"), + (471, "1.895093981e31"), + (472, "73811586"), + (473, "35856681704365"), + (474, "9690646731515010"), + (475, "75780067"), + (476, "110242.87794"), + (477, "25044905874565165"), + (478, "59510340"), + (479, "191541795"), + (480, "turnthestarson"), + (481, "729.12106947"), + (482, "1400824879147"), + (483, "4.993401567e22"), + (484, "8907904768686152599"), + (485, "51281274340"), + (486, "11408450515"), + (487, "106650212746"), + (488, "216737278"), + (489, "1791954757162"), + (490, "777577686"), + (491, "194505988824000"), + (492, "242586962923928"), + (493, "6.818741802"), + (494, "2880067194446832666"), + (495, "789107601"), + (496, "2042473533769142717"), + (497, "684901360"), + (498, "472294837"), + (499, "0.8660312"), + (500, "35407281"), + (501, "197912312715"), + (502, "749485217"), + (503, "3.8694550145"), + (504, "694687"), + (505, "714591308667615832"), + (506, "18934502"), + (507, "316558047002627270"), + (508, "891874596"), + (509, "151725678"), + (510, "315306518862563689"), + (511, "935247012"), + (512, "50660591862310323"), + (513, "2925619196"), + (514, "8986.86698"), + (515, "2422639000800"), + (516, "939087315"), + (517, "581468882"), + (518, "100315739184392"), + (519, "804739330"), + (520, "238413705"), + (521, "44389811"), + (522, "96772715"), + (523, "37125450.44"), + (524, "2432925835413407847"), + (525, "44.69921807"), + (526, "49601160286750947"), + (527, "11.92412011"), + (528, "779027989"), + (529, "23624465"), + (530, "207366437157977206"), + (531, "4515432351156203105"), + (532, "827306.56"), + (533, "789453601"), + (534, "11726115562784664"), + (535, "611778217"), + (536, "3557005261906288"), + (537, "779429131"), + (538, "22472871503401097"), + (539, "426334056"), + (540, "500000000002845"), + (541, "4580726482872451"), + (542, "697586734240314852"), + (543, "199007746081234640"), + (544, "640432376"), + (545, "921107572"), + (546, "215656873"), + (547, "11730879.0023"), + (548, "12144044603581281"), + (549, "476001479068717"), + (550, "328104836"), + (551, "73597483551591773"), + (552, "326227335"), + (553, "57717170"), + (554, "89539872"), + (555, "208517717451208352"), + (556, "52126939292957"), + (557, "2699929328"), + (558, "226754889"), + (559, "684724920"), + (560, "994345168"), + (561, "452480999988235494"), + (562, "51208732914368"), + (563, "27186308211734760"), + (564, "12363.698850"), + (565, "2992480851924313898"), + (566, "329569369413585"), + (567, "75.44817535"), + (568, "4228020"), + (569, "21025060"), + (570, "271197444"), + (571, "30510390701978"), + (572, "19737656"), + (573, "1252.9809"), + (574, "5780447552057000454"), + (575, "0.000989640561"), + (576, "344457.5871"), + (577, "265695031399260211"), + (578, "9219696799346"), + (579, "3805524"), + (580, "2327213148095366"), + (581, "2227616372734"), + (582, "19903"), + (583, "1174137929000"), + (584, "32.83822408"), + (585, "17714439395932"), + (586, "82490213"), + (587, "2240"), + (588, "11651930052"), + (589, "131776959.25"), + (590, "834171904"), + (591, "526007984625966"), + (592, "13415DF2BE9C"), + (593, "96632320042.0"), + (594, "47067598"), + (595, "54.17529329"), + (596, "734582049"), + (597, "0.5001817828"), + (598, "543194779059"), + (599, "12395526079546335"), + (600, "2668608479740672"), + (601, "1617243"), + (602, "269496760"), + (603, "879476477"), + (604, "1398582231101"), + (605, "59992576"), + (606, "158452775"), + (607, "13.1265108586"), + (608, "439689828"), + (609, "172023848"), + (610, "319.30207833"), + (611, "49283233900"), + (612, "819963842"), + (613, "0.3916721504"), + (614, "130694090"), + (615, "108424772"), + (616, "310884668312456458"), + (617, "1001133757"), + (618, "634212216"), + (619, "857810883"), + (620, "1470337306"), + (621, "11429712"), + (622, "3010983666182123972"), + (623, "3679796"), + (624, "984524441"), + (625, "551614306"), + (626, "695577663"), + (627, "220196142"), + (628, "210286684"), + (629, "626616617"), + (630, "9669182880384"), + (631, "869588692"), + (632, "728378714"), + (633, "1.0012e-10"), + (634, "4019680944"), + (635, "689294705"), + (636, "888316"), + (637, "49000634845039"), + (638, "18423394"), + (639, "797866893"), + (640, "50.317928"), + (641, "793525366"), + (642, "631499044"), + (643, "968274154"), + (644, "20.11208767"), + (645, "48894.2174"), + (646, "845218467"), + (647, "563132994232918611"), + (648, "301483197"), + (649, "924668016"), + (650, "538319652"), + (651, "448233151"), + (652, "983924497"), + (653, "1130658687"), + (654, "815868280"), + (655, "2000008332"), + (656, "888873503555187"), + (657, "219493139"), + (658, "958280177"), + (659, "238518915714422000"), + (660, "474766783"), + (661, "646231.2177"), + (662, "860873428"), + (663, "1884138010064752"), + (664, "35295862"), + (665, "11541685709674"), + (666, "0.48023168"), + (667, "1.5276527928"), + (668, "2811077773"), + (669, "56342087360542122"), + (670, "551055065"), + (671, "946106780"), + (672, "91627537"), + (673, "700325380"), + (674, "416678753"), + (675, "416146418"), + (676, "3562668074339584"), + (677, "984183023"), + (678, "1986065"), + (679, "644997092988678"), + (680, "563917241"), + (681, "2611227421428"), + (682, "290872710"), + (683, "2.38955315e11"), + (684, "922058210"), + (685, "662878999"), + (686, "193060223"), + (687, "0.3285320869"), + (688, "110941813"), + (689, "0.56565454"), + (690, "415157690"), + (691, "11570761"), + (692, "842043391019219959"), + (693, "699161"), + (694, "1339784153569958487"), + (695, "0.1017786859"), + (696, "436944244"), + (697, "4343871.06"), + (698, "57808202"), + (699, "37010438774467572"), + (700, "1517926517777556"), + (701, "13.51099836"), + (702, "622305608172525546"), + (703, "843437991"), + (704, "501985601490518144"), + (705, "480440153"), + (706, "884837055"), + (707, "652907799"), + (708, "28874142998632109"), + (709, "773479144"), + (710, "1275000"), + (711, "541510990"), + (712, "413876461"), + (713, "788626351539895"), + (714, "2.452767775565e20"), + (715, "883188017"), + (716, "238948623"), + (717, "1603036763131"), + (718, "228579116"), + (719, "128088830547982"), + (720, "688081048"), + (721, "700792959"), + (722, "3.376792776502e132"), + (723, "1395793419248"), + (724, "18128250110"), + (725, "4598797036650685"), +) + def generate_solution_modules( dir_path: pathlib.Path, @@ -22,783 +753,18 @@ def generate_solution_modules( yield module -def test_project_euler() -> int: - wrong_answer, no_solution, solution_args = [[] for _ in range(3)] - for problem_number, expected in ANSWERS.items(): - problem_dir = PROJECT_EULER_PATH.joinpath(f"problem_{problem_number:02}") - # By checking if it's a directory we can write all the problem number and - # answer pair in ANSWERS variable and not worry whether it is actually - # present in the 'project_euler' directory - if problem_dir.is_dir(): - for solution_module in generate_solution_modules(problem_dir): - try: - answer = str(solution_module.solution()) - assert answer == expected, f"Expected {expected} but got {answer}" - # If the answer is incorrect - except AssertionError as err: - wrong_answer.append( - f"problem_{problem_number:02}/" - f"{solution_module.__name__}: {err}" - ) - # If the module has no attribute called 'solution' - except AttributeError as err: - no_solution.append( - f"problem_{problem_number:02}/" - f"{solution_module.__name__}: {err}" - ) - # If solution() requires arguments - except TypeError as err: - solution_args.append( - f"problem_{problem_number:02}/" - f"{solution_module.__name__}: {err}" - ) - if wrong_answer: - print(f"{len(wrong_answer)} files contain wrong answers:\n") - print("\n".join(wrong_answer) + "\n") - if solution_args: - print( - f"{len(solution_args)} " - f"files require positional arguments for solution() function:\n" - ) - print("\n".join(solution_args) + "\n") - if no_solution: - print(f"{len(no_solution)} files have no solution() function:\n") - print("\n".join(no_solution) + "\n") - return len(wrong_answer + solution_args + no_solution) - - -# https://github.com/luckytoilet/projecteuler-solutions/blob/master/Solutions.md -ANSWERS: Dict[int, str] = { - 1: "233168", - 2: "4613732", - 3: "6857", - 4: "906609", - 5: "232792560", - 6: "25164150", - 7: "104743", - 8: "23514624000", - 9: "31875000", - 10: "142913828922", - 11: "70600674", - 12: "76576500", - 13: "5537376230", - 14: "837799", - 15: "137846528820", - 16: "1366", - 17: "21124", - 18: "1074", - 19: "171", - 20: "648", - 21: "31626", - 22: "871198282", - 23: "4179871", - 24: "2783915460", - 25: "4782", - 26: "983", - 27: "-59231", - 28: "669171001", - 29: "9183", - 30: "443839", - 31: "73682", - 32: "45228", - 33: "100", - 34: "40730", - 35: "55", - 36: "872187", - 37: "748317", - 38: "932718654", - 39: "840", - 40: "210", - 41: "7652413", - 42: "162", - 43: "16695334890", - 44: "5482660", - 45: "1533776805", - 46: "5777", - 47: "134043", - 48: "9110846700", - 49: "296962999629", - 50: "997651", - 51: "121313", - 52: "142857", - 53: "4075", - 54: "376", - 55: "249", - 56: "972", - 57: "153", - 58: "26241", - 59: "129448", - 60: "26033", - 61: "28684", - 62: "127035954683", - 63: "49", - 64: "1322", - 65: "272", - 66: "661", - 67: "7273", - 68: "6531031914842725", - 69: "510510", - 70: "8319823", - 71: "428570", - 72: "303963552391", - 73: "7295372", - 74: "402", - 75: "161667", - 76: "190569291", - 77: "71", - 78: "55374", - 79: "73162890", - 80: "40886", - 81: "427337", - 82: "260324", - 83: "425185", - 84: "101524", - 85: "2772", - 86: "1818", - 87: "1097343", - 88: "7587457", - 89: "743", - 90: "1217", - 91: "14234", - 92: "8581146", - 93: "1258", - 94: "518408346", - 95: "14316", - 96: "24702", - 97: "8739992577", - 98: "18769", - 99: "709", - 100: "756872327473", - 101: "37076114526", - 102: "228", - 103: "20313839404245", - 104: "329468", - 105: "73702", - 106: "21384", - 107: "259679", - 108: "180180", - 109: "38182", - 110: "9350130049860600", - 111: "612407567715", - 112: "1587000", - 113: "51161058134250", - 114: "16475640049", - 115: "168", - 116: "20492570929", - 117: "100808458960497", - 118: "44680", - 119: "248155780267521", - 120: "333082500", - 121: "2269", - 122: "1582", - 123: "21035", - 124: "21417", - 125: "2906969179", - 126: "18522", - 127: "18407904", - 128: "14516824220", - 129: "1000023", - 130: "149253", - 131: "173", - 132: "843296", - 133: "453647705", - 134: "18613426663617118", - 135: "4989", - 136: "2544559", - 137: "1120149658760", - 138: "1118049290473932", - 139: "10057761", - 140: "5673835352990", - 141: "878454337159", - 142: "1006193", - 143: "30758397", - 144: "354", - 145: "608720", - 146: "676333270", - 147: "846910284", - 148: "2129970655314432", - 149: "52852124", - 150: "-271248680", - 151: "0.464399", - 152: "301", - 153: "17971254122360635", - 154: "479742450", - 155: "3857447", - 156: "21295121502550", - 157: "53490", - 158: "409511334375", - 159: "14489159", - 160: "16576", - 161: "20574308184277971", - 162: "3D58725572C62302", - 163: "343047", - 164: "378158756814587", - 165: "2868868", - 166: "7130034", - 167: "3916160068885", - 168: "59206", - 169: "178653872807", - 170: "9857164023", - 171: "142989277", - 172: "227485267000992000", - 173: "1572729", - 174: "209566", - 175: "1,13717420,8", - 176: "96818198400000", - 177: "129325", - 178: "126461847755", - 179: "986262", - 180: "285196020571078987", - 181: "83735848679360680", - 182: "399788195976", - 183: "48861552", - 184: "1725323624056", - 185: "4640261571849533", - 186: "2325629", - 187: "17427258", - 188: "95962097", - 189: "10834893628237824", - 190: "371048281", - 191: "1918080160", - 192: "57060635927998347", - 193: "684465067343069", - 194: "61190912", - 195: "75085391", - 196: "322303240771079935", - 197: "1.710637717", - 198: "52374425", - 199: "0.00396087", - 200: "229161792008", - 201: "115039000", - 202: "1209002624", - 203: "34029210557338", - 204: "2944730", - 205: "0.5731441", - 206: "1389019170", - 207: "44043947822", - 208: "331951449665644800", - 209: "15964587728784", - 210: "1598174770174689458", - 211: "1922364685", - 212: "328968937309", - 213: "330.721154", - 214: "1677366278943", - 215: "806844323190414", - 216: "5437849", - 217: "6273134", - 218: "0", - 219: "64564225042", - 220: "139776,963904", - 221: "1884161251122450", - 222: "1590933", - 223: "61614848", - 224: "4137330", - 225: "2009", - 226: "0.11316017", - 227: "3780.618622", - 228: "86226", - 229: "11325263", - 230: "850481152593119296", - 231: "7526965179680", - 232: "0.83648556", - 233: "271204031455541309", - 234: "1259187438574927161", - 235: "1.002322108633", - 236: "123/59", - 237: "15836928", - 238: "9922545104535661", - 239: "0.001887854841", - 240: "7448717393364181966", - 241: "482316491800641154", - 242: "997104142249036713", - 243: "892371480", - 244: "96356848", - 245: "288084712410001", - 246: "810834388", - 247: "782252", - 248: "23507044290", - 249: "9275262564250418", - 250: "1425480602091519", - 251: "18946051", - 252: "104924.0", - 253: "11.492847", - 254: "8184523820510", - 255: "4.4474011180", - 256: "85765680", - 257: "139012411", - 258: "12747994", - 259: "20101196798", - 260: "167542057", - 261: "238890850232021", - 262: "2531.205", - 263: "2039506520", - 264: "2816417.1055", - 265: "209110240768", - 266: "1096883702440585", - 267: "0.999992836187", - 268: "785478606870985", - 269: "1311109198529286", - 270: "82282080", - 271: "4617456485273129588", - 272: "8495585919506151122", - 273: "2032447591196869022", - 274: "1601912348822", - 275: "15030564", - 276: "5777137137739632912", - 277: "1125977393124310", - 278: "1228215747273908452", - 279: "416577688", - 280: "430.088247", - 281: "1485776387445623", - 282: "1098988351", - 283: "28038042525570324", - 284: "5a411d7b", - 285: "157055.80999", - 286: "52.6494571953", - 287: "313135496", - 288: "605857431263981935", - 289: "6567944538", - 290: "20444710234716473", - 291: "4037526", - 292: "3600060866", - 293: "2209", - 294: "789184709", - 295: "4884650818", - 296: "1137208419", - 297: "2252639041804718029", - 298: "1.76882294", - 299: "549936643", - 300: "8.0540771484375", - 301: "2178309", - 302: "1170060", - 303: "1111981904675169", - 304: "283988410192", - 305: "18174995535140", - 306: "852938", - 307: "0.7311720251", - 308: "1539669807660924", - 309: "210139", - 310: "2586528661783", - 311: "2466018557", - 312: "324681947", - 313: "2057774861813004", - 314: "132.52756426", - 315: "13625242", - 316: "542934735751917735", - 317: "1856532.8455", - 318: "709313889", - 319: "268457129", - 320: "278157919195482643", - 321: "2470433131948040", - 322: "999998760323313995", - 323: "6.3551758451", - 324: "96972774", - 325: "54672965", - 326: "1966666166408794329", - 327: "34315549139516", - 328: "260511850222", - 329: "199740353/29386561536000", - 330: "15955822", - 331: "467178235146843549", - 332: "2717.751525", - 333: "3053105", - 334: "150320021261690835", - 335: "5032316", - 336: "CAGBIHEFJDK", - 337: "85068035", - 338: "15614292", - 339: "19823.542204", - 340: "291504964", - 341: "56098610614277014", - 342: "5943040885644", - 343: "269533451410884183", - 344: "65579304332", - 345: "13938", - 346: "336108797689259276", - 347: "11109800204052", - 348: "1004195061", - 349: "115384615384614952", - 350: "84664213", - 351: "11762187201804552", - 352: "378563.260589", - 353: "1.2759860331", - 354: "58065134", - 355: "1726545007", - 356: "28010159", - 357: "1739023853137", - 358: "3284144505", - 359: "40632119", - 360: "878825614395267072", - 361: "178476944", - 362: "457895958010", - 363: "0.0000372091", - 364: "44855254", - 365: "162619462356610313", - 366: "88351299", - 367: "48271207", - 368: "253.6135092068", - 369: "862400558448", - 370: "41791929448408", - 371: "40.66368097", - 372: "301450082318807027", - 373: "727227472448913", - 374: "334420941", - 375: "7435327983715286168", - 376: "973059630185670", - 377: "732385277", - 378: "147534623725724718", - 379: "132314136838185", - 380: "6.3202e25093", - 381: "139602943319822", - 382: "697003956", - 383: "22173624649806", - 384: "3354706415856332783", - 385: "3776957309612153700", - 386: "528755790", - 387: "696067597313468", - 388: "831907372805129931", - 389: "2406376.3623", - 390: "2919133642971", - 391: "61029882288", - 392: "3.1486734435", - 393: "112398351350823112", - 394: "3.2370342194", - 395: "28.2453753155", - 396: "173214653", - 397: "141630459461893728", - 398: "2010.59096", - 399: "1508395636674243,6.5e27330467", - 400: "438505383468410633", - 401: "281632621", - 402: "356019862", - 403: "18224771", - 404: "1199215615081353", - 405: "237696125", - 406: "36813.12757207", - 407: "39782849136421", - 408: "299742733", - 409: "253223948", - 410: "799999783589946560", - 411: "9936352", - 412: "38788800", - 413: "3079418648040719", - 414: "552506775824935461", - 415: "55859742", - 416: "898082747", - 417: "446572970925740", - 418: "1177163565297340320", - 419: "998567458,1046245404,43363922", - 420: "145159332", - 421: "2304215802083466198", - 422: "92060460", - 423: "653972374", - 424: "1059760019628", - 425: "46479497324", - 426: "31591886008", - 427: "97138867", - 428: "747215561862", - 429: "98792821", - 430: "5000624921.38", - 431: "23.386029052", - 432: "754862080", - 433: "326624372659664", - 434: "863253606", - 435: "252541322550", - 436: "0.5276662759", - 437: "74204709657207", - 438: "2046409616809", - 439: "968697378", - 440: "970746056", - 441: "5000088.8395", - 442: "1295552661530920149", - 443: "2744233049300770", - 444: "1.200856722e263", - 445: "659104042", - 446: "907803852", - 447: "530553372", - 448: "106467648", - 449: "103.37870096", - 450: "583333163984220940", - 451: "153651073760956", - 452: "345558983", - 453: "104354107", - 454: "5435004633092", - 455: "450186511399999", - 456: "333333208685971546", - 457: "2647787126797397063", - 458: "423341841", - 459: "3996390106631", - 460: "18.420738199", - 461: "159820276", - 462: "5.5350769703e1512", - 463: "808981553", - 464: "198775297232878", - 465: "585965659", - 466: "258381958195474745", - 467: "775181359", - 468: "852950321", - 469: "0.56766764161831", - 470: "147668794", - 471: "1.895093981e31", - 472: "73811586", - 473: "35856681704365", - 474: "9690646731515010", - 475: "75780067", - 476: "110242.87794", - 477: "25044905874565165", - 478: "59510340", - 479: "191541795", - 480: "turnthestarson", - 481: "729.12106947", - 482: "1400824879147", - 483: "4.993401567e22", - 484: "8907904768686152599", - 485: "51281274340", - 486: "11408450515", - 487: "106650212746", - 488: "216737278", - 489: "1791954757162", - 490: "777577686", - 491: "194505988824000", - 492: "242586962923928", - 493: "6.818741802", - 494: "2880067194446832666", - 495: "789107601", - 496: "2042473533769142717", - 497: "684901360", - 498: "472294837", - 499: "0.8660312", - 500: "35407281", - 501: "197912312715", - 502: "749485217", - 503: "3.8694550145", - 504: "694687", - 505: "714591308667615832", - 506: "18934502", - 507: "316558047002627270", - 508: "891874596", - 509: "151725678", - 510: "315306518862563689", - 511: "935247012", - 512: "50660591862310323", - 513: "2925619196", - 514: "8986.86698", - 515: "2422639000800", - 516: "939087315", - 517: "581468882", - 518: "100315739184392", - 519: "804739330", - 520: "238413705", - 521: "44389811", - 522: "96772715", - 523: "37125450.44", - 524: "2432925835413407847", - 525: "44.69921807", - 526: "49601160286750947", - 527: "11.92412011", - 528: "779027989", - 529: "23624465", - 530: "207366437157977206", - 531: "4515432351156203105", - 532: "827306.56", - 533: "789453601", - 534: "11726115562784664", - 535: "611778217", - 536: "3557005261906288", - 537: "779429131", - 538: "22472871503401097", - 539: "426334056", - 540: "500000000002845", - 541: "4580726482872451", - 542: "697586734240314852", - 543: "199007746081234640", - 544: "640432376", - 545: "921107572", - 546: "215656873", - 547: "11730879.0023", - 548: "12144044603581281", - 549: "476001479068717", - 550: "328104836", - 551: "73597483551591773", - 552: "326227335", - 553: "57717170", - 554: "89539872", - 555: "208517717451208352", - 556: "52126939292957", - 557: "2699929328", - 558: "226754889", - 559: "684724920", - 560: "994345168", - 561: "452480999988235494", - 562: "51208732914368", - 563: "27186308211734760", - 564: "12363.698850", - 565: "2992480851924313898", - 566: "329569369413585", - 567: "75.44817535", - 568: "4228020", - 569: "21025060", - 570: "271197444", - 571: "30510390701978", - 572: "19737656", - 573: "1252.9809", - 574: "5780447552057000454", - 575: "0.000989640561", - 576: "344457.5871", - 577: "265695031399260211", - 578: "9219696799346", - 579: "3805524", - 580: "2327213148095366", - 581: "2227616372734", - 582: "19903", - 583: "1174137929000", - 584: "32.83822408", - 585: "17714439395932", - 586: "82490213", - 587: "2240", - 588: "11651930052", - 589: "131776959.25", - 590: "834171904", - 591: "526007984625966", - 592: "13415DF2BE9C", - 593: "96632320042.0", - 594: "47067598", - 595: "54.17529329", - 596: "734582049", - 597: "0.5001817828", - 598: "543194779059", - 599: "12395526079546335", - 600: "2668608479740672", - 601: "1617243", - 602: "269496760", - 603: "879476477", - 604: "1398582231101", - 605: "59992576", - 606: "158452775", - 607: "13.1265108586", - 608: "439689828", - 609: "172023848", - 610: "319.30207833", - 611: "49283233900", - 612: "819963842", - 613: "0.3916721504", - 614: "130694090", - 615: "108424772", - 616: "310884668312456458", - 617: "1001133757", - 618: "634212216", - 619: "857810883", - 620: "1470337306", - 621: "11429712", - 622: "3010983666182123972", - 623: "3679796", - 624: "984524441", - 625: "551614306", - 626: "695577663", - 627: "220196142", - 628: "210286684", - 629: "626616617", - 630: "9669182880384", - 631: "869588692", - 632: "728378714", - 633: "1.0012e-10", - 634: "4019680944", - 635: "689294705", - 636: "888316", - 637: "49000634845039", - 638: "18423394", - 639: "797866893", - 640: "50.317928", - 641: "793525366", - 642: "631499044", - 643: "968274154", - 644: "20.11208767", - 645: "48894.2174", - 646: "845218467", - 647: "563132994232918611", - 648: "301483197", - 649: "924668016", - 650: "538319652", - 651: "448233151", - 652: "983924497", - 653: "1130658687", - 654: "815868280", - 655: "2000008332", - 656: "888873503555187", - 657: "219493139", - 658: "958280177", - 659: "238518915714422000", - 660: "474766783", - 661: "646231.2177", - 662: "860873428", - 663: "1884138010064752", - 664: "35295862", - 665: "11541685709674", - 666: "0.48023168", - 667: "1.5276527928", - 668: "2811077773", - 669: "56342087360542122", - 670: "551055065", - 671: "946106780", - 672: "91627537", - 673: "700325380", - 674: "416678753", - 675: "416146418", - 676: "3562668074339584", - 677: "984183023", - 678: "1986065", - 679: "644997092988678", - 680: "563917241", - 681: "2611227421428", - 682: "290872710", - 683: "2.38955315e11", - 684: "922058210", - 685: "662878999", - 686: "193060223", - 687: "0.3285320869", - 688: "110941813", - 689: "0.56565454", - 690: "415157690", - 691: "11570761", - 692: "842043391019219959", - 693: "699161", - 694: "1339784153569958487", - 695: "0.1017786859", - 696: "436944244", - 697: "4343871.06", - 698: "57808202", - 699: "37010438774467572", - 700: "1517926517777556", - 701: "13.51099836", - 702: "622305608172525546", - 703: "843437991", - 704: "501985601490518144", - 705: "480440153", - 706: "884837055", - 707: "652907799", - 708: "28874142998632109", - 709: "773479144", - 710: "1275000", - 711: "541510990", - 712: "413876461", - 713: "788626351539895", - 714: "2.452767775565e20", - 715: "883188017", - 716: "238948623", - 717: "1603036763131", - 718: "228579116", - 719: "128088830547982", - 720: "688081048", - 721: "700792959", - 722: "3.376792776502e132", - 723: "1395793419248", - 724: "18128250110", - 725: "4598797036650685", -} - -if __name__ == "__main__": - exit_code = test_project_euler() - if exit_code: - import sys - - sys.exit(exit_code) +@pytest.mark.parametrize("problem_number, expected", ANSWERS) +def test_project_euler(subtests, problem_number: int, expected: str): + problem_dir = PROJECT_EULER_PATH.joinpath(f"problem_{problem_number:02}") + # By checking if it's a directory we can write all the problem number and + # answer pair in ANSWERS variable and not worry whether it is actually + # present in the 'project_euler' directory + if problem_dir.is_dir(): + for solution_module in generate_solution_modules(problem_dir): + with subtests.test( + msg=f"Problem {problem_number} tests", solution_module=solution_module + ): + answer = str(solution_module.solution()) + assert answer == expected, f"Expected {expected} but got {answer}" + else: + pytest.skip("Solution doesn't exists yet.") From 2fd50e70c54666fec6e0c289895cfb23c4a211aa Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Sun, 27 Sep 2020 23:58:04 +0530 Subject: [PATCH 13/14] Print error messages in oneline format --- .travis.yml | 5 +++-- project_euler/validate_solutions.py | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index ddf204fc4b6e..0602fd6649ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,9 +17,10 @@ jobs: - mypy --ignore-missing-imports . || true # https://github.com/python/mypy/issues/7907 - pytest --doctest-modules --ignore=project_euler/ --durations=10 --cov-report=term-missing:skip-covered --cov=. . - name: Project Euler - before_script: pip install pytest-cov pytest-subtests + before_script: + - pip install pytest-cov pytest-subtests + - pytest --tb=no --no-summary --capture=no project_euler/validate_solutions.py # fail fast on wrong solution script: - - pytest project_euler/validate_solutions.py # fail fast on wrong solution - pytest --doctest-modules --durations=10 --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/ after_success: - scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md diff --git a/project_euler/validate_solutions.py b/project_euler/validate_solutions.py index 8cfd9644612a..10b2e80376f4 100755 --- a/project_euler/validate_solutions.py +++ b/project_euler/validate_solutions.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 import importlib.util import pathlib -from typing import Generator, Tuple from types import ModuleType +from typing import Generator, Tuple import pytest @@ -737,6 +737,8 @@ (725, "4598797036650685"), ) +error_msgs = [] + def generate_solution_modules( dir_path: pathlib.Path, @@ -764,7 +766,18 @@ def test_project_euler(subtests, problem_number: int, expected: str): with subtests.test( msg=f"Problem {problem_number} tests", solution_module=solution_module ): - answer = str(solution_module.solution()) - assert answer == expected, f"Expected {expected} but got {answer}" + try: + answer = str(solution_module.solution()) + assert answer == expected, f"Expected {expected} but got {answer}" + except (AssertionError, AttributeError, TypeError) as err: + error_msgs.append( + f"problem_{problem_number}/{solution_module.__name__}: {err}" + ) + raise else: pytest.skip("Solution doesn't exists yet.") + + +def test_print_error_msgs(): + if error_msgs: + print("\n" + "\n".join(error_msgs) + "\n") From 9d62652eed599679a6ef26564c8b45ce59ded241 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Mon, 28 Sep 2020 08:51:03 +0530 Subject: [PATCH 14/14] Separated answers into a separate file: - Add custom print function to print all the error messages at the end of all the tests - Let Travis skip if this failed --- .travis.yml | 2 +- project_euler/project_euler_answers.json | 2902 ++++++++++++++++++++++ project_euler/validate_solutions.py | 764 +----- 3 files changed, 2927 insertions(+), 741 deletions(-) create mode 100644 project_euler/project_euler_answers.json diff --git a/.travis.yml b/.travis.yml index 0602fd6649ff..f794cde82688 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ jobs: - name: Project Euler before_script: - pip install pytest-cov pytest-subtests - - pytest --tb=no --no-summary --capture=no project_euler/validate_solutions.py # fail fast on wrong solution + - pytest --tb=no --no-summary --capture=no project_euler/validate_solutions.py || true # fail fast on wrong solution script: - pytest --doctest-modules --durations=10 --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/ after_success: diff --git a/project_euler/project_euler_answers.json b/project_euler/project_euler_answers.json new file mode 100644 index 000000000000..3c4cc694e685 --- /dev/null +++ b/project_euler/project_euler_answers.json @@ -0,0 +1,2902 @@ +[ + [ + 1, + "233168" + ], + [ + 2, + "4613732" + ], + [ + 3, + "6857" + ], + [ + 4, + "906609" + ], + [ + 5, + "232792560" + ], + [ + 6, + "25164150" + ], + [ + 7, + "104743" + ], + [ + 8, + "23514624000" + ], + [ + 9, + "31875000" + ], + [ + 10, + "142913828922" + ], + [ + 11, + "70600674" + ], + [ + 12, + "76576500" + ], + [ + 13, + "5537376230" + ], + [ + 14, + "837799" + ], + [ + 15, + "137846528820" + ], + [ + 16, + "1366" + ], + [ + 17, + "21124" + ], + [ + 18, + "1074" + ], + [ + 19, + "171" + ], + [ + 20, + "648" + ], + [ + 21, + "31626" + ], + [ + 22, + "871198282" + ], + [ + 23, + "4179871" + ], + [ + 24, + "2783915460" + ], + [ + 25, + "4782" + ], + [ + 26, + "983" + ], + [ + 27, + "-59231" + ], + [ + 28, + "669171001" + ], + [ + 29, + "9183" + ], + [ + 30, + "443839" + ], + [ + 31, + "73682" + ], + [ + 32, + "45228" + ], + [ + 33, + "100" + ], + [ + 34, + "40730" + ], + [ + 35, + "55" + ], + [ + 36, + "872187" + ], + [ + 37, + "748317" + ], + [ + 38, + "932718654" + ], + [ + 39, + "840" + ], + [ + 40, + "210" + ], + [ + 41, + "7652413" + ], + [ + 42, + "162" + ], + [ + 43, + "16695334890" + ], + [ + 44, + "5482660" + ], + [ + 45, + "1533776805" + ], + [ + 46, + "5777" + ], + [ + 47, + "134043" + ], + [ + 48, + "9110846700" + ], + [ + 49, + "296962999629" + ], + [ + 50, + "997651" + ], + [ + 51, + "121313" + ], + [ + 52, + "142857" + ], + [ + 53, + "4075" + ], + [ + 54, + "376" + ], + [ + 55, + "249" + ], + [ + 56, + "972" + ], + [ + 57, + "153" + ], + [ + 58, + "26241" + ], + [ + 59, + "129448" + ], + [ + 60, + "26033" + ], + [ + 61, + "28684" + ], + [ + 62, + "127035954683" + ], + [ + 63, + "49" + ], + [ + 64, + "1322" + ], + [ + 65, + "272" + ], + [ + 66, + "661" + ], + [ + 67, + "7273" + ], + [ + 68, + "6531031914842725" + ], + [ + 69, + "510510" + ], + [ + 70, + "8319823" + ], + [ + 71, + "428570" + ], + [ + 72, + "303963552391" + ], + [ + 73, + "7295372" + ], + [ + 74, + "402" + ], + [ + 75, + "161667" + ], + [ + 76, + "190569291" + ], + [ + 77, + "71" + ], + [ + 78, + "55374" + ], + [ + 79, + "73162890" + ], + [ + 80, + "40886" + ], + [ + 81, + "427337" + ], + [ + 82, + "260324" + ], + [ + 83, + "425185" + ], + [ + 84, + "101524" + ], + [ + 85, + "2772" + ], + [ + 86, + "1818" + ], + [ + 87, + "1097343" + ], + [ + 88, + "7587457" + ], + [ + 89, + "743" + ], + [ + 90, + "1217" + ], + [ + 91, + "14234" + ], + [ + 92, + "8581146" + ], + [ + 93, + "1258" + ], + [ + 94, + "518408346" + ], + [ + 95, + "14316" + ], + [ + 96, + "24702" + ], + [ + 97, + "8739992577" + ], + [ + 98, + "18769" + ], + [ + 99, + "709" + ], + [ + 100, + "756872327473" + ], + [ + 101, + "37076114526" + ], + [ + 102, + "228" + ], + [ + 103, + "20313839404245" + ], + [ + 104, + "329468" + ], + [ + 105, + "73702" + ], + [ + 106, + "21384" + ], + [ + 107, + "259679" + ], + [ + 108, + "180180" + ], + [ + 109, + "38182" + ], + [ + 110, + "9350130049860600" + ], + [ + 111, + "612407567715" + ], + [ + 112, + "1587000" + ], + [ + 113, + "51161058134250" + ], + [ + 114, + "16475640049" + ], + [ + 115, + "168" + ], + [ + 116, + "20492570929" + ], + [ + 117, + "100808458960497" + ], + [ + 118, + "44680" + ], + [ + 119, + "248155780267521" + ], + [ + 120, + "333082500" + ], + [ + 121, + "2269" + ], + [ + 122, + "1582" + ], + [ + 123, + "21035" + ], + [ + 124, + "21417" + ], + [ + 125, + "2906969179" + ], + [ + 126, + "18522" + ], + [ + 127, + "18407904" + ], + [ + 128, + "14516824220" + ], + [ + 129, + "1000023" + ], + [ + 130, + "149253" + ], + [ + 131, + "173" + ], + [ + 132, + "843296" + ], + [ + 133, + "453647705" + ], + [ + 134, + "18613426663617118" + ], + [ + 135, + "4989" + ], + [ + 136, + "2544559" + ], + [ + 137, + "1120149658760" + ], + [ + 138, + "1118049290473932" + ], + [ + 139, + "10057761" + ], + [ + 140, + "5673835352990" + ], + [ + 141, + "878454337159" + ], + [ + 142, + "1006193" + ], + [ + 143, + "30758397" + ], + [ + 144, + "354" + ], + [ + 145, + "608720" + ], + [ + 146, + "676333270" + ], + [ + 147, + "846910284" + ], + [ + 148, + "2129970655314432" + ], + [ + 149, + "52852124" + ], + [ + 150, + "-271248680" + ], + [ + 151, + "0.464399" + ], + [ + 152, + "301" + ], + [ + 153, + "17971254122360635" + ], + [ + 154, + "479742450" + ], + [ + 155, + "3857447" + ], + [ + 156, + "21295121502550" + ], + [ + 157, + "53490" + ], + [ + 158, + "409511334375" + ], + [ + 159, + "14489159" + ], + [ + 160, + "16576" + ], + [ + 161, + "20574308184277971" + ], + [ + 162, + "3D58725572C62302" + ], + [ + 163, + "343047" + ], + [ + 164, + "378158756814587" + ], + [ + 165, + "2868868" + ], + [ + 166, + "7130034" + ], + [ + 167, + "3916160068885" + ], + [ + 168, + "59206" + ], + [ + 169, + "178653872807" + ], + [ + 170, + "9857164023" + ], + [ + 171, + "142989277" + ], + [ + 172, + "227485267000992000" + ], + [ + 173, + "1572729" + ], + [ + 174, + "209566" + ], + [ + 175, + "1,13717420,8" + ], + [ + 176, + "96818198400000" + ], + [ + 177, + "129325" + ], + [ + 178, + "126461847755" + ], + [ + 179, + "986262" + ], + [ + 180, + "285196020571078987" + ], + [ + 181, + "83735848679360680" + ], + [ + 182, + "399788195976" + ], + [ + 183, + "48861552" + ], + [ + 184, + "1725323624056" + ], + [ + 185, + "4640261571849533" + ], + [ + 186, + "2325629" + ], + [ + 187, + "17427258" + ], + [ + 188, + "95962097" + ], + [ + 189, + "10834893628237824" + ], + [ + 190, + "371048281" + ], + [ + 191, + "1918080160" + ], + [ + 192, + "57060635927998347" + ], + [ + 193, + "684465067343069" + ], + [ + 194, + "61190912" + ], + [ + 195, + "75085391" + ], + [ + 196, + "322303240771079935" + ], + [ + 197, + "1.710637717" + ], + [ + 198, + "52374425" + ], + [ + 199, + "0.00396087" + ], + [ + 200, + "229161792008" + ], + [ + 201, + "115039000" + ], + [ + 202, + "1209002624" + ], + [ + 203, + "34029210557338" + ], + [ + 204, + "2944730" + ], + [ + 205, + "0.5731441" + ], + [ + 206, + "1389019170" + ], + [ + 207, + "44043947822" + ], + [ + 208, + "331951449665644800" + ], + [ + 209, + "15964587728784" + ], + [ + 210, + "1598174770174689458" + ], + [ + 211, + "1922364685" + ], + [ + 212, + "328968937309" + ], + [ + 213, + "330.721154" + ], + [ + 214, + "1677366278943" + ], + [ + 215, + "806844323190414" + ], + [ + 216, + "5437849" + ], + [ + 217, + "6273134" + ], + [ + 218, + "0" + ], + [ + 219, + "64564225042" + ], + [ + 220, + "139776,963904" + ], + [ + 221, + "1884161251122450" + ], + [ + 222, + "1590933" + ], + [ + 223, + "61614848" + ], + [ + 224, + "4137330" + ], + [ + 225, + "2009" + ], + [ + 226, + "0.11316017" + ], + [ + 227, + "3780.618622" + ], + [ + 228, + "86226" + ], + [ + 229, + "11325263" + ], + [ + 230, + "850481152593119296" + ], + [ + 231, + "7526965179680" + ], + [ + 232, + "0.83648556" + ], + [ + 233, + "271204031455541309" + ], + [ + 234, + "1259187438574927161" + ], + [ + 235, + "1.002322108633" + ], + [ + 236, + "123/59" + ], + [ + 237, + "15836928" + ], + [ + 238, + "9922545104535661" + ], + [ + 239, + "0.001887854841" + ], + [ + 240, + "7448717393364181966" + ], + [ + 241, + "482316491800641154" + ], + [ + 242, + "997104142249036713" + ], + [ + 243, + "892371480" + ], + [ + 244, + "96356848" + ], + [ + 245, + "288084712410001" + ], + [ + 246, + "810834388" + ], + [ + 247, + "782252" + ], + [ + 248, + "23507044290" + ], + [ + 249, + "9275262564250418" + ], + [ + 250, + "1425480602091519" + ], + [ + 251, + "18946051" + ], + [ + 252, + "104924.0" + ], + [ + 253, + "11.492847" + ], + [ + 254, + "8184523820510" + ], + [ + 255, + "4.4474011180" + ], + [ + 256, + "85765680" + ], + [ + 257, + "139012411" + ], + [ + 258, + "12747994" + ], + [ + 259, + "20101196798" + ], + [ + 260, + "167542057" + ], + [ + 261, + "238890850232021" + ], + [ + 262, + "2531.205" + ], + [ + 263, + "2039506520" + ], + [ + 264, + "2816417.1055" + ], + [ + 265, + "209110240768" + ], + [ + 266, + "1096883702440585" + ], + [ + 267, + "0.999992836187" + ], + [ + 268, + "785478606870985" + ], + [ + 269, + "1311109198529286" + ], + [ + 270, + "82282080" + ], + [ + 271, + "4617456485273129588" + ], + [ + 272, + "8495585919506151122" + ], + [ + 273, + "2032447591196869022" + ], + [ + 274, + "1601912348822" + ], + [ + 275, + "15030564" + ], + [ + 276, + "5777137137739632912" + ], + [ + 277, + "1125977393124310" + ], + [ + 278, + "1228215747273908452" + ], + [ + 279, + "416577688" + ], + [ + 280, + "430.088247" + ], + [ + 281, + "1485776387445623" + ], + [ + 282, + "1098988351" + ], + [ + 283, + "28038042525570324" + ], + [ + 284, + "5a411d7b" + ], + [ + 285, + "157055.80999" + ], + [ + 286, + "52.6494571953" + ], + [ + 287, + "313135496" + ], + [ + 288, + "605857431263981935" + ], + [ + 289, + "6567944538" + ], + [ + 290, + "20444710234716473" + ], + [ + 291, + "4037526" + ], + [ + 292, + "3600060866" + ], + [ + 293, + "2209" + ], + [ + 294, + "789184709" + ], + [ + 295, + "4884650818" + ], + [ + 296, + "1137208419" + ], + [ + 297, + "2252639041804718029" + ], + [ + 298, + "1.76882294" + ], + [ + 299, + "549936643" + ], + [ + 300, + "8.0540771484375" + ], + [ + 301, + "2178309" + ], + [ + 302, + "1170060" + ], + [ + 303, + "1111981904675169" + ], + [ + 304, + "283988410192" + ], + [ + 305, + "18174995535140" + ], + [ + 306, + "852938" + ], + [ + 307, + "0.7311720251" + ], + [ + 308, + "1539669807660924" + ], + [ + 309, + "210139" + ], + [ + 310, + "2586528661783" + ], + [ + 311, + "2466018557" + ], + [ + 312, + "324681947" + ], + [ + 313, + "2057774861813004" + ], + [ + 314, + "132.52756426" + ], + [ + 315, + "13625242" + ], + [ + 316, + "542934735751917735" + ], + [ + 317, + "1856532.8455" + ], + [ + 318, + "709313889" + ], + [ + 319, + "268457129" + ], + [ + 320, + "278157919195482643" + ], + [ + 321, + "2470433131948040" + ], + [ + 322, + "999998760323313995" + ], + [ + 323, + "6.3551758451" + ], + [ + 324, + "96972774" + ], + [ + 325, + "54672965" + ], + [ + 326, + "1966666166408794329" + ], + [ + 327, + "34315549139516" + ], + [ + 328, + "260511850222" + ], + [ + 329, + "199740353/29386561536000" + ], + [ + 330, + "15955822" + ], + [ + 331, + "467178235146843549" + ], + [ + 332, + "2717.751525" + ], + [ + 333, + "3053105" + ], + [ + 334, + "150320021261690835" + ], + [ + 335, + "5032316" + ], + [ + 336, + "CAGBIHEFJDK" + ], + [ + 337, + "85068035" + ], + [ + 338, + "15614292" + ], + [ + 339, + "19823.542204" + ], + [ + 340, + "291504964" + ], + [ + 341, + "56098610614277014" + ], + [ + 342, + "5943040885644" + ], + [ + 343, + "269533451410884183" + ], + [ + 344, + "65579304332" + ], + [ + 345, + "13938" + ], + [ + 346, + "336108797689259276" + ], + [ + 347, + "11109800204052" + ], + [ + 348, + "1004195061" + ], + [ + 349, + "115384615384614952" + ], + [ + 350, + "84664213" + ], + [ + 351, + "11762187201804552" + ], + [ + 352, + "378563.260589" + ], + [ + 353, + "1.2759860331" + ], + [ + 354, + "58065134" + ], + [ + 355, + "1726545007" + ], + [ + 356, + "28010159" + ], + [ + 357, + "1739023853137" + ], + [ + 358, + "3284144505" + ], + [ + 359, + "40632119" + ], + [ + 360, + "878825614395267072" + ], + [ + 361, + "178476944" + ], + [ + 362, + "457895958010" + ], + [ + 363, + "0.0000372091" + ], + [ + 364, + "44855254" + ], + [ + 365, + "162619462356610313" + ], + [ + 366, + "88351299" + ], + [ + 367, + "48271207" + ], + [ + 368, + "253.6135092068" + ], + [ + 369, + "862400558448" + ], + [ + 370, + "41791929448408" + ], + [ + 371, + "40.66368097" + ], + [ + 372, + "301450082318807027" + ], + [ + 373, + "727227472448913" + ], + [ + 374, + "334420941" + ], + [ + 375, + "7435327983715286168" + ], + [ + 376, + "973059630185670" + ], + [ + 377, + "732385277" + ], + [ + 378, + "147534623725724718" + ], + [ + 379, + "132314136838185" + ], + [ + 380, + "6.3202e25093" + ], + [ + 381, + "139602943319822" + ], + [ + 382, + "697003956" + ], + [ + 383, + "22173624649806" + ], + [ + 384, + "3354706415856332783" + ], + [ + 385, + "3776957309612153700" + ], + [ + 386, + "528755790" + ], + [ + 387, + "696067597313468" + ], + [ + 388, + "831907372805129931" + ], + [ + 389, + "2406376.3623" + ], + [ + 390, + "2919133642971" + ], + [ + 391, + "61029882288" + ], + [ + 392, + "3.1486734435" + ], + [ + 393, + "112398351350823112" + ], + [ + 394, + "3.2370342194" + ], + [ + 395, + "28.2453753155" + ], + [ + 396, + "173214653" + ], + [ + 397, + "141630459461893728" + ], + [ + 398, + "2010.59096" + ], + [ + 399, + "1508395636674243,6.5e27330467" + ], + [ + 400, + "438505383468410633" + ], + [ + 401, + "281632621" + ], + [ + 402, + "356019862" + ], + [ + 403, + "18224771" + ], + [ + 404, + "1199215615081353" + ], + [ + 405, + "237696125" + ], + [ + 406, + "36813.12757207" + ], + [ + 407, + "39782849136421" + ], + [ + 408, + "299742733" + ], + [ + 409, + "253223948" + ], + [ + 410, + "799999783589946560" + ], + [ + 411, + "9936352" + ], + [ + 412, + "38788800" + ], + [ + 413, + "3079418648040719" + ], + [ + 414, + "552506775824935461" + ], + [ + 415, + "55859742" + ], + [ + 416, + "898082747" + ], + [ + 417, + "446572970925740" + ], + [ + 418, + "1177163565297340320" + ], + [ + 419, + "998567458,1046245404,43363922" + ], + [ + 420, + "145159332" + ], + [ + 421, + "2304215802083466198" + ], + [ + 422, + "92060460" + ], + [ + 423, + "653972374" + ], + [ + 424, + "1059760019628" + ], + [ + 425, + "46479497324" + ], + [ + 426, + "31591886008" + ], + [ + 427, + "97138867" + ], + [ + 428, + "747215561862" + ], + [ + 429, + "98792821" + ], + [ + 430, + "5000624921.38" + ], + [ + 431, + "23.386029052" + ], + [ + 432, + "754862080" + ], + [ + 433, + "326624372659664" + ], + [ + 434, + "863253606" + ], + [ + 435, + "252541322550" + ], + [ + 436, + "0.5276662759" + ], + [ + 437, + "74204709657207" + ], + [ + 438, + "2046409616809" + ], + [ + 439, + "968697378" + ], + [ + 440, + "970746056" + ], + [ + 441, + "5000088.8395" + ], + [ + 442, + "1295552661530920149" + ], + [ + 443, + "2744233049300770" + ], + [ + 444, + "1.200856722e263" + ], + [ + 445, + "659104042" + ], + [ + 446, + "907803852" + ], + [ + 447, + "530553372" + ], + [ + 448, + "106467648" + ], + [ + 449, + "103.37870096" + ], + [ + 450, + "583333163984220940" + ], + [ + 451, + "153651073760956" + ], + [ + 452, + "345558983" + ], + [ + 453, + "104354107" + ], + [ + 454, + "5435004633092" + ], + [ + 455, + "450186511399999" + ], + [ + 456, + "333333208685971546" + ], + [ + 457, + "2647787126797397063" + ], + [ + 458, + "423341841" + ], + [ + 459, + "3996390106631" + ], + [ + 460, + "18.420738199" + ], + [ + 461, + "159820276" + ], + [ + 462, + "5.5350769703e1512" + ], + [ + 463, + "808981553" + ], + [ + 464, + "198775297232878" + ], + [ + 465, + "585965659" + ], + [ + 466, + "258381958195474745" + ], + [ + 467, + "775181359" + ], + [ + 468, + "852950321" + ], + [ + 469, + "0.56766764161831" + ], + [ + 470, + "147668794" + ], + [ + 471, + "1.895093981e31" + ], + [ + 472, + "73811586" + ], + [ + 473, + "35856681704365" + ], + [ + 474, + "9690646731515010" + ], + [ + 475, + "75780067" + ], + [ + 476, + "110242.87794" + ], + [ + 477, + "25044905874565165" + ], + [ + 478, + "59510340" + ], + [ + 479, + "191541795" + ], + [ + 480, + "turnthestarson" + ], + [ + 481, + "729.12106947" + ], + [ + 482, + "1400824879147" + ], + [ + 483, + "4.993401567e22" + ], + [ + 484, + "8907904768686152599" + ], + [ + 485, + "51281274340" + ], + [ + 486, + "11408450515" + ], + [ + 487, + "106650212746" + ], + [ + 488, + "216737278" + ], + [ + 489, + "1791954757162" + ], + [ + 490, + "777577686" + ], + [ + 491, + "194505988824000" + ], + [ + 492, + "242586962923928" + ], + [ + 493, + "6.818741802" + ], + [ + 494, + "2880067194446832666" + ], + [ + 495, + "789107601" + ], + [ + 496, + "2042473533769142717" + ], + [ + 497, + "684901360" + ], + [ + 498, + "472294837" + ], + [ + 499, + "0.8660312" + ], + [ + 500, + "35407281" + ], + [ + 501, + "197912312715" + ], + [ + 502, + "749485217" + ], + [ + 503, + "3.8694550145" + ], + [ + 504, + "694687" + ], + [ + 505, + "714591308667615832" + ], + [ + 506, + "18934502" + ], + [ + 507, + "316558047002627270" + ], + [ + 508, + "891874596" + ], + [ + 509, + "151725678" + ], + [ + 510, + "315306518862563689" + ], + [ + 511, + "935247012" + ], + [ + 512, + "50660591862310323" + ], + [ + 513, + "2925619196" + ], + [ + 514, + "8986.86698" + ], + [ + 515, + "2422639000800" + ], + [ + 516, + "939087315" + ], + [ + 517, + "581468882" + ], + [ + 518, + "100315739184392" + ], + [ + 519, + "804739330" + ], + [ + 520, + "238413705" + ], + [ + 521, + "44389811" + ], + [ + 522, + "96772715" + ], + [ + 523, + "37125450.44" + ], + [ + 524, + "2432925835413407847" + ], + [ + 525, + "44.69921807" + ], + [ + 526, + "49601160286750947" + ], + [ + 527, + "11.92412011" + ], + [ + 528, + "779027989" + ], + [ + 529, + "23624465" + ], + [ + 530, + "207366437157977206" + ], + [ + 531, + "4515432351156203105" + ], + [ + 532, + "827306.56" + ], + [ + 533, + "789453601" + ], + [ + 534, + "11726115562784664" + ], + [ + 535, + "611778217" + ], + [ + 536, + "3557005261906288" + ], + [ + 537, + "779429131" + ], + [ + 538, + "22472871503401097" + ], + [ + 539, + "426334056" + ], + [ + 540, + "500000000002845" + ], + [ + 541, + "4580726482872451" + ], + [ + 542, + "697586734240314852" + ], + [ + 543, + "199007746081234640" + ], + [ + 544, + "640432376" + ], + [ + 545, + "921107572" + ], + [ + 546, + "215656873" + ], + [ + 547, + "11730879.0023" + ], + [ + 548, + "12144044603581281" + ], + [ + 549, + "476001479068717" + ], + [ + 550, + "328104836" + ], + [ + 551, + "73597483551591773" + ], + [ + 552, + "326227335" + ], + [ + 553, + "57717170" + ], + [ + 554, + "89539872" + ], + [ + 555, + "208517717451208352" + ], + [ + 556, + "52126939292957" + ], + [ + 557, + "2699929328" + ], + [ + 558, + "226754889" + ], + [ + 559, + "684724920" + ], + [ + 560, + "994345168" + ], + [ + 561, + "452480999988235494" + ], + [ + 562, + "51208732914368" + ], + [ + 563, + "27186308211734760" + ], + [ + 564, + "12363.698850" + ], + [ + 565, + "2992480851924313898" + ], + [ + 566, + "329569369413585" + ], + [ + 567, + "75.44817535" + ], + [ + 568, + "4228020" + ], + [ + 569, + "21025060" + ], + [ + 570, + "271197444" + ], + [ + 571, + "30510390701978" + ], + [ + 572, + "19737656" + ], + [ + 573, + "1252.9809" + ], + [ + 574, + "5780447552057000454" + ], + [ + 575, + "0.000989640561" + ], + [ + 576, + "344457.5871" + ], + [ + 577, + "265695031399260211" + ], + [ + 578, + "9219696799346" + ], + [ + 579, + "3805524" + ], + [ + 580, + "2327213148095366" + ], + [ + 581, + "2227616372734" + ], + [ + 582, + "19903" + ], + [ + 583, + "1174137929000" + ], + [ + 584, + "32.83822408" + ], + [ + 585, + "17714439395932" + ], + [ + 586, + "82490213" + ], + [ + 587, + "2240" + ], + [ + 588, + "11651930052" + ], + [ + 589, + "131776959.25" + ], + [ + 590, + "834171904" + ], + [ + 591, + "526007984625966" + ], + [ + 592, + "13415DF2BE9C" + ], + [ + 593, + "96632320042.0" + ], + [ + 594, + "47067598" + ], + [ + 595, + "54.17529329" + ], + [ + 596, + "734582049" + ], + [ + 597, + "0.5001817828" + ], + [ + 598, + "543194779059" + ], + [ + 599, + "12395526079546335" + ], + [ + 600, + "2668608479740672" + ], + [ + 601, + "1617243" + ], + [ + 602, + "269496760" + ], + [ + 603, + "879476477" + ], + [ + 604, + "1398582231101" + ], + [ + 605, + "59992576" + ], + [ + 606, + "158452775" + ], + [ + 607, + "13.1265108586" + ], + [ + 608, + "439689828" + ], + [ + 609, + "172023848" + ], + [ + 610, + "319.30207833" + ], + [ + 611, + "49283233900" + ], + [ + 612, + "819963842" + ], + [ + 613, + "0.3916721504" + ], + [ + 614, + "130694090" + ], + [ + 615, + "108424772" + ], + [ + 616, + "310884668312456458" + ], + [ + 617, + "1001133757" + ], + [ + 618, + "634212216" + ], + [ + 619, + "857810883" + ], + [ + 620, + "1470337306" + ], + [ + 621, + "11429712" + ], + [ + 622, + "3010983666182123972" + ], + [ + 623, + "3679796" + ], + [ + 624, + "984524441" + ], + [ + 625, + "551614306" + ], + [ + 626, + "695577663" + ], + [ + 627, + "220196142" + ], + [ + 628, + "210286684" + ], + [ + 629, + "626616617" + ], + [ + 630, + "9669182880384" + ], + [ + 631, + "869588692" + ], + [ + 632, + "728378714" + ], + [ + 633, + "1.0012e-10" + ], + [ + 634, + "4019680944" + ], + [ + 635, + "689294705" + ], + [ + 636, + "888316" + ], + [ + 637, + "49000634845039" + ], + [ + 638, + "18423394" + ], + [ + 639, + "797866893" + ], + [ + 640, + "50.317928" + ], + [ + 641, + "793525366" + ], + [ + 642, + "631499044" + ], + [ + 643, + "968274154" + ], + [ + 644, + "20.11208767" + ], + [ + 645, + "48894.2174" + ], + [ + 646, + "845218467" + ], + [ + 647, + "563132994232918611" + ], + [ + 648, + "301483197" + ], + [ + 649, + "924668016" + ], + [ + 650, + "538319652" + ], + [ + 651, + "448233151" + ], + [ + 652, + "983924497" + ], + [ + 653, + "1130658687" + ], + [ + 654, + "815868280" + ], + [ + 655, + "2000008332" + ], + [ + 656, + "888873503555187" + ], + [ + 657, + "219493139" + ], + [ + 658, + "958280177" + ], + [ + 659, + "238518915714422000" + ], + [ + 660, + "474766783" + ], + [ + 661, + "646231.2177" + ], + [ + 662, + "860873428" + ], + [ + 663, + "1884138010064752" + ], + [ + 664, + "35295862" + ], + [ + 665, + "11541685709674" + ], + [ + 666, + "0.48023168" + ], + [ + 667, + "1.5276527928" + ], + [ + 668, + "2811077773" + ], + [ + 669, + "56342087360542122" + ], + [ + 670, + "551055065" + ], + [ + 671, + "946106780" + ], + [ + 672, + "91627537" + ], + [ + 673, + "700325380" + ], + [ + 674, + "416678753" + ], + [ + 675, + "416146418" + ], + [ + 676, + "3562668074339584" + ], + [ + 677, + "984183023" + ], + [ + 678, + "1986065" + ], + [ + 679, + "644997092988678" + ], + [ + 680, + "563917241" + ], + [ + 681, + "2611227421428" + ], + [ + 682, + "290872710" + ], + [ + 683, + "2.38955315e11" + ], + [ + 684, + "922058210" + ], + [ + 685, + "662878999" + ], + [ + 686, + "193060223" + ], + [ + 687, + "0.3285320869" + ], + [ + 688, + "110941813" + ], + [ + 689, + "0.56565454" + ], + [ + 690, + "415157690" + ], + [ + 691, + "11570761" + ], + [ + 692, + "842043391019219959" + ], + [ + 693, + "699161" + ], + [ + 694, + "1339784153569958487" + ], + [ + 695, + "0.1017786859" + ], + [ + 696, + "436944244" + ], + [ + 697, + "4343871.06" + ], + [ + 698, + "57808202" + ], + [ + 699, + "37010438774467572" + ], + [ + 700, + "1517926517777556" + ], + [ + 701, + "13.51099836" + ], + [ + 702, + "622305608172525546" + ], + [ + 703, + "843437991" + ], + [ + 704, + "501985601490518144" + ], + [ + 705, + "480440153" + ], + [ + 706, + "884837055" + ], + [ + 707, + "652907799" + ], + [ + 708, + "28874142998632109" + ], + [ + 709, + "773479144" + ], + [ + 710, + "1275000" + ], + [ + 711, + "541510990" + ], + [ + 712, + "413876461" + ], + [ + 713, + "788626351539895" + ], + [ + 714, + "2.452767775565e20" + ], + [ + 715, + "883188017" + ], + [ + 716, + "238948623" + ], + [ + 717, + "1603036763131" + ], + [ + 718, + "228579116" + ], + [ + 719, + "128088830547982" + ], + [ + 720, + "688081048" + ], + [ + 721, + "700792959" + ], + [ + 722, + "3.376792776502e132" + ], + [ + 723, + "1395793419248" + ], + [ + 724, + "18128250110" + ], + [ + 725, + "4598797036650685" + ] +] \ No newline at end of file diff --git a/project_euler/validate_solutions.py b/project_euler/validate_solutions.py index 10b2e80376f4..01d70721ea8d 100755 --- a/project_euler/validate_solutions.py +++ b/project_euler/validate_solutions.py @@ -1,742 +1,20 @@ #!/usr/bin/env python3 import importlib.util +import json import pathlib from types import ModuleType -from typing import Generator, Tuple +from typing import Generator import pytest -PROJECT_EULER_PATH = pathlib.Path.cwd().joinpath("project_euler") - -# https://github.com/luckytoilet/projecteuler-solutions/blob/master/Solutions.md -ANSWERS: Tuple[Tuple[int, str], ...] = ( - (1, "233168"), - (2, "4613732"), - (3, "6857"), - (4, "906609"), - (5, "232792560"), - (6, "25164150"), - (7, "104743"), - (8, "23514624000"), - (9, "31875000"), - (10, "142913828922"), - (11, "70600674"), - (12, "76576500"), - (13, "5537376230"), - (14, "837799"), - (15, "137846528820"), - (16, "1366"), - (17, "21124"), - (18, "1074"), - (19, "171"), - (20, "648"), - (21, "31626"), - (22, "871198282"), - (23, "4179871"), - (24, "2783915460"), - (25, "4782"), - (26, "983"), - (27, "-59231"), - (28, "669171001"), - (29, "9183"), - (30, "443839"), - (31, "73682"), - (32, "45228"), - (33, "100"), - (34, "40730"), - (35, "55"), - (36, "872187"), - (37, "748317"), - (38, "932718654"), - (39, "840"), - (40, "210"), - (41, "7652413"), - (42, "162"), - (43, "16695334890"), - (44, "5482660"), - (45, "1533776805"), - (46, "5777"), - (47, "134043"), - (48, "9110846700"), - (49, "296962999629"), - (50, "997651"), - (51, "121313"), - (52, "142857"), - (53, "4075"), - (54, "376"), - (55, "249"), - (56, "972"), - (57, "153"), - (58, "26241"), - (59, "129448"), - (60, "26033"), - (61, "28684"), - (62, "127035954683"), - (63, "49"), - (64, "1322"), - (65, "272"), - (66, "661"), - (67, "7273"), - (68, "6531031914842725"), - (69, "510510"), - (70, "8319823"), - (71, "428570"), - (72, "303963552391"), - (73, "7295372"), - (74, "402"), - (75, "161667"), - (76, "190569291"), - (77, "71"), - (78, "55374"), - (79, "73162890"), - (80, "40886"), - (81, "427337"), - (82, "260324"), - (83, "425185"), - (84, "101524"), - (85, "2772"), - (86, "1818"), - (87, "1097343"), - (88, "7587457"), - (89, "743"), - (90, "1217"), - (91, "14234"), - (92, "8581146"), - (93, "1258"), - (94, "518408346"), - (95, "14316"), - (96, "24702"), - (97, "8739992577"), - (98, "18769"), - (99, "709"), - (100, "756872327473"), - (101, "37076114526"), - (102, "228"), - (103, "20313839404245"), - (104, "329468"), - (105, "73702"), - (106, "21384"), - (107, "259679"), - (108, "180180"), - (109, "38182"), - (110, "9350130049860600"), - (111, "612407567715"), - (112, "1587000"), - (113, "51161058134250"), - (114, "16475640049"), - (115, "168"), - (116, "20492570929"), - (117, "100808458960497"), - (118, "44680"), - (119, "248155780267521"), - (120, "333082500"), - (121, "2269"), - (122, "1582"), - (123, "21035"), - (124, "21417"), - (125, "2906969179"), - (126, "18522"), - (127, "18407904"), - (128, "14516824220"), - (129, "1000023"), - (130, "149253"), - (131, "173"), - (132, "843296"), - (133, "453647705"), - (134, "18613426663617118"), - (135, "4989"), - (136, "2544559"), - (137, "1120149658760"), - (138, "1118049290473932"), - (139, "10057761"), - (140, "5673835352990"), - (141, "878454337159"), - (142, "1006193"), - (143, "30758397"), - (144, "354"), - (145, "608720"), - (146, "676333270"), - (147, "846910284"), - (148, "2129970655314432"), - (149, "52852124"), - (150, "-271248680"), - (151, "0.464399"), - (152, "301"), - (153, "17971254122360635"), - (154, "479742450"), - (155, "3857447"), - (156, "21295121502550"), - (157, "53490"), - (158, "409511334375"), - (159, "14489159"), - (160, "16576"), - (161, "20574308184277971"), - (162, "3D58725572C62302"), - (163, "343047"), - (164, "378158756814587"), - (165, "2868868"), - (166, "7130034"), - (167, "3916160068885"), - (168, "59206"), - (169, "178653872807"), - (170, "9857164023"), - (171, "142989277"), - (172, "227485267000992000"), - (173, "1572729"), - (174, "209566"), - (175, "1,13717420,8"), - (176, "96818198400000"), - (177, "129325"), - (178, "126461847755"), - (179, "986262"), - (180, "285196020571078987"), - (181, "83735848679360680"), - (182, "399788195976"), - (183, "48861552"), - (184, "1725323624056"), - (185, "4640261571849533"), - (186, "2325629"), - (187, "17427258"), - (188, "95962097"), - (189, "10834893628237824"), - (190, "371048281"), - (191, "1918080160"), - (192, "57060635927998347"), - (193, "684465067343069"), - (194, "61190912"), - (195, "75085391"), - (196, "322303240771079935"), - (197, "1.710637717"), - (198, "52374425"), - (199, "0.00396087"), - (200, "229161792008"), - (201, "115039000"), - (202, "1209002624"), - (203, "34029210557338"), - (204, "2944730"), - (205, "0.5731441"), - (206, "1389019170"), - (207, "44043947822"), - (208, "331951449665644800"), - (209, "15964587728784"), - (210, "1598174770174689458"), - (211, "1922364685"), - (212, "328968937309"), - (213, "330.721154"), - (214, "1677366278943"), - (215, "806844323190414"), - (216, "5437849"), - (217, "6273134"), - (218, "0"), - (219, "64564225042"), - (220, "139776,963904"), - (221, "1884161251122450"), - (222, "1590933"), - (223, "61614848"), - (224, "4137330"), - (225, "2009"), - (226, "0.11316017"), - (227, "3780.618622"), - (228, "86226"), - (229, "11325263"), - (230, "850481152593119296"), - (231, "7526965179680"), - (232, "0.83648556"), - (233, "271204031455541309"), - (234, "1259187438574927161"), - (235, "1.002322108633"), - (236, "123/59"), - (237, "15836928"), - (238, "9922545104535661"), - (239, "0.001887854841"), - (240, "7448717393364181966"), - (241, "482316491800641154"), - (242, "997104142249036713"), - (243, "892371480"), - (244, "96356848"), - (245, "288084712410001"), - (246, "810834388"), - (247, "782252"), - (248, "23507044290"), - (249, "9275262564250418"), - (250, "1425480602091519"), - (251, "18946051"), - (252, "104924.0"), - (253, "11.492847"), - (254, "8184523820510"), - (255, "4.4474011180"), - (256, "85765680"), - (257, "139012411"), - (258, "12747994"), - (259, "20101196798"), - (260, "167542057"), - (261, "238890850232021"), - (262, "2531.205"), - (263, "2039506520"), - (264, "2816417.1055"), - (265, "209110240768"), - (266, "1096883702440585"), - (267, "0.999992836187"), - (268, "785478606870985"), - (269, "1311109198529286"), - (270, "82282080"), - (271, "4617456485273129588"), - (272, "8495585919506151122"), - (273, "2032447591196869022"), - (274, "1601912348822"), - (275, "15030564"), - (276, "5777137137739632912"), - (277, "1125977393124310"), - (278, "1228215747273908452"), - (279, "416577688"), - (280, "430.088247"), - (281, "1485776387445623"), - (282, "1098988351"), - (283, "28038042525570324"), - (284, "5a411d7b"), - (285, "157055.80999"), - (286, "52.6494571953"), - (287, "313135496"), - (288, "605857431263981935"), - (289, "6567944538"), - (290, "20444710234716473"), - (291, "4037526"), - (292, "3600060866"), - (293, "2209"), - (294, "789184709"), - (295, "4884650818"), - (296, "1137208419"), - (297, "2252639041804718029"), - (298, "1.76882294"), - (299, "549936643"), - (300, "8.0540771484375"), - (301, "2178309"), - (302, "1170060"), - (303, "1111981904675169"), - (304, "283988410192"), - (305, "18174995535140"), - (306, "852938"), - (307, "0.7311720251"), - (308, "1539669807660924"), - (309, "210139"), - (310, "2586528661783"), - (311, "2466018557"), - (312, "324681947"), - (313, "2057774861813004"), - (314, "132.52756426"), - (315, "13625242"), - (316, "542934735751917735"), - (317, "1856532.8455"), - (318, "709313889"), - (319, "268457129"), - (320, "278157919195482643"), - (321, "2470433131948040"), - (322, "999998760323313995"), - (323, "6.3551758451"), - (324, "96972774"), - (325, "54672965"), - (326, "1966666166408794329"), - (327, "34315549139516"), - (328, "260511850222"), - (329, "199740353/29386561536000"), - (330, "15955822"), - (331, "467178235146843549"), - (332, "2717.751525"), - (333, "3053105"), - (334, "150320021261690835"), - (335, "5032316"), - (336, "CAGBIHEFJDK"), - (337, "85068035"), - (338, "15614292"), - (339, "19823.542204"), - (340, "291504964"), - (341, "56098610614277014"), - (342, "5943040885644"), - (343, "269533451410884183"), - (344, "65579304332"), - (345, "13938"), - (346, "336108797689259276"), - (347, "11109800204052"), - (348, "1004195061"), - (349, "115384615384614952"), - (350, "84664213"), - (351, "11762187201804552"), - (352, "378563.260589"), - (353, "1.2759860331"), - (354, "58065134"), - (355, "1726545007"), - (356, "28010159"), - (357, "1739023853137"), - (358, "3284144505"), - (359, "40632119"), - (360, "878825614395267072"), - (361, "178476944"), - (362, "457895958010"), - (363, "0.0000372091"), - (364, "44855254"), - (365, "162619462356610313"), - (366, "88351299"), - (367, "48271207"), - (368, "253.6135092068"), - (369, "862400558448"), - (370, "41791929448408"), - (371, "40.66368097"), - (372, "301450082318807027"), - (373, "727227472448913"), - (374, "334420941"), - (375, "7435327983715286168"), - (376, "973059630185670"), - (377, "732385277"), - (378, "147534623725724718"), - (379, "132314136838185"), - (380, "6.3202e25093"), - (381, "139602943319822"), - (382, "697003956"), - (383, "22173624649806"), - (384, "3354706415856332783"), - (385, "3776957309612153700"), - (386, "528755790"), - (387, "696067597313468"), - (388, "831907372805129931"), - (389, "2406376.3623"), - (390, "2919133642971"), - (391, "61029882288"), - (392, "3.1486734435"), - (393, "112398351350823112"), - (394, "3.2370342194"), - (395, "28.2453753155"), - (396, "173214653"), - (397, "141630459461893728"), - (398, "2010.59096"), - (399, "1508395636674243,6.5e27330467"), - (400, "438505383468410633"), - (401, "281632621"), - (402, "356019862"), - (403, "18224771"), - (404, "1199215615081353"), - (405, "237696125"), - (406, "36813.12757207"), - (407, "39782849136421"), - (408, "299742733"), - (409, "253223948"), - (410, "799999783589946560"), - (411, "9936352"), - (412, "38788800"), - (413, "3079418648040719"), - (414, "552506775824935461"), - (415, "55859742"), - (416, "898082747"), - (417, "446572970925740"), - (418, "1177163565297340320"), - (419, "998567458,1046245404,43363922"), - (420, "145159332"), - (421, "2304215802083466198"), - (422, "92060460"), - (423, "653972374"), - (424, "1059760019628"), - (425, "46479497324"), - (426, "31591886008"), - (427, "97138867"), - (428, "747215561862"), - (429, "98792821"), - (430, "5000624921.38"), - (431, "23.386029052"), - (432, "754862080"), - (433, "326624372659664"), - (434, "863253606"), - (435, "252541322550"), - (436, "0.5276662759"), - (437, "74204709657207"), - (438, "2046409616809"), - (439, "968697378"), - (440, "970746056"), - (441, "5000088.8395"), - (442, "1295552661530920149"), - (443, "2744233049300770"), - (444, "1.200856722e263"), - (445, "659104042"), - (446, "907803852"), - (447, "530553372"), - (448, "106467648"), - (449, "103.37870096"), - (450, "583333163984220940"), - (451, "153651073760956"), - (452, "345558983"), - (453, "104354107"), - (454, "5435004633092"), - (455, "450186511399999"), - (456, "333333208685971546"), - (457, "2647787126797397063"), - (458, "423341841"), - (459, "3996390106631"), - (460, "18.420738199"), - (461, "159820276"), - (462, "5.5350769703e1512"), - (463, "808981553"), - (464, "198775297232878"), - (465, "585965659"), - (466, "258381958195474745"), - (467, "775181359"), - (468, "852950321"), - (469, "0.56766764161831"), - (470, "147668794"), - (471, "1.895093981e31"), - (472, "73811586"), - (473, "35856681704365"), - (474, "9690646731515010"), - (475, "75780067"), - (476, "110242.87794"), - (477, "25044905874565165"), - (478, "59510340"), - (479, "191541795"), - (480, "turnthestarson"), - (481, "729.12106947"), - (482, "1400824879147"), - (483, "4.993401567e22"), - (484, "8907904768686152599"), - (485, "51281274340"), - (486, "11408450515"), - (487, "106650212746"), - (488, "216737278"), - (489, "1791954757162"), - (490, "777577686"), - (491, "194505988824000"), - (492, "242586962923928"), - (493, "6.818741802"), - (494, "2880067194446832666"), - (495, "789107601"), - (496, "2042473533769142717"), - (497, "684901360"), - (498, "472294837"), - (499, "0.8660312"), - (500, "35407281"), - (501, "197912312715"), - (502, "749485217"), - (503, "3.8694550145"), - (504, "694687"), - (505, "714591308667615832"), - (506, "18934502"), - (507, "316558047002627270"), - (508, "891874596"), - (509, "151725678"), - (510, "315306518862563689"), - (511, "935247012"), - (512, "50660591862310323"), - (513, "2925619196"), - (514, "8986.86698"), - (515, "2422639000800"), - (516, "939087315"), - (517, "581468882"), - (518, "100315739184392"), - (519, "804739330"), - (520, "238413705"), - (521, "44389811"), - (522, "96772715"), - (523, "37125450.44"), - (524, "2432925835413407847"), - (525, "44.69921807"), - (526, "49601160286750947"), - (527, "11.92412011"), - (528, "779027989"), - (529, "23624465"), - (530, "207366437157977206"), - (531, "4515432351156203105"), - (532, "827306.56"), - (533, "789453601"), - (534, "11726115562784664"), - (535, "611778217"), - (536, "3557005261906288"), - (537, "779429131"), - (538, "22472871503401097"), - (539, "426334056"), - (540, "500000000002845"), - (541, "4580726482872451"), - (542, "697586734240314852"), - (543, "199007746081234640"), - (544, "640432376"), - (545, "921107572"), - (546, "215656873"), - (547, "11730879.0023"), - (548, "12144044603581281"), - (549, "476001479068717"), - (550, "328104836"), - (551, "73597483551591773"), - (552, "326227335"), - (553, "57717170"), - (554, "89539872"), - (555, "208517717451208352"), - (556, "52126939292957"), - (557, "2699929328"), - (558, "226754889"), - (559, "684724920"), - (560, "994345168"), - (561, "452480999988235494"), - (562, "51208732914368"), - (563, "27186308211734760"), - (564, "12363.698850"), - (565, "2992480851924313898"), - (566, "329569369413585"), - (567, "75.44817535"), - (568, "4228020"), - (569, "21025060"), - (570, "271197444"), - (571, "30510390701978"), - (572, "19737656"), - (573, "1252.9809"), - (574, "5780447552057000454"), - (575, "0.000989640561"), - (576, "344457.5871"), - (577, "265695031399260211"), - (578, "9219696799346"), - (579, "3805524"), - (580, "2327213148095366"), - (581, "2227616372734"), - (582, "19903"), - (583, "1174137929000"), - (584, "32.83822408"), - (585, "17714439395932"), - (586, "82490213"), - (587, "2240"), - (588, "11651930052"), - (589, "131776959.25"), - (590, "834171904"), - (591, "526007984625966"), - (592, "13415DF2BE9C"), - (593, "96632320042.0"), - (594, "47067598"), - (595, "54.17529329"), - (596, "734582049"), - (597, "0.5001817828"), - (598, "543194779059"), - (599, "12395526079546335"), - (600, "2668608479740672"), - (601, "1617243"), - (602, "269496760"), - (603, "879476477"), - (604, "1398582231101"), - (605, "59992576"), - (606, "158452775"), - (607, "13.1265108586"), - (608, "439689828"), - (609, "172023848"), - (610, "319.30207833"), - (611, "49283233900"), - (612, "819963842"), - (613, "0.3916721504"), - (614, "130694090"), - (615, "108424772"), - (616, "310884668312456458"), - (617, "1001133757"), - (618, "634212216"), - (619, "857810883"), - (620, "1470337306"), - (621, "11429712"), - (622, "3010983666182123972"), - (623, "3679796"), - (624, "984524441"), - (625, "551614306"), - (626, "695577663"), - (627, "220196142"), - (628, "210286684"), - (629, "626616617"), - (630, "9669182880384"), - (631, "869588692"), - (632, "728378714"), - (633, "1.0012e-10"), - (634, "4019680944"), - (635, "689294705"), - (636, "888316"), - (637, "49000634845039"), - (638, "18423394"), - (639, "797866893"), - (640, "50.317928"), - (641, "793525366"), - (642, "631499044"), - (643, "968274154"), - (644, "20.11208767"), - (645, "48894.2174"), - (646, "845218467"), - (647, "563132994232918611"), - (648, "301483197"), - (649, "924668016"), - (650, "538319652"), - (651, "448233151"), - (652, "983924497"), - (653, "1130658687"), - (654, "815868280"), - (655, "2000008332"), - (656, "888873503555187"), - (657, "219493139"), - (658, "958280177"), - (659, "238518915714422000"), - (660, "474766783"), - (661, "646231.2177"), - (662, "860873428"), - (663, "1884138010064752"), - (664, "35295862"), - (665, "11541685709674"), - (666, "0.48023168"), - (667, "1.5276527928"), - (668, "2811077773"), - (669, "56342087360542122"), - (670, "551055065"), - (671, "946106780"), - (672, "91627537"), - (673, "700325380"), - (674, "416678753"), - (675, "416146418"), - (676, "3562668074339584"), - (677, "984183023"), - (678, "1986065"), - (679, "644997092988678"), - (680, "563917241"), - (681, "2611227421428"), - (682, "290872710"), - (683, "2.38955315e11"), - (684, "922058210"), - (685, "662878999"), - (686, "193060223"), - (687, "0.3285320869"), - (688, "110941813"), - (689, "0.56565454"), - (690, "415157690"), - (691, "11570761"), - (692, "842043391019219959"), - (693, "699161"), - (694, "1339784153569958487"), - (695, "0.1017786859"), - (696, "436944244"), - (697, "4343871.06"), - (698, "57808202"), - (699, "37010438774467572"), - (700, "1517926517777556"), - (701, "13.51099836"), - (702, "622305608172525546"), - (703, "843437991"), - (704, "501985601490518144"), - (705, "480440153"), - (706, "884837055"), - (707, "652907799"), - (708, "28874142998632109"), - (709, "773479144"), - (710, "1275000"), - (711, "541510990"), - (712, "413876461"), - (713, "788626351539895"), - (714, "2.452767775565e20"), - (715, "883188017"), - (716, "238948623"), - (717, "1603036763131"), - (718, "228579116"), - (719, "128088830547982"), - (720, "688081048"), - (721, "700792959"), - (722, "3.376792776502e132"), - (723, "1395793419248"), - (724, "18128250110"), - (725, "4598797036650685"), +PROJECT_EULER_DIR_PATH = pathlib.Path.cwd().joinpath("project_euler") +PROJECT_EULER_ANSWERS_PATH = PROJECT_EULER_DIR_PATH.joinpath( + "project_euler_answers.json" ) +with open(PROJECT_EULER_ANSWERS_PATH) as file_handle: + PROBLEM_ANSWERS = json.load(file_handle) + error_msgs = [] @@ -755,14 +33,14 @@ def generate_solution_modules( yield module -@pytest.mark.parametrize("problem_number, expected", ANSWERS) +@pytest.mark.parametrize("problem_number, expected", PROBLEM_ANSWERS) def test_project_euler(subtests, problem_number: int, expected: str): - problem_dir = PROJECT_EULER_PATH.joinpath(f"problem_{problem_number:02}") - # By checking if it's a directory we can write all the problem number and - # answer pair in ANSWERS variable and not worry whether it is actually - # present in the 'project_euler' directory + problem_dir = PROJECT_EULER_DIR_PATH.joinpath(f"problem_{problem_number:02}") + # Check if the problem directory exist. If not, then skip. if problem_dir.is_dir(): for solution_module in generate_solution_modules(problem_dir): + # All the tests in a loop is considered as one test by pytest so, use + # subtests to make sure all the subtests are considered as different. with subtests.test( msg=f"Problem {problem_number} tests", solution_module=solution_module ): @@ -773,11 +51,17 @@ def test_project_euler(subtests, problem_number: int, expected: str): error_msgs.append( f"problem_{problem_number}/{solution_module.__name__}: {err}" ) - raise + raise # We still want pytest to know that this test failed else: - pytest.skip("Solution doesn't exists yet.") + pytest.skip(f"Solution {problem_number} does not exist yet.") + +# Run this function at the end of all the tests +# https://stackoverflow.com/a/52873379 +@pytest.fixture(scope="session", autouse=True) +def custom_print_message(request): + def print_error_messages(): + if error_msgs: + print("\n" + "\n".join(error_msgs)) -def test_print_error_msgs(): - if error_msgs: - print("\n" + "\n".join(error_msgs) + "\n") + request.addfinalizer(print_error_messages)