Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit afbea49

Browse files
Add files via upload
1 parent afee7b6 commit afbea49

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed

‎part01-Part01_08.Greeting/pom.xml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project>
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>tkt</groupId>
5+
<artifactId>Part01_08.Greeting</artifactId>
6+
<name>Part01_08.Greeting</name>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
</properties>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>junit</groupId>
19+
<artifactId>junit</artifactId>
20+
<version>4.12</version>
21+
<scope>test</scope>
22+
</dependency>
23+
<dependency>
24+
<groupId>fi.helsinki.cs.tmc</groupId>
25+
<artifactId>edu-test-utils</artifactId>
26+
<version>0.4.2</version>
27+
<scope>test</scope>
28+
</dependency>
29+
</dependencies>
30+
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>org.apache.maven.plugins</groupId>
35+
<artifactId>maven-compiler-plugin</artifactId>
36+
<version>3.8.0</version>
37+
</plugin>
38+
<plugin>
39+
<groupId>org.codehaus.mojo</groupId>
40+
<artifactId>exec-maven-plugin</artifactId>
41+
<version>1.6.0</version>
42+
</plugin>
43+
</plugins>
44+
</build>
45+
46+
<repositories>
47+
<repository>
48+
<id>tmc</id>
49+
<name>TMC repo</name>
50+
<url>https://maven.mooc.fi/releases</url>
51+
<releases>
52+
<enabled>true</enabled>
53+
</releases>
54+
<snapshots>
55+
<enabled>true</enabled>
56+
</snapshots>
57+
</repository>
58+
</repositories>
59+
60+
<pluginRepositories>
61+
<pluginRepository>
62+
<id>tmc</id>
63+
<name>TMC repo</name>
64+
<url>https://maven.mooc.fi/releases</url>
65+
<releases>
66+
<enabled>true</enabled>
67+
</releases>
68+
<snapshots>
69+
<enabled>true</enabled>
70+
</snapshots>
71+
</pluginRepository>
72+
</pluginRepositories>
73+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
import java.util.Scanner;
3+
4+
public class Greeting {
5+
6+
public static void main(String[] args) {
7+
Scanner scanner = new Scanner(System.in);
8+
9+
// Write your program here
10+
System.out.println("What's your name?");
11+
12+
String name = scanner.nextLine();
13+
14+
System.out.println("Hi " + name);
15+
}
16+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
import fi.helsinki.cs.tmc.edutestutils.MockStdio;
3+
import fi.helsinki.cs.tmc.edutestutils.Points;
4+
import java.io.IOException;
5+
import java.nio.file.Files;
6+
import java.nio.file.Paths;
7+
import java.util.ArrayList;
8+
import java.util.Arrays;
9+
import java.util.List;
10+
import java.util.stream.Collectors;
11+
import org.junit.*;
12+
import static org.junit.Assert.assertEquals;
13+
import static org.junit.Assert.fail;
14+
15+
@Points("01-08")
16+
public class GreetingTest {
17+
18+
@Rule
19+
public MockStdio io = new MockStdio();
20+
21+
@Test
22+
public void adaCorrectOutput() {
23+
correctOutput("Ada");
24+
}
25+
26+
@Test
27+
public void lilyCorrectOutput() {
28+
correctOutput("Lily");
29+
}
30+
31+
private void correctOutput(String input) {
32+
io.setSysIn("" + input + "\n");
33+
Greeting.main(new String[]{});
34+
String[] lines = new String[]{"What's your name?", "Hi " + input};
35+
36+
List<String> rows = rows(io.getSysOut().trim());
37+
38+
assertEquals("Output was expected to contain " + lines.length + " line" + ((lines.length == 1) ? "" : "s") + ". Now it contained " + rows.size() + ".", lines.length, rows.size());
39+
for (int i = 0; i < rows.size(); i++) {
40+
assertEquals("Line " + (i + 1) + " output was incorrect (user input was " + input + ". \nExpecting output:\n" + lines[i] + "\nBut output was:\n" + rows.get(i), lines[i].trim(), rows.get(i).trim());
41+
}
42+
}
43+
44+
private List<String> rows(String out) {
45+
return Arrays.asList(out.split("\n"));
46+
}
47+
48+
private List<String> code(String file) {
49+
try {
50+
return Files.lines(Paths.get("src", "main", "java", file)).collect(Collectors.toList());
51+
} catch (IOException e) {
52+
fail("Reading file " + file + " failed. Write your code in the file " + file);
53+
}
54+
55+
return new ArrayList<>();
56+
}
57+
58+
}
942 Bytes
Binary file not shown.
3.28 KB
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /