Skip to content

Commit 8f8ce61

Browse files
author
AR Abdul Azeez
committed
added new method
1 parent 4a4676d commit 8f8ce61

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.onesignal.common
2+
3+
/**
4+
* A simple utility class designed to test code coverage.
5+
* This class contains various methods with different branches and conditions
6+
* to verify that test coverage tools are working correctly.
7+
*/
8+
object CoverageTestHelper {
9+
/**
10+
* Adds two numbers together.
11+
*/
12+
fun add(a: Int, b: Int): Int {
13+
return a + b
14+
}
15+
16+
/**
17+
* Subtracts the second number from the first.
18+
*/
19+
fun subtract(a: Int, b: Int): Int {
20+
return a - b
21+
}
22+
23+
/**
24+
* Returns the maximum of two numbers.
25+
*/
26+
fun max(a: Int, b: Int): Int {
27+
return if (a > b) a else b
28+
}
29+
30+
/**
31+
* Returns the minimum of two numbers.
32+
*/
33+
fun min(a: Int, b: Int): Int {
34+
return if (a < b) a else b
35+
}
36+
37+
/**
38+
* Checks if a number is positive.
39+
*/
40+
fun isPositive(number: Int): Boolean {
41+
return number > 0
42+
}
43+
44+
/**
45+
* Checks if a number is negative.
46+
*/
47+
fun isNegative(number: Int): Boolean {
48+
return number < 0
49+
}
50+
51+
/**
52+
* Checks if a number is zero.
53+
*/
54+
fun isZero(number: Int): Boolean {
55+
return number == 0
56+
}
57+
58+
/**
59+
* Returns a greeting message based on the time of day.
60+
* @param hour The hour of the day (0-23)
61+
*/
62+
fun getGreeting(hour: Int): String {
63+
return when {
64+
hour < 0 -> "Invalid hour"
65+
hour < 12 -> "Good morning"
66+
hour < 18 -> "Good afternoon"
67+
hour < 24 -> "Good evening"
68+
else -> "Invalid hour"
69+
}
70+
}
71+
72+
/**
73+
* Calculates the factorial of a number (only for small numbers).
74+
*/
75+
fun factorial(n: Int): Long {
76+
if (n < 0) {
77+
return -1
78+
}
79+
if (n == 0 || n == 1) {
80+
return 1
81+
}
82+
var result = 1L
83+
for (i in 2..n) {
84+
result *= i
85+
}
86+
return result
87+
}
88+
89+
/**
90+
* Checks if a string is empty or null.
91+
*/
92+
fun isEmptyOrNull(str: String?): Boolean {
93+
return str == null || str.isEmpty()
94+
}
95+
96+
/**
97+
* Returns the length of a string, or -1 if null.
98+
*/
99+
fun getLength(str: String?): Int {
100+
return str?.length ?: -1
101+
}
102+
103+
fun isGood(value: Boolean): Boolean {
104+
return value
105+
}
106+
}

0 commit comments

Comments
 (0)