1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
type: edu
custom_name: stage1
files:
- name: src/phonebook/Main.java
visible: true
text: |
package phonebook;
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
learner_created: false
- name: test/PhoneBookTest.java
visible: false
text: "import org.hyperskill.hstest.stage.StageTest;\nimport org.hyperskill.hstest.testcase.CheckResult;\n\
import org.hyperskill.hstest.testcase.TestCase;\n\nimport java.util.Arrays;\n\
import java.util.List;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\
\npublic class PhoneBookTest extends StageTest {\n\n private long timeOnTestStart;\n\
\ private static String outputFirstTest;\n \n @Override\n public List<TestCase>\
\ generate() {\n timeOnTestStart = System.currentTimeMillis();\n \
\ return Arrays.asList(\n new TestCase<>().setTimeLimit(30 * 60\
\ * 1000),\n new TestCase<>().setTimeLimit(30 * 60 * 1000).setCheckFunc((reply,\
\ attach) -> {\n if (reply.equals(outputFirstTest)) {\n \
\ return CheckResult.wrong(\n \"\
Your program output is exactly the same during different runs. \" +\n \
\ \"Does your program just output a string?\"\n \
\ );\n\n }\n return CheckResult.correct();\n\
\ })\n );\n }\n \n private CheckResult checkPhrases(String\
\ reply, String... phrases) {\n reply = reply.toLowerCase();\n for\
\ (String phrase : phrases) {\n if (!reply.contains(phrase.toLowerCase()))\
\ {\n return CheckResult.wrong(\"Not found the part `\" + phrase\
\ + \"` in your output.\");\n }\n }\n return CheckResult.correct();\n\
\ }\n \n private Pattern timePattern = Pattern.compile(\".*(\\\\d+)\\\
\\s*min.*?(\\\\d+)\\\\s*sec.*?(\\\\d+)\\\\s*ms.*\", Pattern.DOTALL);\n \n \
\ // returns -1 if not matches.\n private long getUserEstimatedTime(String\
\ reply) {\n Matcher matcher = timePattern.matcher(reply);\n if\
\ (!matcher.matches()) {\n return -1;\n }\n int min =\
\ Integer.parseInt(matcher.group(1));\n int sec = Integer.parseInt(matcher.group(2));\n\
\ int ms = Integer.parseInt(matcher.group(3));\n \n return\
\ ms + sec * 1000 + min * 1000 * 60;\n }\n \n @Override\n public CheckResult\
\ check(String reply, Object clue) {\n\n outputFirstTest = reply;\n\n \
\ long realTime = System.currentTimeMillis() - timeOnTestStart;\n \
\ timeOnTestStart = System.currentTimeMillis();\n// System.out.println(\"\
Time delta: \" + realTime);\n \n if (!reply.contains(\"500 / 500\"\
) && !reply.contains(\"500/500\")) {\n return CheckResult.wrong(\"\
Your output should contain `500 / 500` fragment.\");\n }\n \n \
\ CheckResult res = checkPhrases(reply, \"start searching\", \"found\",\n\
\ \"min.\", \"sec.\", \"ms.\");\n if (!res.isCorrect())\
\ {\n return res;\n }\n long estimatedTime = getUserEstimatedTime(reply);\n\
\ if (estimatedTime == -1) {\n return CheckResult.wrong(\"Your\
\ output format doesn't contain numbers before min, sec, ms words.\");\n \
\ }\n \n if (realTime < 1000) {\n return CheckResult.wrong(\"\
Your program completes too fast. Faster than a second!\");\n }\n \
\ \n double ratio = estimatedTime / (realTime + 0.0);\n if (ratio\
\ < 0.5 || ratio > 1.5) {\n return CheckResult.wrong(\"Too large difference\
\ between the real working time and your output. \" +\n \"\
Real program working time was \" + realTime + \" ms, and your output contained\
\ \" + estimatedTime + \"ms in total.\");\n }\n \n return\
\ CheckResult.correct();\n }\n}\n"
learner_created: false
feedback_link: https://hyperskill.org/projects/63/stages/340/implement#comment
status: Solved
feedback:
message: Congratulations!
time: Wed, 27 Apr 2022 15:20:47 UTC
record: -1
|