2월, 2025의 게시물 표시

Leetcode

이미지
1. Two Sum: find a pair with specific sum   class Solution : def twoSum ( self , nums : List [ int ] , target : int ) - > List [ int ] : numMap = { } n = len ( nums ) # Build the hash table for i in range ( n ) : numMap [ nums [ i ] ] = i # Find the complement for i in range ( n ) : complement = target - nums [ i ] if complement in numMap and numMap [ complement ] != i : return [ i , numMap [ complement ] ] return [ ] # No solution found You might wonder how does the code deals with duplicates. As you can see, in the iteration of building the hash table, always the latter(with bigger index) will be saved in the hash table. In the latter iteration finding the complement, the former one(with smaller index) always goes through the iteration earlier, so the [i, numMap[complement]] can return two different indexes, carrying duplicate...
 1. JWT 구현(리프레시 토큰 및 리프레시 토큰 로테이션) 2. 프론트엔드도 보안 강화(JWT 포함 요보안 변수 관리) 3. 마이페이지 만들기 4.  + 관리용 페이지

How to write test code in springboot

In springboot, running 'controller test' instead of unit test is typical. Springboot has its own testing features with 'MockMvc'.  The default annotation for test is @SpringBootTest. You can use @AutoConfigureMockMvc with it to create MockMvc and run test. Or for simple test which does not require service or repository layer, you can simply use @WebMvcTest solely. Three substantial MockMvc methods that are used for testings are like below 1. perform(): runs the controller as if the application got a HTTP request. Receives 'RequestBuilder' as an input and returns 'ResultActions' as an output. ResultActions carries not only the response of the request, but the steps application went through. 2. andExpect(): check if the ResultActions is adequate using its parameter ' ResultMatcher'. 3. andDo(): can implement additional tasks on the ResultActions using its parameter ' ResultHandler'. Thus, the code would like the below example. @SpringBootTe...