Skip to content

Commit

Permalink
Cursor 모델 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
byundojin committed Nov 21, 2024
1 parent 0ea0b51 commit 81d8058
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cursor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .internal.color import Color
from .internal.cursor import Cursor
14 changes: 14 additions & 0 deletions cursor/internal/color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from enum import Enum
from random import randint

class Color(Enum):
RED = "RED"
YELLOW = "YELLOW"
GREEN = "GREEN"
BLUE = "BLUE"

@staticmethod
def get_random():
rand_idx = randint(0, len(Color._member_names_) - 1)
color = Color._member_names_[rand_idx]
return Color._member_map_[color]
19 changes: 19 additions & 0 deletions cursor/internal/cursor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from board import Point
from .color import Color
from dataclasses import dataclass

@dataclass
class Cursor:
conn_id: str
position: Point
pointer: Point | None
color: Color

@staticmethod
def create(conn_id: str):
return Cursor(
conn_id=conn_id,
position=Point(0, 0),
pointer=None,
color=Color.get_random()
)
1 change: 1 addition & 0 deletions cursor/test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .cursor_test import CursorTestCase
16 changes: 16 additions & 0 deletions cursor/test/cursor_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from cursor import Cursor, Color
import unittest

class CursorTestCase(unittest.TestCase):
def test_cursor_create(self):
conn_id = "some id"
cursor = Cursor.create(conn_id)

self.assertEqual(cursor.conn_id, conn_id)
self.assertEqual(cursor.position.x, 0)
self.assertEqual(cursor.position.y, 0)
self.assertIsNone(cursor.pointer)
self.assertIn(cursor.color, Color)

if __name__ == "__main__":
unittest.main()
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
from conn.test import *
from conn.manager.test import *

#cursor
from cursor.test import *

if __name__ == "__main__":
unittest.main()

0 comments on commit 81d8058

Please sign in to comment.