Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. import bot.SimpleBotKt;
  2. import org.hyperskill.hstest.v6.stage.BaseStageTest;
  3. import org.hyperskill.hstest.v6.testcase.CheckResult;
  4. import org.hyperskill.hstest.v6.testcase.TestCase;
  5.  
  6. import java.util.Collections;
  7. import java.util.List;
  8.  
  9.  
  10. class Clue {
  11. int age;
  12. String name;
  13. int count;
  14.  
  15. Clue(String name, int age, int count) {
  16. this.age = age;
  17. this.name = name;
  18. this.count = count;
  19. }
  20. }
  21.  
  22.  
  23. public class ChattyBotTest extends BaseStageTest<Clue> {
  24.  
  25. public ChattyBotTest() {
  26. super(SimpleBotKt.class);
  27. }
  28.  
  29. @Override
  30. public List<TestCase<Clue>> generate() {
  31. String input = "Marry\n1 0 5\n10";
  32.  
  33. for (int i = 1; i < 9; i++) {
  34. input += "\n" + i;
  35. }
  36.  
  37. return Collections.singletonList(
  38. new TestCase<Clue>()
  39. .setInput(input)
  40. .setAttach(new Clue("Marry", 40, 10))
  41. );
  42. }
  43.  
  44. @Override
  45. public CheckResult check(String reply, Clue clue) {
  46.  
  47. String[] lines = reply.trim().split("\n");
  48.  
  49. int length = 9 + clue.count + 1;
  50.  
  51. if (lines.length <= length) {
  52. return CheckResult.FALSE(
  53. "You should output at least " + (length + 1) + " lines " +
  54. "(for the count number " + clue.count +").\n" +
  55. "Lines found: " + lines.length + "\n" +
  56. "Your output:\n" +
  57. reply
  58. );
  59. }
  60.  
  61. String lineWithName = lines[3].toLowerCase();
  62. String name = clue.name.toLowerCase();
  63.  
  64. if (!lineWithName.contains(name)) {
  65. return CheckResult.FALSE(
  66. "The name was " + clue.name + "\n" +
  67. "But the 4-th line was:\n" +
  68. "\"" + lines[3] + "\"\n\n" +
  69. "4-th line should contain a name of the user"
  70. );
  71. }
  72.  
  73. String lineWithAge = lines[6].toLowerCase();
  74. String age = Integer.toString(clue.age);
  75.  
  76. if (!lineWithAge.contains(age)) {
  77. return CheckResult.FALSE(
  78. "Can't find a correct age " +
  79. "in the last line of output! " +
  80. "Maybe you calculated the age wrong?\n\n" +
  81. "Your last line: \n" + "\"" + lines[6] + "\""
  82. );
  83. }
  84.  
  85. for (int i = 0; i < clue.count + 1; i++) {
  86. String numLine = lines[i + 8];
  87. String actualNum = i + "!";
  88.  
  89. if (!numLine.equals(actualNum)) {
  90. return CheckResult.FALSE(
  91. "Expected " + (i+8) + "-th line: \n" +
  92. "\"" + actualNum + "\"\n" +
  93. "Your "+ (i+8) + "-th line: \n" +
  94. "\"" + numLine + "\""
  95. );
  96. }
  97. }
  98.  
  99. String lastLine = lines[lines.length - 1];
  100.  
  101. if (!lastLine.equals("Congratulations, have a nice day!")) {
  102. return CheckResult.FALSE(
  103. "Your last line should be:\n" +
  104. "\"Congratulations, have a nice day!\"\n" +
  105. "Found:\n" +
  106. "\"" + lastLine + "\""
  107. );
  108. }
  109.  
  110. return CheckResult.TRUE;
  111. }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement