def test_on_converting_a_page_to_a_str():
    s1 = Symbol(1, 4)
    s2 = Symbol(2, 2)
    s3 = Symbol(3, 7)
    s4 = Symbol(4, 1)

    t1 = Tile({s1, s2})
    t2 = Tile({s2, s4})
    t3 = Tile({s3, s2, s1})

    p = Page()

    p.add_tile(t1)
    p.add_tile(t2)
    p.add_tile(t3)

    page_to_str = str(p)

    root = os.path.dirname(__file__)
    abs_path = os.path.join(root, "output")
    abs_path = os.path.join(abs_path, "test_page_to_text_file.txt")
    with open(abs_path, "w") as text_file:
        print(f"{page_to_str}", file=text_file)

    reference_tile_set = {"[N1, N2]", "[N2, N4]", "[N1, N2, N3]"}
    set_of_tiles = set()
    for t in p.tiles:
        set_of_tiles.add(str(t))

    assert set_of_tiles == reference_tile_set

    print("test_on_converting_a_page_to_a_str : everything is fine.\n")
def test_on_the_functions_for_the_counts():
    p = Page()

    s1 = Symbol(1, 4)
    s2 = Symbol(2, 2)
    s3 = Symbol(3, 7)
    s4 = Symbol(4, 1)

    t1 = Tile({s1, s2})
    t2 = Tile({s2, s4})
    t3 = Tile({s3, s2, s1})

    p.add_tile(t1)
    p.add_tile(t2)
    p.add_tile(t3)

    nb_symbols = p.symbol_count()
    nb_tiles = p.tile_count()

    reference_tile_set = {"[N1, N2]", "[N2, N4]", "[N1, N2, N3]"}
    set_of_tiles = set()
    for t in p.tiles:
        set_of_tiles.add(str(t))

    assert set_of_tiles == reference_tile_set
    assert nb_symbols == 4, "It says that the number of symbols on the page is not equal to 4 : problem"
    assert nb_tiles == 3, "It says that the number of tiles on the page is not equal to 3 : problem"

    print("tests_on_the_functions_for_the_counts : everything is fine.\n")
def test_comparison_of_two_different_symbols():
    s1 = Symbol(2, 2)
    s2 = Symbol(100, 10)

    assert s1 < s2, "it says that s1 is greater than s2 : problem"
    assert s1 != s2, "it says that s1 is equal to s2 : problem"
    print("comparison_of_two_different_symbols : everything is fine.\n")
def test_creation_of_two_identical_symbols():
    symb1 = Symbol(1, 4)
    symb2 = Symbol(1, 4)

    assert symb1 == symb2, "It says that symb1 and symb2 are different : problem"
    assert symb1.size == 4, "The size of symbol1 is supposed to be equal to 4 and it is not : problem"
    print("First symbol : ", symb1)
    print("creation_of_two_identical_symbols : everything is fine.\n")
def test_characteristics_of_a_page():
    p = Page()

    s1 = Symbol(1, 4)
    s2 = Symbol(2, 2)
    s3 = Symbol(3, 7)

    t1 = Tile({s1, s2})

    p.add_tile(t1)

    assert s1 in p, "It says that p does not contain s1 : problem"
    assert s3 not in p, "It says that p contains s3 : problem"

    print("characteristics_of_a_page : everything is fine.\n")
def test_on_the_containing_function():
    p = Page()

    s1 = Symbol(1, 4)
    s2 = Symbol(2, 2)
    s3 = Symbol(3, 7)

    t1 = Tile({s1, s2})
    t2 = Tile({s2, s3})

    p.add_tile(t1)

    assert t1 in p, "It says that t1 is not in p : problem"
    assert s1 in p, "It says that s1 is not in p : problem"
    assert t2 not in p, "It says that t2 is in p : problem"
    assert s3 not in p, "It says that s3 is in p : problem"
    print("test_on_the_containing_function : everything is fine.\n")
Exemple #7
0
def test_creation_of_a_tile():
    size1 = 4
    size2 = 2
    size3 = 7
    sum_size = size1 + size2 + size3

    s1 = Symbol(1, 4)
    s2 = Symbol(2, 2)
    s3 = Symbol(3, 7)

    t1 = Tile({s2, s3, s1})

    reference_values = "[N1, N2, N3]"
    tile_in_str = str(t1)
    assert tile_in_str == reference_values

    assert len(t1) == sum_size, "It says that the tile size is not equal to 6 : problem"
def test_of_the_creation_and_of_the_characterics():

    s1 = Symbol(1, 4)
    s2 = Symbol(2, 2)
    s3 = Symbol(3, 7)
    s4 = Symbol(4, 1)

    t1 = Tile({s1, s2})
    t2 = Tile({s2, s4})
    t3 = Tile({s3, s2, s1})

    my_input = ProblemInput({t1, t2, t3}, "problem")
    root = os.path.dirname(__file__)
    abs_path = os.path.join(root, "output")
    my_input.write_instance_in_text_file(abs_path)
    print(
        "test_of_the_creation_and_of_the_characterics : everything is fine.\n")
Exemple #9
0
def creating_the_set_of_all_the_symbols_in_the_intput(the_set, symbols):
    set_of_symbol_indexes = set()
    for temp in the_set:
        my_str = str(temp).replace("[", "")
        my_str = str(my_str).replace("]", "")
        my_str = my_str.replace(" ", "")
        before, separator, after = my_str.partition("-")
        index = int(before.replace("N", ""))
        symbols.add(Symbol(index, int(after)))
        set_of_symbol_indexes.add(index)
    return (symbols, set_of_symbol_indexes)
def test_of_the_creation_and_of_the_characterics_with_opt():

    s1 = Symbol(1, 4)
    s2 = Symbol(2, 5)
    s3 = Symbol(3, 2)
    s4 = Symbol(4, 3)
    s5 = Symbol(5, 4)
    s6 = Symbol(6, 4)

    t1 = Tile({s1, s2})
    t2 = Tile({s2, s3})
    t3 = Tile({s4, s5})
    t4 = Tile({s5, s6})

    C1 = len(t1) + len(t2) - s2.size
    C2 = len(t3) + len(t4) - s5.size
    Cmax = max(C1, C2)

    #  tiles, name, height, max_symbol_size, seed, opt_value, opt_tiles_m1, opt_tiles_m2 ):
    my_input = ProblemInput({t1, t2, t3, t4}, "problem_with_opt", -1, -1, -1,
                            Cmax, {t1, t2}, {t3, t4})
    root = os.path.dirname(__file__)
    abs_path = os.path.join(root, "output")
    my_input.write_instance_in_text_file(abs_path)
    print(
        "test_of_the_creation_and_of_the_characterics_with_opt : everything is fine.\n"
    )
def test_characteristics_of_a_symbol():
    s = Symbol(4, 2)

    print("Symbol name : ", s.name)
    print("Symbol size : ", s.size)
    print("characteristics_of_a_symbol : everything is fine.\n")