Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests #19

Open
matthewjwhite opened this issue Dec 23, 2020 · 2 comments
Open

Add unit tests #19

matthewjwhite opened this issue Dec 23, 2020 · 2 comments

Comments

@matthewjwhite
Copy link
Owner

This project desperately needs some unit tests, especially given the additional complexity added by navigation.

@matthewjwhite
Copy link
Owner Author

Here are some mandatory navigation tests that should be integrated into whatever testbed is developed:

Using configuration:

player:
  class:
    - Mage
    - Barbarian
    - Paladin
monster:
  - name: Hellhound
    strength: 2
    health: 10
  - name: Wizard
    strength: 4
    health: 20
map:
  - name: West Dungeon
    monsters:
      - Hellhound
    dim:
      xMin: 0
      yMin: 0
      xMax: 200
      yMax: 200
  - name: Central Dungeon
    monsters:
      - Wizard
    dim:
      xMin: 201
      yMin: 100
      xMax: 400
      yMax: 300
  - name: East Dungeon
    monsters:
      - Wizard
    dim:
      xMin: 401
      yMin: 0
      xMax: 600
      yMax: 300
  - name: North Dungeon
    monsters:
      - Wizard
    dim:
      xMin: 300
      yMin: 301
      xMax: 450
      yMax: 500
  - name: South Dungeon
    monsters:
      - Wizard
    dim:
      xMin: 250
      yMin: 50
      xMax: 380
      yMax: 99
from game.user import User, BadMove
from game.map import Location, Map

xyz = {'name': 'Bob', 'health': 100, 'strength': 100}

### LEFT/RIGHT

# WEST TO CENTRAL
bob = User(cls='Paladin', key='key', location=Location(mp=Map.get('West Dungeon'), x=200, y=198), **xyz)
bob.move('e')
assert bob.location.map.name == 'Central Dungeon'
assert bob.location.x == 0
assert bob.location.y == 98

# CENTRAL TO EAST
bob.location = Location(mp=Map.get('Central Dungeon'), x=199, y=198)
bob.move('e')
assert bob.location.map.name == 'East Dungeon'
assert bob.location.x == 0
assert bob.location.y == 298

# EAST TO CENTRAL
bob.location = Location(mp=Map.get('East Dungeon'), x=0, y=198)
bob.move('w')
assert bob.location.map.name == 'Central Dungeon'
assert bob.location.x == 199
assert bob.location.y == 98

### UP/ DOWN

# MIDDLE OF CENTRAL
bob.location = Location(mp=Map.get('Central Dungeon'), x=50, y=50)
bob.move('n')
assert bob.location.map.name == 'Central Dungeon'
assert bob.location.x == 50
assert bob.location.y == 51

# CENTRAL TO NORTH
bob.location = Location(mp=Map.get('Central Dungeon'), x=105, y=200)
bob.move('n')
assert bob.location.map.name == 'North Dungeon'
assert bob.location.x == 6
assert bob.location.y == 0

# CENTRAL TO SOUTH
bob.location = Location(mp=Map.get('Central Dungeon'), x=150, y=0)
bob.move('s')
assert bob.location.map.name == 'South Dungeon'
assert bob.location.x == 101
assert bob.location.y == 49

# EAST TO NORTH
bob.location = Location(mp=Map.get('East Dungeon'), x=40, y=300)
bob.move('n')
assert bob.location.map.name == 'North Dungeon'
assert bob.location.x == 141
assert bob.location.y == 0

# MULTIMAP CORNER WALK
bob.location = Location(mp=Map.get('Central Dungeon'), x=199, y=200)
bob.move('n')
assert bob.location.map.name == 'North Dungeon'
assert bob.location.x == 100
assert bob.location.y == 0
bob.move('e')
assert bob.location.map.name == 'North Dungeon'
assert bob.location.x == 101
assert bob.location.y == 0
bob.move('s')
assert bob.location.map.name == 'East Dungeon'
assert bob.location.x == 0
assert bob.location.y == 300
bob.move('w')
assert bob.location.map.name == 'Central Dungeon'
assert bob.location.x == 199
assert bob.location.y == 200


### EDGE/BOUNDARY (LITERAL) CASES

# NORTH, NO NEIGHBOR
bob.location = Location(mp=Map.get('North Dungeon'), x=75, y=199)
try:
    bob.move('n')
    raise Exception('Should have failed!')
except Exception as error:
    assert type(error) is BadMove

# SOUTH, NO NEIGHBOR
bob.location = Location(mp=Map.get('South Dungeon'), x=100, y=0)
try:
    bob.move('s')
    raise Exception('Should have failed!')
except Exception as error:
    assert type(error) is BadMove

# WEST, NO NEIGHBOR
bob.location = Location(mp=Map.get('West Dungeon'), x=0, y=50)
try:
    bob.move('w')
    raise Exception('Should have failed!')
except Exception as error:
    assert type(error) is BadMove

# EAST, NO NEIGHBOR
bob.location = Location(mp=Map.get('East Dungeon'), x=199, y=299)
try:
    bob.move('e')
    raise Exception('Should have failed!')
except Exception as error:
    assert type(error) is BadMove

@matthewjwhite
Copy link
Owner Author

Some other great ideas for tests:

  • All constructors.
  • Results of constructors -> to_cfg/db (whichever applicable) -> from_cfg/db, ensure same contents.
    • Confirm that, for example, Map references indeed refer to the same object, since one of the key points is to avoid duplication of data in memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant