Skip to content

Commit bb5b50d

Browse files
RaghavTanejasiriak
andauthored
Add Z-Score Algorithm (TheAlgorithms#3065)
Co-authored-by: Andrii Siriak <siryaka@gmail.com>
1 parent 2e09e44 commit bb5b50d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.thealgorithms.maths;
2+
3+
public class StandardScore {
4+
public static double zScore(double num, double mean, double stdDev)
5+
{
6+
double z = (num - mean)/stdDev;
7+
return z;
8+
}
9+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.thealgorithms.maths;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class StandardScoreTest{
7+
@Test
8+
void test1()
9+
{
10+
Assertions.assertEquals(StandardScore.zScore(2, 0, 5), 0.4);
11+
}
12+
@Test
13+
void test2()
14+
{
15+
Assertions.assertEquals(StandardScore.zScore(1, 1, 1), 0.0);
16+
}
17+
@Test
18+
void test3()
19+
{
20+
Assertions.assertEquals(StandardScore.zScore(2.5, 1.8, 0.7), 1.0);
21+
}
22+
@Test
23+
void test4()
24+
{
25+
Assertions.assertEquals(StandardScore.zScore(8.9, 3, 4.2), 1.4047619047619049);
26+
}
27+
}

0 commit comments

Comments
 (0)