<commit_before>#!/usr/bin/env python3

from rubikscubennnsolver import ImplementThis, SolveError, StuckInALoop
from rubikscubennnsolver.RubiksCube222 import RubiksCube222, solved_2x2x2
from rubikscubennnsolver.RubiksCube333 import RubiksCube333, solved_3x3x3
from rubikscubennnsolver.RubiksCube444 import RubiksCube444, solved_4x4x4
from rubikscubennnsolver.RubiksCube555 import RubiksCube555, solved_5x5x5
from rubikscubennnsolver.RubiksCube666 import RubiksCube666, solved_6x6x6
from rubikscubennnsolver.RubiksCube777 import RubiksCube777, solved_7x7x7
import argparse
import json
import logging
import os
import sys

logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s %(filename)12s %(levelname)8s: %(message)s')
log = logging.getLogger(__name__)

# Color the errors and warnings in red
logging.addLevelName(logging.ERROR, "\033[91m   %s\033[0m" % logging.getLevelName(logging.ERROR))
logging.addLevelName(logging.WARNING, "\033[91m %s\033[0m" % logging.getLevelName(logging.WARNING))

parser = argparse.ArgumentParser()
parser.add_argument('--size', type=str, default='4x4x4')
parser.add_argument('--test-cubes', type=str, default='test_cubes.json')
parser.add_argument('--start', type=int, default=0)
args = parser.parse_args()

try:

    with open(args.test_cubes, 'r') as fh:
        test_cases = json.load(fh)

    solution_total = 0
    centers_solution_total = 0
    edges_solution_total = 0
    min_solution = None
    max_solution = None
    min_solution_kociemba_string = None
    max_solution_kociemba_string = None

    results = []
    order = 'URFDLB'

    for size in sorted(test_cases.keys()):

        if args.size != 'all' and size != args.size:
            continue

        # solve the cube
        if size == '2x2x2':
            cube = RubiksCube222(solved_2x2x2, order)

        elif size == '3x3x3':
            cube = RubiksCube333(solved_3x3x3, order)

        elif size == '4x4x4':
            cube = RubiksCube444(solved_4x4x4, order)
            #cube.ev3 = True

        elif size == '5x5x5':
            cube = RubiksCube555(solved_5x5x5, order)

        elif size == '6x6x6':
            cube = RubiksCube666(solved_6x6x6, order)

        elif size == '7x7x7':
            cube = RubiksCube777(solved_7x7x7, order)

        else:
            print("ERROR: Add support for %s" % size)
            sys.exit(1)

        kociemba_strings = test_cases[size]
        num_test_cases = len(kociemba_strings)
        num_test_cases_executed = 0

        for (index, kociemba_string) in enumerate(kociemba_strings):

            if index < args.start:
                continue

            #os.system('clear')
            log.warning("Test %d/%d %s cube: %s" % (index, num_test_cases, size, kociemba_string))
            num_test_cases_executed += 1
            kociemba_string = str(kociemba_string)
            cube.solution = []
            cube.load_state(kociemba_string, order)

            try:
                cube.solve()
                solution = cube.solution
            except Exception:
                results.append("\033[91m%s FAIL\033[0m: %s" % (size, kociemba_string))
                continue

            # Now put the cube back in its initial state and verify the solution solves it
            # uncomment this to test compress_solution()
            #cube = RubiksCube(kociemba_string)
            #for step in solution:
            #    cube.rotate(step)

            if cube.solved():
                results.append("\033[92m%s PASS\033[0m: %s" % (size, kociemba_string))
                # cube.print_solution()
            else:
                results.append("\033[91m%s FAIL\033[0m: %s" % (size, kociemba_string))
                cube.print_cube()
                cube.print_solution()
                break
                '''
                for result in results:
                    print(result)

                cube.print_cube()
                assert False, "Cube should be solvd but it isn't"
                '''

            solution_length = len(cube.solution)
            solution_total += solution_length
            centers_solution_total += cube.steps_to_solve_centers
            edges_solution_total += cube.steps_to_group_edges

            if min_solution is None or solution_length < min_solution:
                min_solution = solution_length
                min_solution_kociemba_string = kociemba_string

            if max_solution is None or solution_length > max_solution:
                max_solution = solution_length
                max_solution_kociemba_string = kociemba_string

        results.append("%s avg centers solution %s steps" % (size, float(centers_solution_total/num_test_cases_executed)))
        results.append("%s avg edges solution %s steps" % (size, float(edges_solution_total/num_test_cases_executed)))
        results.append("%s avg solution %s steps" % (size, float(solution_total/num_test_cases_executed)))
        results.append("%s min solution %s steps (%s)" % (size, min_solution, min_solution_kociemba_string))
        results.append("%s max solution %s steps (%s)" % (size, max_solution, max_solution_kociemba_string))
        results.append("")<commit_msg>Fix utils/test.py<commit_after>#!/usr/bin/env python3

from rubikscubennnsolver import ImplementThis, SolveError, StuckInALoop
from rubikscubennnsolver.RubiksCube222 import RubiksCube222, solved_2x2x2
from rubikscubennnsolver.RubiksCube333 import RubiksCube333, solved_3x3x3
from rubikscubennnsolver.RubiksCube444 import RubiksCube444, solved_4x4x4
from rubikscubennnsolver.RubiksCube555 import RubiksCube555, solved_5x5x5
from rubikscubennnsolver.RubiksCube666 import RubiksCube666, solved_6x6x6
from rubikscubennnsolver.RubiksCube777 import RubiksCube777, solved_7x7x7
import argparse
import json
import logging
import os
import sys

logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s %(filename)12s %(levelname)8s: %(message)s')
log = logging.getLogger(__name__)

# Color the errors and warnings in red
logging.addLevelName(logging.ERROR, "\033[91m   %s\033[0m" % logging.getLevelName(logging.ERROR))
logging.addLevelName(logging.WARNING, "\033[91m %s\033[0m" % logging.getLevelName(logging.WARNING))

parser = argparse.ArgumentParser()
parser.add_argument('--size', type=str, default='4x4x4')
parser.add_argument('--test-cubes', type=str, default='test_cubes.json')
parser.add_argument('--start', type=int, default=0)
args = parser.parse_args()

try:

    with open(args.test_cubes, 'r') as fh:
        test_cases = json.load(fh)

    solution_total = 0
    centers_solution_total = 0
    edges_solution_total = 0
    min_solution = None
    max_solution = None
    min_solution_kociemba_string = None
    max_solution_kociemba_string = None

    results = []
    order = 'URFDLB'

    for size in sorted(test_cases.keys()):

        if args.size != 'all' and size != args.size:
            continue

        # solve the cube
        if size == '2x2x2':
            cube = RubiksCube222(solved_2x2x2, order)

        elif size == '3x3x3':
            cube = RubiksCube333(solved_3x3x3, order)

        elif size == '4x4x4':
            cube = RubiksCube444(solved_4x4x4, order)

        elif size == '5x5x5':
            cube = RubiksCube555(solved_5x5x5, order)

        elif size == '6x6x6':
            cube = RubiksCube666(solved_6x6x6, order)

        elif size == '7x7x7':
            cube = RubiksCube777(solved_7x7x7, order)

        else:
            print("ERROR: Add support for %s" % size)
            sys.exit(1)

        cube.cpu_mode = 'normal'
        kociemba_strings = test_cases[size]
        num_test_cases = len(kociemba_strings)
        num_test_cases_executed = 0

        for (index, kociemba_string) in enumerate(kociemba_strings):

            if index < args.start:
                continue

            #os.system('clear')
            log.warning("Test %d/%d %s cube: %s" % (index, num_test_cases, size, kociemba_string))
            num_test_cases_executed += 1
            kociemba_string = str(kociemba_string)
            cube.solution = []
            cube.load_state(kociemba_string, order)

            try:
                cube.solve()
                solution = cube.solution
            except Exception as e:
                results.append("\033[91m%s FAIL (exception) \033[0m: %s\n%s\n" % (size, kociemba_string, str(e)))
                continue

            # Now put the cube back in its initial state and verify the solution solves it
            # uncomment this to test compress_solution()
            #cube = RubiksCube(kociemba_string)
            #for step in solution:
            #    cube.rotate(step)

            if cube.solved():
                results.append("\033[92m%s PASS\033[0m: %s" % (size, kociemba_string))
                # cube.print_solution()
            else:
                results.append("\033[91m%s FAIL (not solved)\033[0m: %s" % (size, kociemba_string))
                cube.print_cube()
                cube.print_solution()
                break
                '''
                for result in results:
                    print(result)

                cube.print_cube()
                assert False, "Cube should be solvd but it isn't"
                '''

            solution_length = len(cube.solution)
            solution_total += solution_length
            centers_solution_total += cube.steps_to_solve_centers
            edges_solution_total += cube.steps_to_group_edges

            if min_solution is None or solution_length < min_solution:
                min_solution = solution_length
                min_solution_kociemba_string = kociemba_string

            if max_solution is None or solution_length > max_solution:
                max_solution = solution_length
                max_solution_kociemba_string = kociemba_string

        results.append("%s avg centers solution %s steps" % (size, float(centers_solution_total/num_test_cases_executed)))
        results.append("%s avg edges solution %s steps" % (size, float(edges_solution_total/num_test_cases_executed)))
        results.append("%s avg solution %s steps" % (size, float(solution_total/num_test_cases_executed)))
        results.append("%s min solution %s steps (%s)" % (size, min_solution, min_solution_kociemba_string))
        results.append("%s max solution %s steps (%s)" % (size, max_solution, max_solution_kociemba_string))
        results.append("")
{'fraction_non_alphanumeric': 0.09461398641538314, 'fraction_numerical': 0.032048215823208645, 'mean_word_length': 2.540128682695564, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4378600', 'n_tokens_mistral': 3678, 'n_tokens_neox': 3362, 'n_words': 693}