Add Z-Score Algorithm (#3065)
Co-authored-by: Andrii Siriak <siryaka@gmail.com>
This commit is contained in:
parent
2e09e44a38
commit
bb5b50dea2
9
src/main/java/com/thealgorithms/maths/StandardScore.java
Normal file
9
src/main/java/com/thealgorithms/maths/StandardScore.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package com.thealgorithms.maths;
|
||||||
|
|
||||||
|
public class StandardScore {
|
||||||
|
public static double zScore(double num, double mean, double stdDev)
|
||||||
|
{
|
||||||
|
double z = (num - mean)/stdDev;
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
}
|
27
src/test/java/com/thealgorithms/maths/StandardScoreTest.java
Normal file
27
src/test/java/com/thealgorithms/maths/StandardScoreTest.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package com.thealgorithms.maths;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class StandardScoreTest{
|
||||||
|
@Test
|
||||||
|
void test1()
|
||||||
|
{
|
||||||
|
Assertions.assertEquals(StandardScore.zScore(2, 0, 5), 0.4);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void test2()
|
||||||
|
{
|
||||||
|
Assertions.assertEquals(StandardScore.zScore(1, 1, 1), 0.0);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void test3()
|
||||||
|
{
|
||||||
|
Assertions.assertEquals(StandardScore.zScore(2.5, 1.8, 0.7), 1.0);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void test4()
|
||||||
|
{
|
||||||
|
Assertions.assertEquals(StandardScore.zScore(8.9, 3, 4.2), 1.4047619047619049);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user