-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
397ec7c
commit d341506
Showing
129 changed files
with
5,300 additions
and
1 deletion.
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
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 @@ | ||
force_new_sandbox: true |
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,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>tkt</groupId> | ||
<artifactId>Part03_01.ThirdElement</artifactId> | ||
<name>Part03_01.ThirdElement</name> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>fi.helsinki.cs.tmc</groupId> | ||
<artifactId>edu-test-utils</artifactId> | ||
<version>0.4.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>tmc</id> | ||
<name>TMC repo</name> | ||
<url>https://maven.mooc.fi/releases</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>tmc</id> | ||
<name>TMC repo</name> | ||
<url>https://maven.mooc.fi/releases</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
</project> |
22 changes: 22 additions & 0 deletions
22
part03-Part03_01.ThirdElement/src/main/java/ThirdElement.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,22 @@ | ||
|
||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
public class ThirdElement { | ||
|
||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
ArrayList<String> list = new ArrayList<>(); | ||
while (true) { | ||
String input = scanner.nextLine(); | ||
if (input.equals("")) { | ||
break; | ||
} | ||
|
||
list.add(input); | ||
} | ||
|
||
System.out.println(lista.get(0)); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
part03-Part03_01.ThirdElement/src/test/java/ThirdElementTest.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,80 @@ | ||
|
||
import fi.helsinki.cs.tmc.edutestutils.MockStdio; | ||
import fi.helsinki.cs.tmc.edutestutils.Points; | ||
import fi.helsinki.cs.tmc.edutestutils.ReflectionUtils; | ||
import java.lang.reflect.Method; | ||
import java.util.NoSuchElementException; | ||
import org.junit.*; | ||
import static org.junit.Assert.*; | ||
|
||
@Points("03-01") | ||
public class ThirdElementTest { | ||
|
||
@Rule | ||
public MockStdio io = new MockStdio(); | ||
|
||
@Test | ||
public void test() { | ||
String[][] input = {{"Tom", "Emma", "Alex", "Mary", "", "Alex"}, {"Emma", "Alex", "Mary", "", "Mary"}}; | ||
|
||
for (int i = 0; i < input.length; i++) { | ||
check(input[i]); | ||
} | ||
} | ||
|
||
private void check(String... strings) { | ||
int oldOut = io.getSysOut().length(); | ||
|
||
String in = ""; | ||
for (int i = 0; i < strings.length - 1; i++) { | ||
in += strings[i] + "\n"; | ||
} | ||
|
||
io.setSysIn(in); | ||
callMain(ThirdElement.class); | ||
String out = io.getSysOut().substring(oldOut); | ||
|
||
assertTrue("you're not printing anything!", out.length() > 0); | ||
|
||
String ans = getLastWord(out); | ||
String expectedAns = strings[strings.length - 1]; | ||
|
||
for (int i = 0; i < strings.length - 1; i++) { | ||
String name = strings[i]; | ||
if (name.equals(expectedAns)) { | ||
continue; | ||
} | ||
|
||
if (name.equals("")) { | ||
continue; | ||
} | ||
|
||
if (out.contains(name)) { | ||
fail("Input:\n" + in + "\n the following output was not expected \"" + name + "\", but it got printed.\nThe output was:\n" + out); | ||
} | ||
} | ||
|
||
String virheIlm = "Input:\n" + in + "\n\n Expected output: \"" + expectedAns + "\", you printed: \"" + ans + "\"\n"; | ||
assertEquals(virheIlm, expectedAns, ans); | ||
} | ||
|
||
private void callMain(Class kl) { | ||
try { | ||
kl = ReflectionUtils.newInstanceOfClass(kl); | ||
String[] t = null; | ||
String x[] = new String[0]; | ||
Method m = ReflectionUtils.requireMethod(kl, "main", x.getClass()); | ||
ReflectionUtils.invokeMethod(Void.TYPE, m, null, (Object) x); | ||
} catch (NoSuchElementException e) { | ||
fail("Your program tried to read too much input. Remember to use nextLine() method to read!"); | ||
} catch (Throwable e) { | ||
fail("Something unexpected happened. The public static void main(String[] args) method of '" + kl + "' class has disappeared \n" | ||
+ "or something unexpected happened. More info: " + e); | ||
} | ||
} | ||
|
||
private static String getLastWord(String inputStr) { | ||
String[] parts = inputStr.split("\\s+"); | ||
return parts[parts.length - 1]; | ||
} | ||
} |
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 @@ | ||
force_new_sandbox: true |
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,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>tkt</groupId> | ||
<artifactId>Part03_02.SecondPlusThird</artifactId> | ||
<name>Part03_02.SecondPlusThird</name> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>fi.helsinki.cs.tmc</groupId> | ||
<artifactId>edu-test-utils</artifactId> | ||
<version>0.4.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>tmc</id> | ||
<name>TMC repo</name> | ||
<url>https://maven.mooc.fi/releases</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>tmc</id> | ||
<name>TMC repo</name> | ||
<url>https://maven.mooc.fi/releases</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
</project> |
22 changes: 22 additions & 0 deletions
22
part03-Part03_02.SecondPlusThird/src/main/java/SecondPlusThird.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,22 @@ | ||
|
||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
public class SecondPlusThird { | ||
|
||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
ArrayList<Integer> numbers = new ArrayList<>(); | ||
while (true) { | ||
int number = Integer.valueOf(scanner.nextLine()); | ||
if (number == 0) { | ||
break; | ||
} | ||
|
||
numbers.add(number); | ||
} | ||
|
||
System.out.println(luvut.get(0)); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
part03-Part03_02.SecondPlusThird/src/test/java/SecondPlusThirdTest.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,80 @@ | ||
|
||
import fi.helsinki.cs.tmc.edutestutils.MockStdio; | ||
import fi.helsinki.cs.tmc.edutestutils.Points; | ||
import fi.helsinki.cs.tmc.edutestutils.ReflectionUtils; | ||
import java.lang.reflect.Method; | ||
import java.util.NoSuchElementException; | ||
import org.junit.*; | ||
import static org.junit.Assert.*; | ||
|
||
@Points("03-02") | ||
public class SecondPlusThirdTest { | ||
|
||
@Rule | ||
public MockStdio io = new MockStdio(); | ||
|
||
@Test | ||
public void test() { | ||
String[][] input = {{"1", "3", "5", "7", "0", "8"}, {"2", "3", "4", "0", "7"}}; | ||
|
||
for (int i = 0; i < input.length; i++) { | ||
check(input[i]); | ||
} | ||
} | ||
|
||
private void check(String... strs) { | ||
int oldOut = io.getSysOut().length(); | ||
|
||
String in = ""; | ||
for (int i = 0; i < strs.length - 1; i++) { | ||
in += strs[i] + "\n"; | ||
} | ||
|
||
io.setSysIn(in); | ||
callMain(SecondPlusThird.class); | ||
String out = io.getSysOut().substring(oldOut); | ||
|
||
assertTrue("you're not printing anything!", out.length() > 0); | ||
|
||
String result = getLast(out); | ||
String expectedResult = strs[strs.length - 1]; | ||
|
||
for (int i = 0; i < strs.length - 1; i++) { | ||
String num = strs[i]; | ||
if (num.equals(expectedResult)) { | ||
continue; | ||
} | ||
|
||
if (num.equals("")) { | ||
continue; | ||
} | ||
|
||
if (out.contains(num)) { | ||
fail("Input:\n" + in + "\nThe output was not expected to contain \"" + num + "\".\nThe output was:\n" + out); | ||
} | ||
} | ||
|
||
String errorMsg = "Input:\n" + in + "\n\n Expected output: \"" + expectedResult + "\", the output was: \"" + result + "\"\n"; | ||
assertEquals(errorMsg, expectedResult, result); | ||
} | ||
|
||
private void callMain(Class kl) { | ||
try { | ||
kl = ReflectionUtils.newInstanceOfClass(kl); | ||
String[] t = null; | ||
String x[] = new String[0]; | ||
Method m = ReflectionUtils.requireMethod(kl, "main", x.getClass()); | ||
ReflectionUtils.invokeMethod(Void.TYPE, m, null, (Object) x); | ||
} catch (NoSuchElementException e) { | ||
fail("Your program tried to read too much input. Remember to use nextLine() method to read!"); | ||
} catch (Throwable e) { | ||
fail("Something unexpected happened. The public static void main(String[] args) method of '" + kl + "' class has disappeared \n" | ||
+ "or something unexpected happened. More info: " + e); | ||
} | ||
} | ||
|
||
private static String getLast(String inputStr) { | ||
String[] pieces = inputStr.split("\\s+"); | ||
return pieces[pieces.length - 1]; | ||
} | ||
} |
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 @@ | ||
force_new_sandbox: true |
Oops, something went wrong.