88from ..types .clash_of_code import LanguageIds , Mode , Modes
99from ..utils import minified_players_to_players , to_datetime
1010from .player import Player
11- from .question import Question
11+ from .question import Question , TestCaseResult
12+ from .solution import Solution
1213
1314if TYPE_CHECKING :
1415 from ..state import ConnectionState
1516
16- __all__ = ("ClashOfCode" , "Solution" , "TestCaseResult" )
17-
18-
19- class TestCaseResult (BaseObject ):
20- success : bool
21- found : str
22- expected : str
23-
24- __slots__ = ("success" , "found" , "expected" )
25-
26- def __init__ (self , state : "ConnectionState" , data : dict ):
27- self .success = data ["comparison" ]["success" ]
28- self .found = (
29- data ["output" ] if self .success else data ["comparison" ]["success" ]
30- )
31- self .expected = (
32- data ["output" ] if self .success else data ["comparison" ]["success" ]
33- )
34-
35- super ().__init__ (state )
36-
37-
38- class Solution (BaseObject ):
39- __slots__ = ()
40-
41- def __init__ (self , state : "ConnectionState" , data : dict ):
42- ...
43-
44- super ().__init__ (state )
45-
46- def share (self ):
47- ...
17+ __all__ = ("ClashOfCode" ,)
4818
4919
5020class ClashOfCode (BaseObject ):
@@ -456,7 +426,9 @@ async def _get_question():
456426 )
457427 )
458428 self ._question = Question (
459- self ._state , test_session ["currentQuestion" ]["question" ]
429+ self ._state ,
430+ self ,
431+ test_session ["currentQuestion" ]["question" ],
460432 )
461433
462434 if refetch :
@@ -480,7 +452,9 @@ def _get_question():
480452 )
481453 )
482454 self ._question = Question (
483- self ._state , test_session ["currentQuestion" ]["question" ]
455+ self ._state ,
456+ self ,
457+ test_session ["currentQuestion" ]["question" ],
484458 )
485459
486460 if refetch :
@@ -532,15 +506,19 @@ async def _play_test_cases():
532506 if not self ._question :
533507 await self .get_question ()
534508
535- all_indexes = [tc .index for tc in self ._question .test_cases ]
536509 results = {}
537- for index in all_indexes :
538- if indexes and index not in indexes :
510+ for test_case in self . _question . test_cases :
511+ if indexes and test_case . index not in indexes :
539512 continue
540513 result = await self ._state .http .play_test_session_by_handle (
541- self ._test_session_handle , language_id , code , index
514+ self ._test_session_handle ,
515+ language_id ,
516+ code ,
517+ test_case .index ,
518+ )
519+ results [test_case .index ] = TestCaseResult (
520+ self ._state , self , test_case , result
542521 )
543- results [index ] = TestCaseResult (self ._state , result )
544522
545523 if refetch :
546524 await self .fetch ()
@@ -553,15 +531,19 @@ def _play_test_cases():
553531 if not self ._question :
554532 self .get_question ()
555533
556- all_indexes = [tc .index for tc in self ._question .test_cases ]
557534 results = {}
558- for index in all_indexes :
559- if indexes and index not in indexes :
535+ for test_case in self . _question . test_cases :
536+ if indexes and test_case . index not in indexes :
560537 continue
561538 result = self ._state .http .play_test_session_by_handle (
562- self ._test_session_handle , language_id , code , index
539+ self ._test_session_handle ,
540+ language_id ,
541+ code ,
542+ test_case .index ,
543+ )
544+ results [test_case .index ] = TestCaseResult (
545+ self ._state , self , test_case , result
563546 )
564- results [index ] = TestCaseResult (self ._state , result )
565547
566548 if refetch :
567549 self .fetch ()
@@ -620,7 +602,7 @@ async def _submit():
620602 if refetch :
621603 await self .fetch ()
622604
623- return Solution (self ._state , solution )
605+ return Solution (self ._state , self , solution )
624606
625607 else :
626608
@@ -638,6 +620,6 @@ def _submit():
638620 if refetch :
639621 self .fetch ()
640622
641- return Solution (self ._state , solution )
623+ return Solution (self ._state , self , solution )
642624
643625 return _submit ()
0 commit comments