GuessTheUnits.java

1
package com.epam.bootcamp.bmi_calculator;
2
3
public class GuessTheUnits{
4
5
	private double height;
6
	private double weight;	
7
	private String unitType;
8
	
9
	
10
	/**
11
	 * Váltószám konstansok
12
	 */
13
	private static final double ouncesToPounds = 0.0625;
14
	private static final double centimeterToMeter = 100;
15
	private static final double feetToInch = 12;
16
	
17
	public GuessTheUnits(double height, double weight) throws Exception{
18
		this.height = height;
19
		this.weight = weight;
20 1 1. <init> : removed call to com/epam/bootcamp/bmi_calculator/GuessTheUnits::guessUnit → KILLED
		guessUnit();
21
	}
22
	
23
	/**
24
	 * A mértékegység megállapító metódus.
25
	 * Ha a magasság kisebb száznál, és azon belül 10 és 3 között van, akkor feetben kaptuk a magasságot.
26
	 * Ha a magasság kisebb száznál, de nagyobb vagy egyenlő 10-el, akkor inchben.
27
	 * Ha a magasság kisebb vagy egyenlő 3-al, akkor méterben.
28
	 * Ha a magasság nagyobb száznál, akkor pedig centiméterben.
29
	 * 
30
	 * A magasság alapján meg tudjuk mondani, hogy milyen mértékegységben kaphattuk a súlyt.
31
	 * Ha US mértékegységet használunk és a súly nagyobb mint ezer, akkor ounces-ban kaptuk meg a súlyt.
32
	 * Ha metrikus mértékegységet használunk, és a súly nagyobb mint ezer, valószínűleg két különböző mértékegységben
33
	 * kaptuk meg a magasságot és a súlyt, ezért hibát dob.
34
	 * 
35
	 * Ha feetben, centiméterben vagy ounces-ban kaptuk valamelyik értéket, a convertUnit metódussal át kell alakítanunk azt.
36
	 * @throws Exception
37
	 */
38
	private void guessUnit() throws Exception{ // kitaláljuk a mértékegységet
39 2 1. guessUnit : changed conditional boundary → SURVIVED
2. guessUnit : negated conditional → KILLED
		if(this.height < 100){
40 4 1. guessUnit : changed conditional boundary → SURVIVED
2. guessUnit : changed conditional boundary → SURVIVED
3. guessUnit : negated conditional → KILLED
4. guessUnit : negated conditional → KILLED
			if(this.height < 10 && this.height > 3){ // feet
41 1 1. guessUnit : removed call to com/epam/bootcamp/bmi_calculator/GuessTheUnits::convertUnit → KILLED
				convertUnit("feet"); //átkonvertáljuk inch-re
42
				this.unitType = "US";
43 2 1. guessUnit : changed conditional boundary → SURVIVED
2. guessUnit : negated conditional → KILLED
			}else if(this.height >= 10){ // inch
44
				this.unitType = "US";
45
			}else{ // meter
46
				this.unitType = "metric";
47
			}
48
		}else{ // centimeter
49 1 1. guessUnit : removed call to com/epam/bootcamp/bmi_calculator/GuessTheUnits::convertUnit → KILLED
			convertUnit("centimeter"); //átkonvertáljuk méterre
50
			this.unitType = "metric";
51
		}
52
		
53 1 1. guessUnit : negated conditional → KILLED
		if(this.unitType.equals("US")){ // ounces
54 2 1. guessUnit : changed conditional boundary → SURVIVED
2. guessUnit : negated conditional → KILLED
			if(this.weight > 1000){
55 1 1. guessUnit : removed call to com/epam/bootcamp/bmi_calculator/GuessTheUnits::convertUnit → KILLED
				convertUnit("ounces"); //átkonvertáljuk fontra
56
			}
57
		}else{
58 2 1. guessUnit : changed conditional boundary → SURVIVED
2. guessUnit : negated conditional → KILLED
			if(this.weight > 1000){
59
				throw new Exception("Height and weight is in different metric.");
60
			}
61
		}
62
	}
63
	
64
	
65
	/**
66
	 * Átváltja a mértékegységeket egységesre.
67
	 * @param unit
68
	 */
69
	private void convertUnit(String unit){
70 1 1. convertUnit : negated conditional → KILLED
		if(unit.equals("ounces")){
71 1 1. convertUnit : Replaced double multiplication with division → KILLED
			this.weight = this.weight * ouncesToPounds;
72
		}
73 1 1. convertUnit : negated conditional → KILLED
		if(unit.equals("feet")){
74 1 1. convertUnit : Replaced double multiplication with division → KILLED
			this.height = this.height * feetToInch;
75
		}
76 1 1. convertUnit : negated conditional → KILLED
		if(unit.equals("centimeter")){
77 1 1. convertUnit : Replaced double division with multiplication → KILLED
			this.height = this.height / centimeterToMeter;
78
		}
79
	}
80
	
81
	/**
82
	 * Súly getter
83
	 * @return a súly
84
	 */
85
	public double getWeight(){
86 1 1. getWeight : replaced double return with 0.0d for com/epam/bootcamp/bmi_calculator/GuessTheUnits::getWeight → KILLED
		return this.weight;
87
	}
88
	
89
	/**
90
	 * Magasság getter
91
	 * @return magasság
92
	 */
93
	public double getHeight(){
94 1 1. getHeight : replaced double return with 0.0d for com/epam/bootcamp/bmi_calculator/GuessTheUnits::getHeight → KILLED
		return this.height;
95
	}
96
	
97
	/**
98
	 * A mértékegység típusa getter
99
	 * @return mértékegység típusa
100
	 */
101
	public String getUnitType(){
102 1 1. getUnitType : replaced return value with "" for com/epam/bootcamp/bmi_calculator/GuessTheUnits::getUnitType → KILLED
		return this.unitType;
103
	}
104
}

Mutations

20

1.1
Location : <init>
Killed by : com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest.GuessTheUnitsTest1(com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest)
removed call to com/epam/bootcamp/bmi_calculator/GuessTheUnits::guessUnit → KILLED

39

1.1
Location : guessUnit
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : guessUnit
Killed by : com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest.GuessTheUnitsTest2(com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest)
negated conditional → KILLED

40

1.1
Location : guessUnit
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : guessUnit
Killed by : none
changed conditional boundary → SURVIVED

3.3
Location : guessUnit
Killed by : com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest.GuessTheUnitsTest3(com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest)
negated conditional → KILLED

4.4
Location : guessUnit
Killed by : com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest.GuessTheUnitsTest1(com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest)
negated conditional → KILLED

41

1.1
Location : guessUnit
Killed by : com.epam.bootcamp.bmi_calculator.BMITest.BMITest8(com.epam.bootcamp.bmi_calculator.BMITest)
removed call to com/epam/bootcamp/bmi_calculator/GuessTheUnits::convertUnit → KILLED

43

1.1
Location : guessUnit
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : guessUnit
Killed by : com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest.GuessTheUnitsTest1(com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest)
negated conditional → KILLED

49

1.1
Location : guessUnit
Killed by : com.epam.bootcamp.bmi_calculator.BMITest.BMITest5(com.epam.bootcamp.bmi_calculator.BMITest)
removed call to com/epam/bootcamp/bmi_calculator/GuessTheUnits::convertUnit → KILLED

53

1.1
Location : guessUnit
Killed by : com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest.GuessTheUnitsTest4(com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest)
negated conditional → KILLED

54

1.1
Location : guessUnit
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : guessUnit
Killed by : com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest.GuessTheUnitsTest3(com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest)
negated conditional → KILLED

55

1.1
Location : guessUnit
Killed by : com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest.GuessTheUnitsTest3(com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest)
removed call to com/epam/bootcamp/bmi_calculator/GuessTheUnits::convertUnit → KILLED

58

1.1
Location : guessUnit
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : guessUnit
Killed by : com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest.GuessTheUnitsTest1(com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest)
negated conditional → KILLED

70

1.1
Location : convertUnit
Killed by : com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest.GuessTheUnitsTest4(com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest)
negated conditional → KILLED

71

1.1
Location : convertUnit
Killed by : com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest.GuessTheUnitsTest3(com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest)
Replaced double multiplication with division → KILLED

73

1.1
Location : convertUnit
Killed by : com.epam.bootcamp.bmi_calculator.BMITest.BMITest5(com.epam.bootcamp.bmi_calculator.BMITest)
negated conditional → KILLED

74

1.1
Location : convertUnit
Killed by : com.epam.bootcamp.bmi_calculator.BMITest.BMITest8(com.epam.bootcamp.bmi_calculator.BMITest)
Replaced double multiplication with division → KILLED

76

1.1
Location : convertUnit
Killed by : com.epam.bootcamp.bmi_calculator.BMITest.BMITest5(com.epam.bootcamp.bmi_calculator.BMITest)
negated conditional → KILLED

77

1.1
Location : convertUnit
Killed by : com.epam.bootcamp.bmi_calculator.BMITest.BMITest5(com.epam.bootcamp.bmi_calculator.BMITest)
Replaced double division with multiplication → KILLED

86

1.1
Location : getWeight
Killed by : com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest.GuessTheUnitsTest3(com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest)
replaced double return with 0.0d for com/epam/bootcamp/bmi_calculator/GuessTheUnits::getWeight → KILLED

94

1.1
Location : getHeight
Killed by : com.epam.bootcamp.bmi_calculator.BMITest.BMITest5(com.epam.bootcamp.bmi_calculator.BMITest)
replaced double return with 0.0d for com/epam/bootcamp/bmi_calculator/GuessTheUnits::getHeight → KILLED

102

1.1
Location : getUnitType
Killed by : com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest.GuessTheUnitsTest1(com.epam.bootcamp.bmi_calculator.GuessTheUnitsTest)
replaced return value with "" for com/epam/bootcamp/bmi_calculator/GuessTheUnits::getUnitType → KILLED

Active mutators

Tests examined


Report generated by PIT 1.8.1