Wprowadzenie_do_testowania/Testy po pierwszej modyfikacji/BMITest.java

202 lines
4.5 KiB
Java
Raw Permalink Normal View History

2022-06-20 14:04:23 +02:00
package com.epam.bootcamp.bmi_calculator;
import static org.junit.Assert.*;
import org.junit.*;
import org.junit.rules.ExpectedException;
import com.epam.bootcamp.bmi_calculator.interfacesImplements.MetricBMI;
public class BMITest {
App app;
/*@Test
public void GuessTheUnitsTest1() throws Exception{
GuessTheUnits gtu = new GuessTheUnits(1.7,50.0);
assertEquals(gtu.getUnitType(),"metric");
}
@Test
public void GuessTheUnitsTest2() throws Exception{
}*/
@Before
public void setup(){
app = new App();
}
@Test
public void BMITest1() throws Exception{
app.setHeight(1.7);
app.setWeight(50);
assertEquals(app.calculateBMI(),17.3,1);
assertEquals(app.bmiResult(),"Thinness");
}
@Test
public void BMITest2() throws Exception{
try{
app.setHeight(0);
app.setWeight(50.0);
app.calculateBMI();
}catch(Exception e){
assertEquals(e.getMessage(),"Height is equals or less than zero.");
}
}
@Test
public void BMITest12() throws Exception{
try{
app.setHeight(-0.01);
app.setWeight(50.0);
app.calculateBMI();
}catch(Exception e){
assertEquals(e.getMessage(),"Height is equals or less than zero.");
}
}
@Test
public void BMITest13() throws Exception{
try{
app.setHeight(-1);
app.setWeight(50.0);
app.calculateBMI();
}catch(Exception e){
assertEquals(e.getMessage(),"Height is equals or less than zero.");
}
}
@Test
public void BMITest14() throws Exception{
try{
app.setHeight(-11);
app.setWeight(50.0);
app.calculateBMI();
}catch(Exception e){
assertEquals(e.getMessage(),"Height is equals or less than zero.");
}
}
@Test
public void BMITest3() throws Exception{
try{
app.setHeight(1);
app.setWeight(-3);
app.calculateBMI();
}catch(Exception e){
assertEquals(e.getMessage(),"Weight is equals or less than zero.");
}
}
@Test
public void BMITest10() throws Exception{
try{
app.setHeight(1);
app.setWeight(-1);
app.calculateBMI();
}catch(Exception e){
assertEquals(e.getMessage(),"Weight is equals or less than zero.");
}
}
@Test
public void BMITest11() throws Exception{
try{
app.setHeight(1);
app.setWeight(-300000);
app.calculateBMI();
}catch(Exception e){
assertEquals(e.getMessage(),"Weight is equals or less than zero.");
}
}
@Test
public void BMITest4() throws Exception{
try{
app.setHeight(170);
app.setWeight(1764);
app.calculateBMI();
}catch(Exception e){
assertEquals(e.getMessage(),"Height and weight is in different metric.");
}
}
@Test
public void BMITest18() throws Exception{
try{
app.setHeight(5.9);
app.setWeight(60);
app.calculateBMI();
}catch(Exception e){
assertEquals(e.getMessage(),"Height and weight is in different metric.");
}
}
@Test
public void BMITest19() throws Exception{
try{
app.setHeight(5.1);
app.setWeight(-60);
app.calculateBMI();
}catch(Exception e){
assertEquals(e.getMessage(),"Weight is equals or less than zero.");
}
}
@Test
public void BMITest5() throws Exception{
app.setHeight(170);
app.setWeight(50.0);
assertEquals(app.calculateBMI(),17.3,1);
assertEquals(app.bmiResult(),"Thinness");
}
@Test
public void BMITest6() throws Exception{
app.setHeight(5.58);
app.setWeight(1764);
assertEquals(app.calculateBMI(),17.3,1);
assertEquals(app.bmiResult(),"Thinness");
}
@Test
public void BMITest7() throws Exception{
app.setHeight(86.7);
app.setWeight(6349.3);
assertEquals(app.calculateBMI(),37.19,0.5);
assertEquals(app.bmiResult(),"Heavily overweight");
}
@Test
public void BMITest8() throws Exception{
app.setHeight(6.56);
app.setWeight(220.47);
assertEquals(app.calculateBMI(),25,0.5);
assertEquals(app.bmiResult(),"Overweight");
}
@Test
public void BMITest15() throws Exception{
app.setHeight(6.56);
app.setWeight(2220.47);
assertEquals(app.calculateBMI(),15.743818755222017,0.5);
assertEquals(app.bmiResult(),"Thinness");
}
@Test
public void BMITest16() throws Exception{
app.setHeight(1.56);
app.setWeight(220.47);
assertEquals(app.calculateBMI(),90.59418145956607,0.5);
assertEquals(app.bmiResult(),"Heavily overweight");
}
@Test
public void BMITest9() throws Exception{
app.setHeight(200);
app.setWeight(80);
assertEquals(app.calculateBMI(),20,0.0);
assertEquals(app.bmiResult(),"Normal");
}
@Test
public void BMITest17() throws Exception{
app.setHeight(210);
app.setWeight(83);
assertEquals(app.calculateBMI(),18.820861678004533,0.0);
assertEquals(app.bmiResult(),"Normal");
}
}