# Path: cwmud/core/world.py
# class Room(Entity):
# 
#     """A MUD room.  Where the magic happens."""
# 
#     _uid_code = "R"
# 
#     type = "room"
# 
#     # These are used to generate Character.act messages.
#     _movement_strings = {
#         (1, 0, 0): ("east", "the west"),
#         (-1, 0, 0): ("west", "the east"),
#         (0, 1, 0): ("north", "the south"),
#         (0, -1, 0): ("south", "the north"),
#         (0, 0, 1): ("up", "below"),
#         (0, 0, -1): ("down", "above"),
#         (1, 1, 0): ("northeast", "the southwest"),
#         (-1, 1, 0): ("northwest", "the southeast"),
#         (1, -1, 0): ("southeast", "the northwest"),
#         (-1, -1, 0): ("southwest", "the northeast"),
#     }
# 
#     def __repr__(self):
#         name = self.name if self.name else "(unnamed)"
#         return joins("Room<", name, ":", self.get_coord_str(), ">", sep="")
# 
#     @property
#     def coords(self):
#         """Return a tuple of this room's x,y,z coordinates."""
#         return self.x, self.y, self.z
# 
#     def get_coord_str(self):
#         """Return a string representing the coordinates for this room.
# 
#         :returns str: The coordinate string
# 
#         """
#         if self.x is Unset or self.y is Unset or self.z is Unset:
#             return Unset
#         return "{},{},{}".format(self.x, self.y, self.z)
# 
#     def set_coord_from_str(self, coord_str):
#         """Set this room's coordinates given a string.
# 
#         :param str coord_str: A string of coordinates in the form "x,y,z"
#         :returns None:
# 
#         """
#         self.x, self.y, self.z = map(int, coord_str.split(","))
# 
#     @classmethod
#     def generate(cls, coord_str, name, description=None):
#         """Generate a room.
# 
#         :param str coord_str: The string with the room's coordinates
#         :param str name: A name for the room
#         :param description: Optional, a description for the room
#         :returns Room: The generated room
# 
#         """
#         room = Room()
#         room.set_coord_from_str(coord_str)
#         room.name = name
#         if description is not None:
#             room.description = description
#         room.save()
#         return room
# 
#     def get_exits(self):
#         """Return the rooms this room connects to.
# 
#         :returns dict: The connecting rooms, keyed by direction name
# 
#         """
#         # This is an inefficient placeholder until an Exit type is in.
#         found = {}
#         for change, (dir_name, rev_name) in self._movement_strings.items():
#             x, y, z = map(sum, zip(self.coords, change))
#             room = Room.get(x=x, y=y, z=z)
#             if room:
#                 found[dir_name] = room
#         return found
# 
#     @classmethod
#     def get_movement_strings(cls, change):
#         """Return a pair of strings to describe character movement.
# 
#         :param tuple<int,int,int> change: A tuple of the (x,y,z) change
#         :returns tuple<str,str>: The relevant to and from strings
# 
#         """
#         return cls._movement_strings.get(change, ("nowhere", "nowhere"))


import gc
import pytest
from cwmud.core.attributes import Unset
from cwmud.core.players import Player
from cwmud.core.world import Room



class TestRooms:

    """A collection of tests for room entities."""

    room = None

    def test_room_create(self):
        """Test that we can create a room."""
        type(self).room = Room()

    def test_room_coords(self):
        """Test that room coordinates function properly."""
        assert self.room.coords == (Unset, Unset, Unset)
        assert self.room.get_coord_str() == Unset
        self.room.x, self.room.y, self.room.z = (5, 5, 5)
        assert self.room.coords == (5, 5, 5)
        assert self.room.get_coord_str() == "5,5,5"
        with pytest.raises(ValueError):
            self.room.x = "123"
        with pytest.raises(ValueError):
            self.room.y = "123"
        with pytest.raises(ValueError):
            self.room.z = "123"

    def test_room_exits(self):
        """Test that room exits function properly."""
        assert not self.room.get_exits()

# Path: cwmud/core/world.py
# class Room(Entity):
# 
#     """A MUD room.  Where the magic happens."""
# 
#     _uid_code = "R"
# 
#     type = "room"
# 
#     # These are used to generate Character.act messages.
#     _movement_strings = {
#         (1, 0, 0): ("east", "the west"),
#         (-1, 0, 0): ("west", "the east"),
#         (0, 1, 0): ("north", "the south"),
#         (0, -1, 0): ("south", "the north"),
#         (0, 0, 1): ("up", "below"),
#         (0, 0, -1): ("down", "above"),
#         (1, 1, 0): ("northeast", "the southwest"),
#         (-1, 1, 0): ("northwest", "the southeast"),
#         (1, -1, 0): ("southeast", "the northwest"),
#         (-1, -1, 0): ("southwest", "the northeast"),
#     }
# 
#     def __repr__(self):
#         name = self.name if self.name else "(unnamed)"
#         return joins("Room<", name, ":", self.get_coord_str(), ">", sep="")
# 
#     @property
#     def coords(self):
#         """Return a tuple of this room's x,y,z coordinates."""
#         return self.x, self.y, self.z
# 
#     def get_coord_str(self):
#         """Return a string representing the coordinates for this room.
# 
#         :returns str: The coordinate string
# 
#         """
#         if self.x is Unset or self.y is Unset or self.z is Unset:
#             return Unset
#         return "{},{},{}".format(self.x, self.y, self.z)
# 
#     def set_coord_from_str(self, coord_str):
#         """Set this room's coordinates given a string.
# 
#         :param str coord_str: A string of coordinates in the form "x,y,z"
#         :returns None:
# 
#         """
#         self.x, self.y, self.z = map(int, coord_str.split(","))
# 
#     @classmethod
#     def generate(cls, coord_str, name, description=None):
#         """Generate a room.
# 
#         :param str coord_str: The string with the room's coordinates
#         :param str name: A name for the room
#         :param description: Optional, a description for the room
#         :returns Room: The generated room
# 
#         """
#         room = Room()
#         room.set_coord_from_str(coord_str)
#         room.name = name
#         if description is not None:
#             room.description = description
#         room.save()
#         return room
# 
#     def get_exits(self):
#         """Return the rooms this room connects to.
# 
#         :returns dict: The connecting rooms, keyed by direction name
# 
#         """
#         # This is an inefficient placeholder until an Exit type is in.
#         found = {}
#         for change, (dir_name, rev_name) in self._movement_strings.items():
#             x, y, z = map(sum, zip(self.coords, change))
#             room = Room.get(x=x, y=y, z=z)
#             if room:
#                 found[dir_name] = room
#         return found
# 
#     @classmethod
#     def get_movement_strings(cls, change):
#         """Return a pair of strings to describe character movement.
# 
#         :param tuple<int,int,int> change: A tuple of the (x,y,z) change
#         :returns tuple<str,str>: The relevant to and from strings
# 
#         """
#         return cls._movement_strings.get(change, ("nowhere", "nowhere"))


# Path: tests/core/test_world.py
import gc
import pytest
from cwmud.core.attributes import Unset
from cwmud.core.players import Player
from cwmud.core.world import Room




class TestRooms:

    """A collection of tests for room entities."""

    room = None

    def test_room_create(self):
        """Test that we can create a room."""
        type(self).room = Room()

    def test_room_coords(self):
        """Test that room coordinates function properly."""
        assert self.room.coords == (Unset, Unset, Unset)
        assert self.room.get_coord_str() == Unset
        self.room.x, self.room.y, self.room.z = (5, 5, 5)
        assert self.room.coords == (5, 5, 5)
        assert self.room.get_coord_str() == "5,5,5"
        with pytest.raises(ValueError):
            self.room.x = "123"
        with pytest.raises(ValueError):
            self.room.y = "123"
        with pytest.raises(ValueError):
            self.room.z = "123"

    def test_room_exits(self):
        """Test that room exits function properly."""
        assert not self.room.get_exits()

        another_room = Room()