Skip to content

Commit 17300dc

Browse files
committedSep 4, 2017
Initial commit
0 parents  commit 17300dc

File tree

9 files changed

+208
-0
lines changed

9 files changed

+208
-0
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# kotlin-template

‎cover.png

26.2 KB
Loading

‎kotlin-project/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/target/
2+
.settings
3+
.project
4+
.classpath

‎kotlin-project/pom.xml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.yourself</groupId>
7+
<artifactId>kotlin-project</artifactId>
8+
<version>1.0.0</version>
9+
10+
<name>kotlin-project</name>
11+
<description>Add project description here</description>
12+
13+
<properties>
14+
<kotlin.version>1.1.4</kotlin.version>
15+
<junit.version>4.12</junit.version>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.jetbrains.kotlin</groupId>
22+
<artifactId>kotlin-stdlib-jre8</artifactId>
23+
<version>${kotlin.version}</version>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>junit</groupId>
28+
<artifactId>junit</artifactId>
29+
<version>${junit.version}</version>
30+
<scope>test</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.jetbrains.kotlin</groupId>
34+
<artifactId>kotlin-test-junit</artifactId>
35+
<version>${kotlin.version}</version>
36+
<scope>test</scope>
37+
</dependency>
38+
</dependencies>
39+
40+
<build>
41+
<sourceDirectory>src</sourceDirectory>
42+
<testSourceDirectory>test</testSourceDirectory>
43+
<plugins>
44+
<plugin>
45+
<artifactId>kotlin-maven-plugin</artifactId>
46+
<groupId>org.jetbrains.kotlin</groupId>
47+
<version>${kotlin.version}</version>
48+
<executions>
49+
<execution>
50+
<id>compile</id>
51+
<phase>compile</phase>
52+
<goals><goal>compile</goal></goals>
53+
</execution>
54+
<execution>
55+
<id>test-compile</id>
56+
<phase>test-compile</phase>
57+
<goals><goal>test-compile</goal></goals>
58+
</execution>
59+
</executions>
60+
</plugin>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-jar-plugin</artifactId>
64+
<version>2.6</version>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
</project>
69+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// { autofold
2+
package com.yourself;
3+
4+
import java.util.Arrays;
5+
6+
public class Universe {
7+
// }
8+
9+
public static int countAllStars(int... galaxies) {
10+
int totalStars = 0;
11+
for(int stars : galaxies) {
12+
totalStars = stars; // fix me!
13+
}
14+
return totalStars;
15+
}
16+
17+
//{ autofold
18+
}
19+
//}

‎kotlin-project/src/universe.kt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fun countAllStars(vararg galaxies: Int): Int {
2+
var totalStars = 0
3+
for (stars in galaxies) {
4+
totalStars = stars // fix me
5+
}
6+
return totalStars
7+
}

‎kotlin-project/test/universeTest.kt

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
3+
import java.io.File;
4+
import java.util.Scanner;
5+
6+
import org.junit.Assert;
7+
import org.junit.Test;
8+
9+
class UniverseTest {
10+
11+
@Test fun test() {
12+
try {
13+
Assert.assertEquals("Running countAllStars(2, 3)...", 5, countAllStars(2, 3))
14+
Assert.assertEquals("Running countAllStars(9, -3)...", 6, countAllStars(9, -3))
15+
success(true)
16+
17+
if (existsInFile("galaxies.sum()", File("./src/universe.kt"))) {
18+
msg("My personal Yoda, you are. 🙏", "* ● ¸ . ¸. :° ☾ °  ¸. ● ¸ .  ¸. :. • ")
19+
msg("My personal Yoda, you are. 🙏", "  ★ ° ☆ ¸. ¸  ★  :.  . ")
20+
msg("My personal Yoda, you are. 🙏", "__.-._ ° . .    . ☾ °  . * ¸ .")
21+
msg("My personal Yoda, you are. 🙏", "'-._\\7' .  ° ☾ °  ¸.☆ ● .   ")
22+
msg("My personal Yoda, you are. 🙏", " /'.-c   * ● ¸.  ° °  ¸. ")
23+
msg("My personal Yoda, you are. 🙏", " | /T   ° °  ¸. ¸ .   ")
24+
msg("My personal Yoda, you are. 🙏", "_)_/LI");
25+
} else {
26+
msg("Kudos 🌟", "Did you know that in Kotlin you can use the sum() function directly on an Array? Try it!")
27+
msg("Kudos 🌟", "")
28+
msg("Kudos 🌟", "var galaxies = arrayOf(37, 3, 2)")
29+
msg("Kudos 🌟", "var totalStars = galaxies.sum() // 42")
30+
}
31+
} catch (ae: AssertionError) {
32+
success(false)
33+
msg("Oops! 🐞", ae.message)
34+
msg("Hint 💡", "Did you properly accumulate all stars into 'totalStars'? 🤔")
35+
}
36+
}
37+
38+
fun msg(channel: String, msg: String?) {
39+
System.out.println(String.format("TECHIO> message --channel \"%s\" \"%s\"", channel, msg))
40+
}
41+
42+
fun success(success: Boolean) {
43+
System.out.println(String.format("TECHIO> success %s", success))
44+
}
45+
46+
// check if a string exists in a text file
47+
fun existsInFile(str: String, file: File): Boolean {
48+
val scanner = Scanner(file)
49+
try {
50+
while (scanner.hasNextLine()) {
51+
if (scanner.nextLine().contains(str))
52+
return true
53+
}
54+
return false;
55+
} finally {
56+
scanner.close()
57+
}
58+
}
59+
}

‎markdowns/welcome.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Welcome!
2+
3+
This Kotlin template lets you get started quickly with a simple working example using Maven and JUnit. If it is your first contribution then you should have a look at the [Getting Started](https://tech.io/doc/getting-started-create-playground) document.
4+
5+
6+
The source code is on [GitHub](https://github.com/TechDotIO/kotlin-template), please feel free to come up with proposals to improve it.
7+
8+
# Hands-on Demo
9+
10+
@[Luke, how many stars are there in these galaxies?]({"stubs": ["src/universe.kt"], "command": "UniverseTest#test"})
11+
12+
Check out the markdown file [`welcome.md`](https://github.com/TechDotIO/kotlin-template/blob/master/markdowns/welcome.md) to see how this exercise is injected into the template.
13+
14+
# Template Resources
15+
16+
[`markdowns/welcome.md`](https://github.com/TechDotIO/kotlin-template/blob/master/markdowns/welcome.md)
17+
What you are reading here is generated by this file. Tech.io uses the [Markdown syntax](https://tech.io/doc/reference-markdowns) to render text, media and to inject programming exercises.
18+
19+
20+
[`java-project`](https://github.com/TechDotIO/java-template/tree/master/kotlin-project)
21+
A simple Java + Maven + JUnit project dedicated to run the programming exercise above. A project relies on a Docker image to run. You can find images on the [Docker Hub](https://hub.docker.com/explore/) or you can even [build your own](https://tech.io/doc/reference-runner).
22+
23+
24+
[`techio.yml`](https://github.com/TechDotIO/java-template/blob/master/techio.yml)
25+
This *mandatory* file describes both the table of content and the programming project(s). The file path should not be changed.
26+
27+
28+
# Visual and Interactive Content
29+
30+
Tech.io provides all the tools to embed visual and interactive content like a Web app or a Unix terminal within your contribution. Please refer to the [documentation](https://tech.io/doc) to learn more about the viewer integrations.

‎techio.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
title : Advanced Kotlin template
2+
3+
# Table of content
4+
plan:
5+
- title: Welcome # Set the page title (only displayed if your contribution has several pages)
6+
statement: markdowns/welcome.md # Set the file path to the page content
7+
# - title: Another Page
8+
# statement: markdowns/another-page.md
9+
10+
11+
# Settings for your programming projects and the associated Docker images
12+
projects:
13+
java:
14+
root: /kotlin-project # Set the root path to your Kotlin project
15+
16+
# Set the docker image. This image runs JUnit tests using this syntax:
17+
# @[Code Editor Title]({"stubs": ["editorFile1.kt", "editorFile2.kt", ...], "command": "MyJUnitClass#myMethod"})
18+
# More details here: https://github.com/TechDotIO/kotlin-maven3-junit4-runner
19+
runner: techio/kotlin-maven3-junit4-runner:1.0.5-kotlin-1.1.4

0 commit comments

Comments
 (0)
Please sign in to comment.