<commit_before># <NAME> et <NAME> - 2015

import unittest
import random
from collections import deque

from tryalgo.graph import write_graph, extract_path, make_flow_labels
from tryalgo.graph import tree_adj_to_prec, tree_prec_to_adj
from tryalgo.graph import matrix_to_listlist, listlist_and_matrix_to_listdict
from tryalgo.graph import listdict_to_listlist_and_matrix, dictdict_to_listdict
from tryalgo.anagrams import anagrams
from tryalgo.arithm import inv
from tryalgo.arithm_expr_eval import arithm_expr_eval, arithm_expr_parse
from tryalgo.arithm_expr_target import arithm_expr_target
from tryalgo.bellman_ford import bellman_ford
from tryalgo.knapsack import knapsack, knapsack2
from tryalgo.graph import write_graph, extract_path, make_flow_labels
from tryalgo.bfs import bfs
from tryalgo.biconnected_components import cut_nodes_edges, cut_nodes_edges2
from tryalgo.binary_search import continuous_binary_search, discrete_binary_search, optimized_binary_search
from tryalgo.bipartite_matching import max_bipartite_matching
from tryalgo.closest_points import closest_points
from tryalgo.closest_values import closest_values
from tryalgo.convex_hull import left_turn, andrew
from tryalgo.dancing_links import dancing_links
from tryalgo.dfs import find_cycle, dfs_recursive, dfs_iterative, dfs_grid
from tryalgo.dijkstra import dijkstra_update_heap, dijkstra
from tryalgo.dilworth import dilworth
from tryalgo.dinic import dinic
from tryalgo.dist_grid import dist_grid
from tryalgo.edmonds_karp import edmonds_karp
from tryalgo.eratosthene import eratosthene
from tryalgo.eulerian_tour import eulerian_tour_directed, random_eulerien_graph, is_eulerian_tour
from tryalgo.fast_exponentiation import fast_exponentiation, fast_exponentiation2
from tryalgo.fenwick import Fenwick
from tryalgo.floyd_warshall import floyd_warshall
from tryalgo.ford_fulkerson import ford_fulkerson
from tryalgo.freivalds import freivalds
from tryalgo.gale_shapley import gale_shapley
from tryalgo.gauss_jordan import gauss_jordan, GJ_ZERO_SOLUTIONS, GJ_UNE_SOLUTION, GJ_PLUSIEURS_SOLUTIONS
from tryalgo.graph01 import dist01
from tryalgo.huffman import huffman
from tryalgo.interval_tree import interval_tree, intervals_containing
from tryalgo.interval_cover import interval_cover
from tryalgo.intervals_union import intervals_union
from tryalgo.knuth_morris_pratt_border import maximum_border_length, powerstring_by_border
from tryalgo.knuth_morris_pratt import knuth_morris_pratt
from tryalgo.kruskal import kruskal
from tryalgo.kuhn_munkres_n4 import kuhn_munkres as kuhn_munkres_n4
from tryalgo.kuhn_munkres    import kuhn_munkres as kuhn_munkres_n3
from tryalgo.rabin_karp import rabin_karp_matching
from tryalgo.laser_mirrors import laser_mirrors
from tryalgo.levenshtein import levenshtein
from tryalgo.longest_common_subsequence import longest_common_subsequence
from tryalgo.longest_increasing_subsequence import longest_increasing_subsequence
from tryalgo.lowest_common_ancestor import LowestCommonAncestorShortcuts, LowestCommonAncestorRMQ
from tryalgo.majority import majority
from tryalgo.manacher import manacher
from tryalgo.matrix_chain_mult import matrix_mult_opt_order, matrix_chain_mult
from tryalgo.max_interval_intersec import max_interval_intersec
from tryalgo.merge_ordered_lists import merge
from tryalgo.min_mean_cycle import min_mean_cycle
from tryalgo.next_permutation import next_permutation
from tryalgo.our_heap import OurHeap
from tryalgo.our_queue import OurQueue
from tryalgo.polygon import area, is_simple
from tryalgo.predictive_text import predictive_text, propose
from tryalgo.rabin_karp import rabin_karp_factor
from tryalgo.range_minimum_query import RangeMinQuery
from tryalgo.rectangles_from_grid import rectangles_from_grid
from tryalgo.rectangles_from_histogram import rectangles_from_histogram
from tryalgo.rectangles_from_points import rectangles_from_points
from tryalgo.scalar import min_scalar_prod
from tryalgo.strongly_connected_components import tarjan, kosaraju, tarjan_recursif
from tryalgo.subsetsum_divide import subset_sum as subset_sum1
from tryalgo.subsetsum import subset_sum as subset_sum2, coin_change
from tryalgo.sudoku import sudoku
from tryalgo.three_partition import three_partition
from tryalgo.topological_order import topological_order_dfs, topological_order
from tryalgo.trie import Trie, spell_check
from tryalgo.two_sat import two_sat
from tryalgo.union_rectangles import union_rectangles
from tryalgo.windows_k_distinct import windows_k_distinct


class TestTryalgo(unittest.TestCase):


    def unorder(self, L):
        return set(frozenset(group) for group in L)

    def test_anagrams(self):
        L = [("le chien marche vers sa niche et trouve une "
                       "limace de chine nue pleine de malice "
                       "qui lui fait du charme".split(),
                       [['nue', 'une'],
                        ['limace', 'malice'],
                        ['marche', 'charme'],
                        ['chien', 'niche', 'chine']]),
            (["aba", "baa", "abb"], [["aba", "baa"]]),
            (["aba"], []),
            ([], [])]
        for words, res in L:
            self.assertEqual(self.unorder(anagrams(words)), self.unorder(res))

    def test_arithm(self):
        self.assertEqual(inv(8, 17), 15)

    def test_arithm_expr_eval(self):
        L = [("13 + A47 * ZZ22", 37),
             ("4 / 7 + 4 / 7", 0),
             ("3 * 3 / 7", 1),
             ("12", 12)]
        for str_expr, val in L:
            cell = {"ZZ22": 3, "A47": 8}
            expr = arithm_expr_parse(str_expr.split())
            self.assertEqual(arithm_expr_eval(cell, expr), val)

    def test_arithm_expr_target(self):
        L = [([3, 100, 8, 8, 10, 6], 683, 683 ),<commit_msg>test_tryalgo.unorder uses now sorted<commit_after># <NAME> et <NAME> - 2015

import unittest
import random
from collections import deque

from tryalgo.graph import write_graph, extract_path, make_flow_labels
from tryalgo.graph import tree_adj_to_prec, tree_prec_to_adj
from tryalgo.graph import matrix_to_listlist, listlist_and_matrix_to_listdict
from tryalgo.graph import listdict_to_listlist_and_matrix, dictdict_to_listdict
from tryalgo.anagrams import anagrams
from tryalgo.arithm import inv
from tryalgo.arithm_expr_eval import arithm_expr_eval, arithm_expr_parse
from tryalgo.arithm_expr_target import arithm_expr_target
from tryalgo.bellman_ford import bellman_ford
from tryalgo.knapsack import knapsack, knapsack2
from tryalgo.graph import write_graph, extract_path, make_flow_labels
from tryalgo.bfs import bfs
from tryalgo.biconnected_components import cut_nodes_edges, cut_nodes_edges2
from tryalgo.binary_search import continuous_binary_search, discrete_binary_search, optimized_binary_search
from tryalgo.bipartite_matching import max_bipartite_matching
from tryalgo.closest_points import closest_points
from tryalgo.closest_values import closest_values
from tryalgo.convex_hull import left_turn, andrew
from tryalgo.dancing_links import dancing_links
from tryalgo.dfs import find_cycle, dfs_recursive, dfs_iterative, dfs_grid
from tryalgo.dijkstra import dijkstra_update_heap, dijkstra
from tryalgo.dilworth import dilworth
from tryalgo.dinic import dinic
from tryalgo.dist_grid import dist_grid
from tryalgo.edmonds_karp import edmonds_karp
from tryalgo.eratosthene import eratosthene
from tryalgo.eulerian_tour import eulerian_tour_directed, random_eulerien_graph, is_eulerian_tour
from tryalgo.fast_exponentiation import fast_exponentiation, fast_exponentiation2
from tryalgo.fenwick import Fenwick
from tryalgo.floyd_warshall import floyd_warshall
from tryalgo.ford_fulkerson import ford_fulkerson
from tryalgo.freivalds import freivalds
from tryalgo.gale_shapley import gale_shapley
from tryalgo.gauss_jordan import gauss_jordan, GJ_ZERO_SOLUTIONS, GJ_UNE_SOLUTION, GJ_PLUSIEURS_SOLUTIONS
from tryalgo.graph01 import dist01
from tryalgo.huffman import huffman
from tryalgo.interval_tree import interval_tree, intervals_containing
from tryalgo.interval_cover import interval_cover
from tryalgo.intervals_union import intervals_union
from tryalgo.knuth_morris_pratt_border import maximum_border_length, powerstring_by_border
from tryalgo.knuth_morris_pratt import knuth_morris_pratt
from tryalgo.kruskal import kruskal
from tryalgo.kuhn_munkres_n4 import kuhn_munkres as kuhn_munkres_n4
from tryalgo.kuhn_munkres    import kuhn_munkres as kuhn_munkres_n3
from tryalgo.rabin_karp import rabin_karp_matching
from tryalgo.laser_mirrors import laser_mirrors
from tryalgo.levenshtein import levenshtein
from tryalgo.longest_common_subsequence import longest_common_subsequence
from tryalgo.longest_increasing_subsequence import longest_increasing_subsequence
from tryalgo.lowest_common_ancestor import LowestCommonAncestorShortcuts, LowestCommonAncestorRMQ
from tryalgo.majority import majority
from tryalgo.manacher import manacher
from tryalgo.matrix_chain_mult import matrix_mult_opt_order, matrix_chain_mult
from tryalgo.max_interval_intersec import max_interval_intersec
from tryalgo.merge_ordered_lists import merge
from tryalgo.min_mean_cycle import min_mean_cycle
from tryalgo.next_permutation import next_permutation
from tryalgo.our_heap import OurHeap
from tryalgo.our_queue import OurQueue
from tryalgo.polygon import area, is_simple
from tryalgo.predictive_text import predictive_text, propose
from tryalgo.rabin_karp import rabin_karp_factor
from tryalgo.range_minimum_query import RangeMinQuery
from tryalgo.rectangles_from_grid import rectangles_from_grid
from tryalgo.rectangles_from_histogram import rectangles_from_histogram
from tryalgo.rectangles_from_points import rectangles_from_points
from tryalgo.scalar import min_scalar_prod
from tryalgo.strongly_connected_components import tarjan, kosaraju, tarjan_recursif
from tryalgo.subsetsum_divide import subset_sum as subset_sum1
from tryalgo.subsetsum import subset_sum as subset_sum2, coin_change
from tryalgo.sudoku import sudoku
from tryalgo.three_partition import three_partition
from tryalgo.topological_order import topological_order_dfs, topological_order
from tryalgo.trie import Trie, spell_check
from tryalgo.two_sat import two_sat
from tryalgo.union_rectangles import union_rectangles
from tryalgo.windows_k_distinct import windows_k_distinct


class TestTryalgo(unittest.TestCase):


    def unorder(self, L):
        return sorted(sorted(group) for group in L)

    def test_anagrams(self):
        L = [("le chien marche vers sa niche et trouve une "
                       "limace de chine nue pleine de malice "
                       "qui lui fait du charme".split(),
                       [['nue', 'une'],
                        ['limace', 'malice'],
                        ['marche', 'charme'],
                        ['chien', 'niche', 'chine']]),
            (["aba", "baa", "abb"], [["aba", "baa"]]),
            (["aba"], []),
            ([], [])]
        for words, res in L:
            self.assertEqual(self.unorder(anagrams(words)), self.unorder(res))

    def test_arithm(self):
        self.assertEqual(inv(8, 17), 15)

    def test_arithm_expr_eval(self):
        L = [("13 + A47 * ZZ22", 37),
             ("4 / 7 + 4 / 7", 0),
             ("3 * 3 / 7", 1),
             ("12", 12)]
        for str_expr, val in L:
            cell = {"ZZ22": 3, "A47": 8}
            expr = arithm_expr_parse(str_expr.split())
            self.assertEqual(arithm_expr_eval(cell, expr), val)

    def test_arithm_expr_target(self):
        L = [([3, 100, 8, 8, 10, 6], 683, 683 ),
{'fraction_non_alphanumeric': 0.05709087758814866, 'fraction_numerical': 0.010915706488781079, 'mean_word_length': 5.1964573268921095, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, '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': '1165758', 'n_tokens_mistral': 3931, 'n_tokens_neox': 3745, 'n_words': 941}