|
| 1 | +import pytest |
| 2 | + |
| 3 | +from libs.placement_controller import PlacementController |
| 4 | +from libs.node import Node, Color |
| 5 | + |
| 6 | + |
| 7 | +@pytest.fixture |
| 8 | +def placement_data(): |
| 9 | + """ creates simple placement data |
| 10 | + Placement bellow: |
| 11 | + |
| 12 | + A D |
| 13 | + \ / |
| 14 | + B-\/-E |
| 15 | + /\ |
| 16 | + / \ |
| 17 | + C F |
| 18 | + |
| 19 | + Total there are 3 intersection within this placement. |
| 20 | + """ |
| 21 | + |
| 22 | + layers = [] |
| 23 | + layer1 = [] |
| 24 | + layer2 = [] |
| 25 | + |
| 26 | + dummy_color = Color(0,0,0) |
| 27 | + A = Node("A",dummy_color) |
| 28 | + B = Node("B",dummy_color) |
| 29 | + C = Node("C",dummy_color) |
| 30 | + D = Node("D",dummy_color) |
| 31 | + E = Node("E",dummy_color) |
| 32 | + F = Node("F",dummy_color) |
| 33 | + |
| 34 | + A.add_connection(F) |
| 35 | + B.add_connection(E) |
| 36 | + C.add_connection(D) |
| 37 | + |
| 38 | + |
| 39 | + layer1.append(A) |
| 40 | + layer1.append(B) |
| 41 | + layer1.append(C) |
| 42 | + |
| 43 | + layer2.append(D) |
| 44 | + layer2.append(E) |
| 45 | + layer2.append(F) |
| 46 | + |
| 47 | + |
| 48 | + layers.append(layer1) |
| 49 | + layers.append(layer2) |
| 50 | + |
| 51 | + return layers |
| 52 | + |
| 53 | +def test_count_intersections_raw(placement_data): |
| 54 | + pc = PlacementController(); |
| 55 | + pc.set_data(placement_data) |
| 56 | + assert 3 == pc.calc_intersections() |
| 57 | + |
| 58 | +def test_count_intersections_on_swap_colmns(placement_data): |
| 59 | + pc = PlacementController(); |
| 60 | + placement_data[0],placement_data[1] = placement_data[1],placement_data[0] |
| 61 | + pc.set_data(placement_data) |
| 62 | + assert 0 == pc.calc_intersections() |
| 63 | + |
| 64 | +def test_count_intersections_on_swap_inside_first_column(placement_data): |
| 65 | + pc = PlacementController(); |
| 66 | + placement_data[0][0],placement_data[0][2] = placement_data[0][2],placement_data[0][0] |
| 67 | + pc.set_data(placement_data) |
| 68 | + assert 0 == pc.calc_intersections() |
| 69 | + |
| 70 | +def test_count_intersections_on_swap_inside_second_column(placement_data): |
| 71 | + pc = PlacementController(); |
| 72 | + placement_data[1][0],placement_data[1][1] = placement_data[1][1],placement_data[1][0] |
| 73 | + pc.set_data(placement_data) |
| 74 | + assert 2 == pc.calc_intersections() |
| 75 | + |
| 76 | + |
| 77 | + |
0 commit comments