Skip to content

Commit b0e0cae

Browse files
committed
Add trial test to demonstrate increment operators
This commit adds a trial test to the project, which serves as an example and demonstrates the usage of increment operators. The test file includes two test cases: one checks the sum of 1 and 1, expecting the result to be 2 😊, and the other checks the product of 2 and 2, expecting the result to be 4 😄. The main focus of the commit is to showcase the difference between postfix and prefix increment operators. Additionally, code changes were made to display initial information, perform operations with increment operators, implement user input for result comparison, and provide appropriate feedback based on the user's answer. I also added dependencies for testing and updated the .gitignore file. 🎉
1 parent e68870e commit b0e0cae

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
### Kotlin .gitignore template
12
### Java template
23
# Compiled class file
34
*.class
@@ -876,4 +877,3 @@ Icon
876877
Network Trash Folder
877878
Temporary Items
878879
.apdisk
879-

build.gradle.kts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@ repositories {
1313
}
1414

1515
dependencies {
16-
testImplementation(kotlin("test"))
16+
testImplementation("org.jetbrains.kotlin:kotlin-test:1.8.20-RC")
1717
// https://mvnrepository.com/artifact/com.google.code.gson/gson
1818
implementation("com.google.code.gson:gson:2.10.1")
19+
20+
// https://mvnrepository.com/artifact/junit/junit
21+
testImplementation("junit:junit:4.13.2")
22+
23+
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
24+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
1925
}
2026

2127
tasks.test {
2228
useJUnitPlatform()
2329
}
2430

2531
tasks.withType<KotlinCompile> {
26-
kotlinOptions.jvmTarget = "1.8"
32+
kotlinOptions.jvmTarget = "17"
2733
}
2834

2935
application {

src/main/kotlin/Main.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,27 @@ fun main() {
7878
// This code prompts the user to rate the repository and provides different responses based on their input.
7979
// It includes a secret message that is revealed when the input is left blank.
8080
// The code demonstrates how to handle different scenarios based on the user's feedback.
81+
82+
print("Enter a number to perform a series of actions on it: ")
83+
var interestingNumber = readln().toInt()
84+
85+
// Printing initial information
86+
print("You are given the number $interestingNumber, " +
87+
"after this operation: (interestingNumber++ + ++interestingNumber), " +
88+
"which will be equal to the variable (interestingNumber is given number): ")
89+
90+
// Performing the operation
91+
val resultOfPerform = interestingNumber++ + ++interestingNumber
92+
93+
// Getting user input for comparison
94+
val compareWithResult = readln().toInt()
95+
96+
// Checking the user's answer
97+
if (resultOfPerform == compareWithResult) {
98+
println("Great answer, it's correct!")
99+
} else if ((resultOfPerform - compareWithResult == 1) || (compareWithResult - resultOfPerform == 1)) {
100+
println("Your answer was very close, think again!")
101+
} else {
102+
println("Your answer is wrong. You should think again!")
103+
}
81104
}

src/test/kotlin/MyTests.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import org.junit.jupiter.api.Test
2+
import org.junit.jupiter.api.Assertions.assertEquals
3+
4+
// Class containing tests
5+
class MyTests {
6+
7+
// Test case 1
8+
@Test
9+
fun test1() {
10+
assertEquals(2, 1 + 1) // Check if the sum of 1 and 1 is equal to 2
11+
}
12+
13+
// Test case 2
14+
@Test
15+
fun test2() {
16+
assertEquals(4, 2 * 2) /* Check if the product of 2 and 2 is equal to 4 */
17+
}
18+
}

0 commit comments

Comments
 (0)