示例#1
0
def test_conflict_game_02_03():
    # arrange
    situation: Situation = Situation(
        orders=[
            # conflict 02:
            mk_order("Au A Vie mve Mun"),
            mk_order_0("Ge A Mun"),
            # conflict 03:
            mk_order("En F Lon mve NTH"),
            mk_order("En F CHN msup Lon"),
            mk_order("Ge F NTH con Kie"),
            mk_order("Ge A Kie mve Lon"),
        ], )
    # act
    result = conflict_game(situation)
    # assert
    expected = ConflictResolution(
        orders=[
            # conflict 02: Vie can not move, Mun holds
            mk_oresult("Au A Vie mve Mun !"),
            mk_oresult("Ge A Mun hld Mun"),
            # conflict 03: Lon moves and breaks convoy, NTH dislodged, Kie fails.
            mk_oresult("En F Lon mve NTH"),
            mk_oresult("En F CHN msup Lon"),
            mk_oresult("Ge F NTH con Kie >"),
            mk_oresult("Ge A Kie mve Lon !"),
        ],
        pattfields=set())
    assert result <= expected, f"\nres: {result.__log__()} !=\nexp: {expected.__log__()}"  # or use == with clear_originals().
示例#2
0
def test_6_a_11():
    """
    === 6.A.11. TEST CASE, SIMPLE BOUNCE ===

    Two armies bouncing on each other.

        Austria:
        A Vienna - Tyrolia

        Italy:
        A Venice - Tyrolia

    The two units bounce.
    """
    # arrange
    situation: Situation = Situation(orders=[
        mk_order("Au A Vie mve Tyr"),
        mk_order("It A Ven mve Tyr"),
    ], )
    # act
    result = conflict_game(situation)
    # assert
    expected = ConflictResolution(
        orders=[
            mk_oresult(
                "Au A Vie mve Tyr !"
            ),  # TODO check if its ok to not change dest field along with order.
            mk_oresult(
                "It A Ven mve Tyr !"
            ),  # TODO check if its ok to not change dest field along with order.
        ],
        pattfields={"Tyr"})
    result.show(sys.stderr, line_prefix="| ")
    # '<=' ignores 'original'
    assert result <= expected, f"\nres: {result.__log__()} !=\nexp: {expected.__log__()}"
示例#3
0
 def test_testdata(self, id, orders, order_results, pattfields):
     # arrange
     situation: Situation = Situation(orders=orders)
     # act
     result = conflict_game(situation)
     # assert
     expected = ConflictResolution(orders=order_results,
                                   pattfields=pattfields)
     # '<=' ignores 'original'
     assert result <= expected, f"\nres: {result.__log__()} !=\nexp: {expected.__log__()}"
示例#4
0
def _op_ConflictResolution(op, left: ConflictResolution,
                           right: ConflictResolution):
    if False:
        import pprint
        ls = pprint.pformat(left.json(), 2, 240).splitlines()
        rs = pprint.pformat(right.json(), 2, 240).splitlines()
        return ["Comparing ConflictResolution instances:"
                ] + ["LEFT:"] + ls + ["RIGHT:"] + rs
    elif False:
        res = ["Comparing ConflictResolution instances: " + op]
        res.append("ORDERS:")
        for lo, ro in zip_longest(left.orders, right.orders, fillvalue=None):
            if lo != ro:
                res.append(f"!!! {lo} != {ro}")
            else:
                res.append(f"== {lo} == {ro}")
        res.append(f"PATTFIELDS: {left.pattfields} =?= {right.pattfields}")
        return res
    return ["left " + op + " right:", left.__log__(), right.__log__()]
示例#5
0
def test_conflict_game_01():
    # arrange
    situation: Situation = Situation(orders=[
        mk_order_h("Ge A Mun hld"),
    ], )
    # act
    result = conflict_game(situation)
    # assert
    expected = ConflictResolution(orders=[
        mk_oresult("Ge A Mun hld Mun"),
    ],
                                  pattfields=set())
    assert result <= expected  # or use == with clear_originals().
示例#6
0
def test_conflict_game_01a():
    # arrange
    situation: Situation = Situation(orders=[
        mk_order("Ge A Mun mve Kie"),
    ], )
    # act
    result = conflict_game(situation)
    # assert
    expected = ConflictResolution(orders=[
        mk_oresult("Ge A Mun mve Kie"),
    ],
                                  pattfields=set())
    # '<=' ignores 'original'
    assert result <= expected, f"\nres: {result.__log__()} !=\nexp: {expected.__log__()}"
示例#7
0
def test_conflict_game_03():
    # arrange
    situation: Situation = Situation(orders=[
        mk_order("En F Lon mve NTH"),
        mk_order("En F CHN msup Lon"),
        mk_order("Ge F NTH con Kie"),
        mk_order("Ge A Kie mve Lon"),
    ], )
    # act
    result = conflict_game(situation)
    # assert
    expected = ConflictResolution(orders=[
        mk_oresult("En F Lon mve NTH"),
        mk_oresult("En F CHN msup Lon"),
        mk_oresult("Ge F NTH con Kie >"),
        mk_oresult("Ge A Kie mve Lon !"),
    ],
                                  pattfields=set())
    assert result <= expected  # or use == with clear_originals().
示例#8
0
def test_conflict_game_patt_01():
    # arrange
    situation: Situation = Situation(orders=[
        mk_order("Ge A Mun mve Vie"),
        mk_order("Au A Tri mve Vie"),
    ], )
    # act
    result = conflict_game(situation)
    # assert
    expected = ConflictResolution(
        orders=[
            mk_oresult("Ge A Mun hld Vie !"
                       ),  # TODO check if changed order but kept dest is ok
            mk_oresult("Au A Tri hld Vie !"
                       ),  # TODO check if changed order but kept dest is ok
        ],
        pattfields={"Vie"})
    assert result <= expected, f"\nres: {result.__log__()}\nexp: {expected.__log__()}"  # or use == with clear_originals().
    assert result.clear_originals(
    ) == expected  # or use <= to keep information
示例#9
0
def test_conflict_game_02():
    # arrange
    situation: Situation = Situation(orders=[
        mk_order("Au A Vie mve Mun"),
        mk_order_0("Ge A Mun"),
    ],
                                     switches=Switches(verbose=True))
    # act
    result = conflict_game(situation)
    # assert
    expected = ConflictResolution(
        orders=[
            mk_oresult(
                "Au A Vie hld Mun !"
            ),  # TODO check if its ok to not change dest field along with order.
            mk_oresult("Ge A Mun hld Mun"),
        ],
        pattfields=set())
    # '<=' ignores 'original'
    assert result <= expected, f"\nres: {result.__log__()} !=\nexp: {expected.__log__()}"
    # better way using '==' but loosing information.
    assert result.clear_originals(
    ) == expected, f"\nres: {result.__log__()} !=\nexp: {expected.__log__()}"