exploration.tests.test_geographic

Authors: Peter Mawhorter, Nissi Awosanya, Kitty Boakye Consulted: Date: 2023-6-9 Purpose: Tests for open-world (geographic) exploration representation.

  1"""
  2Authors: Peter Mawhorter, Nissi Awosanya, Kitty Boakye
  3Consulted:
  4Date: 2023-6-9
  5Purpose: Tests for open-world (geographic) exploration representation.
  6"""
  7
  8import pytest
  9
 10from .. import parsing
 11from .. import geographic
 12
 13
 14def test_MetricSpace() -> None:
 15    """
 16    All-around test for various features of `geographic.MetricSpace`.
 17    """
 18    # TODO
 19
 20
 21@pytest.fixture
 22def pf():
 23    """
 24    Returns a default `parsing.ParseFormat`.
 25    """
 26    return parsing.ParseFormat()
 27
 28
 29@pytest.fixture
 30def chasmExample():
 31    """
 32    Uses the `example` class method to return a new instance of the
 33    'chasm' example graph for testing.
 34    """
 35    return geographic.FeatureGraph.example('chasm')
 36
 37
 38@pytest.fixture
 39def townExample():
 40    """
 41    Uses the `example` class method to return a new instance of the
 42    'town' example graph for testing.
 43    """
 44    return geographic.FeatureGraph.example('town')
 45
 46
 47@pytest.fixture
 48def intercomExample():
 49    """
 50    Uses the `example` class method to return a new instance of the
 51    'intercom' example graph for testing.
 52    """
 53    return geographic.FeatureGraph.example('intercom')
 54
 55
 56def test_BuildFeatureGraph(
 57    townExample,
 58    chasmExample,
 59    intercomExample,
 60    pf
 61) -> None:
 62    """
 63    Test basic relationships in the town, chasm, and intercom examples.
 64    """
 65    # Chasm example
 66    assert (
 67        chasmExample.listFeatures() == [
 68            (0, 'main', 'region'),
 69            (1, 'east', 'region'),
 70            (2, 'west', 'region'),
 71            (3, 'chasm', 'edge'),
 72            (4, 'bridge', 'path'),
 73            (5, 'bridgeLever', 'affordance'),
 74            (6, 'house', 'node'),
 75            (7, 'openChest', 'affordance'),
 76            (8, 'crossroads', 'node'),
 77            (9, 'windmill', 'landmark'),
 78            (10, 'housePath', 'path'),
 79            (11, 'startPath', 'path'),
 80            (12, 'startingGrove', 'node'),
 81            (13, 'bridgePath', 'path'),
 82            (14, 'bridgePath', 'path'),
 83            (15, 'house', 'node'),
 84            (16, 'basement', 'region'),
 85            (17, 'downstairs', 'region'),
 86            (18, 'upstairs', 'region'),
 87            (19, 'stairs', 'path'),
 88        ]
 89    )
 90    with pytest.raises(geographic.AmbiguousFeatureSpecifierError):
 91        chasmExample.resolveFeature('house')
 92    with pytest.raises(geographic.AmbiguousFeatureSpecifierError):
 93        chasmExample.resolveFeature('bridgePath')
 94    f = pf.parseFeatureSpecifier
 95    assert chasmExample.resolveFeature(f("east::house")) == 6
 96    assert chasmExample.resolveFeature(f("west::house")) == 15
 97    assert chasmExample.resolveFeature(f("east::bridgePath")) == 13
 98    assert chasmExample.resolveFeature(f("west::bridgePath")) == 14
 99    assert chasmExample.relations(7, 'within') == {6}
100    assert chasmExample.relations(6, 'contains') == {7}
101    assert chasmExample.relations(17, 'within') == {15}
102    assert chasmExample.relations(17, 'touches') == {19}
103
104    # Town example
105    assert (
106        townExample.listFeatures() == [
107            (0, 'town', 'region'),
108            (1, 'castleHill', 'region'),
109            (2, 'castle', 'node'),
110            (3, 'market', 'region'),
111            (4, 'eastResidences', 'region'),
112            (5, 'southResidences', 'region'),
113            (6, 'marketSquare', 'node'),
114            (7, 'ringRoad', 'path'),
115            (8, 'mainRoad', 'path'),
116            (9, 'wall', 'edge'),
117            (10, 'outside', 'region'),
118        ]
119    )
120    assert townExample.relations(7, 'touches') == {6}
121    assert townExample.relations(8, 'touches') == {2, 6, 9}
122    assert townExample.relations(7, 'within') == {0, 3, 4, 5}
123    assert townExample.relations(8, 'within') == {0, 1, 3, 10}
124
125    # Intercom example
126    assert (
127        intercomExample.listFeatures() == [
128            (0, 'swamp', 'region'),
129            (1, 'eastSwamp', 'region'),
130            (2, 'westSwamp', 'region'),
131            (3, 'midSwamp', 'region'),
132            (4, 'house', 'node'),
133            (5, 'inside', 'region'),
134            (6, 'kitchen', 'region'),
135            (7, 'intercom', 'affordance'),
136        ]
137    )
138    assert intercomExample.relations(1, 'within') == {0}
139    assert intercomExample.relations(4, 'within') == {2, 3}
140    assert intercomExample.relations(3, 'touches') == {1, 2}
141    assert intercomExample.relations(1, 'touches') == {3}
142    assert intercomExample.relations(2, 'touches') == {3}
143    assert intercomExample.relations(2, 'contains') == {4}
144    assert intercomExample.relations(3, 'contains') == {4}
145    assert intercomExample.relations(7, 'within') == {5, 6}
146
147
148def test_FeatureGraph(chasmExample) -> None:
149    """
150    All-around test for various features of `geographic.FeatureGraph`.
151    """
152    # TODO
153
154
155def test_FeatureDecision() -> None:
156    """
157    All-around test for various features of `geographic.FeatureDecision`.
158    """
159    # TODO
160
161
162def test_FeatureAction() -> None:
163    """
164    All-around test for various features of `geographic.FeatureAction`.
165    """
166    # TODO
167
168
169def test_GeographicExploration() -> None:
170    """
171    All-around test for various features of
172    `geographic.GeographicExploration`.
173    """
174    # TODO
def test_MetricSpace() -> None:
15def test_MetricSpace() -> None:
16    """
17    All-around test for various features of `geographic.MetricSpace`.
18    """
19    # TODO

All-around test for various features of geographic.MetricSpace.

@pytest.fixture
def pf():
22@pytest.fixture
23def pf():
24    """
25    Returns a default `parsing.ParseFormat`.
26    """
27    return parsing.ParseFormat()

Returns a default parsing.ParseFormat.

@pytest.fixture
def chasmExample():
30@pytest.fixture
31def chasmExample():
32    """
33    Uses the `example` class method to return a new instance of the
34    'chasm' example graph for testing.
35    """
36    return geographic.FeatureGraph.example('chasm')

Uses the example class method to return a new instance of the 'chasm' example graph for testing.

@pytest.fixture
def townExample():
39@pytest.fixture
40def townExample():
41    """
42    Uses the `example` class method to return a new instance of the
43    'town' example graph for testing.
44    """
45    return geographic.FeatureGraph.example('town')

Uses the example class method to return a new instance of the 'town' example graph for testing.

@pytest.fixture
def intercomExample():
48@pytest.fixture
49def intercomExample():
50    """
51    Uses the `example` class method to return a new instance of the
52    'intercom' example graph for testing.
53    """
54    return geographic.FeatureGraph.example('intercom')

Uses the example class method to return a new instance of the 'intercom' example graph for testing.

def test_BuildFeatureGraph(townExample, chasmExample, intercomExample, pf) -> None:
 57def test_BuildFeatureGraph(
 58    townExample,
 59    chasmExample,
 60    intercomExample,
 61    pf
 62) -> None:
 63    """
 64    Test basic relationships in the town, chasm, and intercom examples.
 65    """
 66    # Chasm example
 67    assert (
 68        chasmExample.listFeatures() == [
 69            (0, 'main', 'region'),
 70            (1, 'east', 'region'),
 71            (2, 'west', 'region'),
 72            (3, 'chasm', 'edge'),
 73            (4, 'bridge', 'path'),
 74            (5, 'bridgeLever', 'affordance'),
 75            (6, 'house', 'node'),
 76            (7, 'openChest', 'affordance'),
 77            (8, 'crossroads', 'node'),
 78            (9, 'windmill', 'landmark'),
 79            (10, 'housePath', 'path'),
 80            (11, 'startPath', 'path'),
 81            (12, 'startingGrove', 'node'),
 82            (13, 'bridgePath', 'path'),
 83            (14, 'bridgePath', 'path'),
 84            (15, 'house', 'node'),
 85            (16, 'basement', 'region'),
 86            (17, 'downstairs', 'region'),
 87            (18, 'upstairs', 'region'),
 88            (19, 'stairs', 'path'),
 89        ]
 90    )
 91    with pytest.raises(geographic.AmbiguousFeatureSpecifierError):
 92        chasmExample.resolveFeature('house')
 93    with pytest.raises(geographic.AmbiguousFeatureSpecifierError):
 94        chasmExample.resolveFeature('bridgePath')
 95    f = pf.parseFeatureSpecifier
 96    assert chasmExample.resolveFeature(f("east::house")) == 6
 97    assert chasmExample.resolveFeature(f("west::house")) == 15
 98    assert chasmExample.resolveFeature(f("east::bridgePath")) == 13
 99    assert chasmExample.resolveFeature(f("west::bridgePath")) == 14
100    assert chasmExample.relations(7, 'within') == {6}
101    assert chasmExample.relations(6, 'contains') == {7}
102    assert chasmExample.relations(17, 'within') == {15}
103    assert chasmExample.relations(17, 'touches') == {19}
104
105    # Town example
106    assert (
107        townExample.listFeatures() == [
108            (0, 'town', 'region'),
109            (1, 'castleHill', 'region'),
110            (2, 'castle', 'node'),
111            (3, 'market', 'region'),
112            (4, 'eastResidences', 'region'),
113            (5, 'southResidences', 'region'),
114            (6, 'marketSquare', 'node'),
115            (7, 'ringRoad', 'path'),
116            (8, 'mainRoad', 'path'),
117            (9, 'wall', 'edge'),
118            (10, 'outside', 'region'),
119        ]
120    )
121    assert townExample.relations(7, 'touches') == {6}
122    assert townExample.relations(8, 'touches') == {2, 6, 9}
123    assert townExample.relations(7, 'within') == {0, 3, 4, 5}
124    assert townExample.relations(8, 'within') == {0, 1, 3, 10}
125
126    # Intercom example
127    assert (
128        intercomExample.listFeatures() == [
129            (0, 'swamp', 'region'),
130            (1, 'eastSwamp', 'region'),
131            (2, 'westSwamp', 'region'),
132            (3, 'midSwamp', 'region'),
133            (4, 'house', 'node'),
134            (5, 'inside', 'region'),
135            (6, 'kitchen', 'region'),
136            (7, 'intercom', 'affordance'),
137        ]
138    )
139    assert intercomExample.relations(1, 'within') == {0}
140    assert intercomExample.relations(4, 'within') == {2, 3}
141    assert intercomExample.relations(3, 'touches') == {1, 2}
142    assert intercomExample.relations(1, 'touches') == {3}
143    assert intercomExample.relations(2, 'touches') == {3}
144    assert intercomExample.relations(2, 'contains') == {4}
145    assert intercomExample.relations(3, 'contains') == {4}
146    assert intercomExample.relations(7, 'within') == {5, 6}

Test basic relationships in the town, chasm, and intercom examples.

def test_FeatureGraph(chasmExample) -> None:
149def test_FeatureGraph(chasmExample) -> None:
150    """
151    All-around test for various features of `geographic.FeatureGraph`.
152    """
153    # TODO

All-around test for various features of geographic.FeatureGraph.

def test_FeatureDecision() -> None:
156def test_FeatureDecision() -> None:
157    """
158    All-around test for various features of `geographic.FeatureDecision`.
159    """
160    # TODO

All-around test for various features of geographic.FeatureDecision.

def test_FeatureAction() -> None:
163def test_FeatureAction() -> None:
164    """
165    All-around test for various features of `geographic.FeatureAction`.
166    """
167    # TODO

All-around test for various features of geographic.FeatureAction.

def test_GeographicExploration() -> None:
170def test_GeographicExploration() -> None:
171    """
172    All-around test for various features of
173    `geographic.GeographicExploration`.
174    """
175    # TODO

All-around test for various features of geographic.GeographicExploration.