-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from SWM-NM/dev
TestDuringController 테스트 코드 일부 추가
- Loading branch information
Showing
14 changed files
with
226 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
|
||
import java.util.Scanner; | ||
public class Main { | ||
public static void main(String[] args) { | ||
Scanner input = new Scanner(System.in); | ||
int A = input.nextInt(); | ||
int B = input.nextInt(); | ||
System.out.println(A+B); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/test/java/swm_nm/morandi/domain/testDuring/controller/TestDuringControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package swm_nm.morandi.domain.testDuring.controller; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import swm_nm.morandi.domain.testDuring.dto.OutputDto; | ||
import swm_nm.morandi.domain.testDuring.dto.TestInputData; | ||
import swm_nm.morandi.domain.testDuring.service.RunCodeService; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest | ||
class TestDuringControllerTest { | ||
} |
81 changes: 81 additions & 0 deletions
81
src/test/java/swm_nm/morandi/domain/testDuring/service/RunCodeServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package swm_nm.morandi.domain.testDuring.service; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import swm_nm.morandi.domain.testDuring.dto.OutputDto; | ||
import swm_nm.morandi.domain.testDuring.dto.TestInputData; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@SpringBootTest | ||
class RunCodeServiceTest { | ||
|
||
@Autowired | ||
private RunCodeService runCodeService; | ||
@Test | ||
@Transactional | ||
void pythonRunCodeTest() throws Exception { | ||
// given | ||
TestInputData testInputData = new TestInputData(); | ||
testInputData.setCode(readFileContent("temp.py")); | ||
testInputData.setInput(null); | ||
testInputData.setLanguage("Python"); | ||
|
||
// when | ||
OutputDto outputDto = runCodeService.runCode(testInputData); | ||
|
||
// then | ||
assertThat(outputDto.getOutput()).isEqualTo("168\n"); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
void cppRunCodeTest() throws Exception { | ||
// given | ||
TestInputData testInputData = new TestInputData(); | ||
testInputData.setCode(readFileContent("temp.cpp")); | ||
testInputData.setInput("1 2"); | ||
testInputData.setLanguage("Cpp"); | ||
|
||
// when | ||
OutputDto outputDto = runCodeService.runCode(testInputData); | ||
|
||
// then | ||
assertThat(outputDto.getOutput()).isEqualTo("3\n"); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
void javaRunCodeTest() throws Exception { | ||
// given | ||
TestInputData testInputData = new TestInputData(); | ||
testInputData.setCode(readFileContent("Main.java")); | ||
testInputData.setInput("1 2"); | ||
testInputData.setLanguage("Java"); | ||
|
||
// when | ||
OutputDto outputDto = runCodeService.runCode(testInputData); | ||
|
||
// then | ||
assertThat(outputDto.getOutput()).isEqualTo("3\n"); | ||
} | ||
|
||
private String readFileContent(String filePath) throws IOException { | ||
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { | ||
StringBuilder content = new StringBuilder(); | ||
String line; | ||
while ((line = br.readLine()) != null) { | ||
content.append(line).append("\n"); | ||
} | ||
return content.toString(); | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/test/java/swm_nm/morandi/domain/testDuring/service/SolvedCheckServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package swm_nm.morandi.domain.testDuring.service; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestReporter; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.security.test.context.support.WithMockUser; | ||
import swm_nm.morandi.domain.member.entity.Member; | ||
import swm_nm.morandi.domain.member.repository.MemberRepository; | ||
import swm_nm.morandi.domain.problem.entity.Problem; | ||
import swm_nm.morandi.domain.problem.repository.ProblemRepository; | ||
import swm_nm.morandi.domain.testDuring.dto.TestCheckDto; | ||
import swm_nm.morandi.domain.testExit.dto.AttemptProblemDto; | ||
import swm_nm.morandi.domain.testExit.entity.AttemptProblem; | ||
import swm_nm.morandi.domain.testExit.entity.Tests; | ||
import swm_nm.morandi.domain.testInfo.repository.TestRepository; | ||
import swm_nm.morandi.domain.testRecord.repository.AttemptProblemRepository; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@SpringBootTest | ||
@WithMockUser(username = "1", roles = "USER") | ||
class SolvedCheckServiceTest { | ||
|
||
@Autowired | ||
private TestRepository testRepository; | ||
|
||
@Autowired | ||
private MemberRepository memberRepository; | ||
|
||
@Autowired | ||
private AttemptProblemRepository attemptProblemRepository; | ||
|
||
@Autowired | ||
private ProblemRepository problemRepository; | ||
|
||
@Autowired | ||
private SolvedCheckService solvedCheckService; | ||
@Test | ||
void isSolvedCheck() { | ||
// given | ||
Optional<Member> result = memberRepository.findById(1L); | ||
Member member = result.get(); | ||
Tests test = Tests.builder() | ||
.member(member) | ||
.testDate(LocalDateTime.now()) | ||
.testTime(120L) | ||
.build(); | ||
Tests savedTest = testRepository.save(test); | ||
// 백준 문제 : 1002, 1003, 1004 | ||
List<Problem> problems = problemRepository.findAllById(Arrays.asList(1L, 2L, 3L)); | ||
|
||
IntStream.range(0, 3).mapToObj(i -> AttemptProblem.builder() | ||
.member(member) | ||
.test(savedTest) | ||
.isSolved(false) | ||
.problem(problems.get(i)) | ||
.build()).forEachOrdered(attemptProblem -> attemptProblemRepository.save(attemptProblem)); | ||
|
||
TestCheckDto testCheckDto = new TestCheckDto(); | ||
testCheckDto.setTestId(savedTest.getTestId()); | ||
testCheckDto.setBojId("aj4941"); | ||
testCheckDto.setTestTypeId(1L); | ||
|
||
// when | ||
List<AttemptProblemDto> attemptProblemDtos = solvedCheckService.isSolvedCheck(testCheckDto); | ||
|
||
// aj4941 유저는 백준 문제 1002, 1003, 1004번 모두 정답이므로 3문제가 모두 정답처리 되어야 한다. | ||
int count = (int) attemptProblemDtos.stream().filter(AttemptProblemDto::getIsSolved).count(); | ||
|
||
// then | ||
assertThat(count).isEqualTo(3); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/java/swm_nm/morandi/domain/testDuring/service/TempCodeServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package swm_nm.morandi.domain.testDuring.service; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class TempCodeServiceTest { | ||
@Test | ||
void saveTempCodeTest() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
typedef pair<ll, ll> pll; | ||
int dx[4] = { -1, 1, 0, 0 }; | ||
int dy[4] = { 0, 0, -1, 1 }; | ||
|
||
int main(void) | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); cout.tie(NULL); | ||
int a, b; cin >> a >> b; | ||
cout << a + b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print(123 + 45) |