1
Here are my methods for calculating standard deviation, which for some reason unknown by me does not work (I left my test method down here as well).
public strictfp Double getMedia(List<Double> valor) {
try {
return getSoma(valor) / valor.size();
} catch (NullPointerException e) {
throw new IllegalArgumentException("The list has null values");
}
}
public strictfp Double getSoma(List<Double> valor) {
Double soma = 0D;
for (int i = 0; i < valor.size(); i++) {
soma += valor.get(i);
}
return soma;
}
public strictfp Double getDesvioPadrao(List<Double> valor) {
Double media = getMedia(valor);
int tam = valor.size();
Double desvPadrao = 0D;
for (Double vlr : valor) {
Double aux = vlr - media;
desvPadrao += aux * aux;
}
return Math.sqrt(desvPadrao / tam);
}
#
Test method:
@SuppressWarnings("deprecation")
@Test
private void TesteDesvioPadrao() {
List<Double> valor = new ArrayList<Double>();
valor.add(13.0);
valor.add(23.0);
valor.add(4.0);
valor.add(2.0);
valor.add(11.0);
valor.add(12.0);
assertEquals(new Double(7.467708), ilbt.getDesvioPadrao(valor));
}
What is the mistake? The question is not clear
– Denis Rudnei de Souza
What’s the problem you’re having? Your question doesn’t tell you what you need.
– Jorge.M
When I run my test method, "initializationError"
– Strigi
Please do not put SOLVED in the title, the site does not work like this. From a look at the [tour]
– user28595