Skip to content

Commit

Permalink
Added Functionality of comparing value and conversion between differe…
Browse files Browse the repository at this point in the history
…nt volume units
  • Loading branch information
aakash070 committed Jul 30, 2015
1 parent 06e30b9 commit 7215a2b
Show file tree
Hide file tree
Showing 15 changed files with 372 additions and 81 deletions.
320 changes: 249 additions & 71 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/CheckConversion/domain/volume/Volume.class
Binary file not shown.
Binary file modified out/production/CheckConversion/tests/LengthTest.class
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions src/domain/volume/Cup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package domain.volume;

/**
* Created by aakash on 7/30/2015.
*/
public class Cup extends Volume{

public Cup(double volume) {
super(volume*48);
}

@Override
public double getVolumeValue() {
return super.getVolume();
}

public static double convert(Volume volume) {
return volume.getVolumeValue()/48;
}
}
20 changes: 20 additions & 0 deletions src/domain/volume/Ounce.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package domain.volume;

/**
* Created by aakash on 7/30/2015.
*/
public class Ounce extends Volume{

public Ounce(double volume) {
super(volume*6);
}

@Override
public double getVolumeValue() {
return super.getVolume();
}

public static double convert(Volume volume) {
return volume.getVolumeValue()/6;
}
}
20 changes: 20 additions & 0 deletions src/domain/volume/TableSpoon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package domain.volume;

/**
* Created by aakash on 7/30/2015.
*/
public class TableSpoon extends Volume{

public TableSpoon(double volume) {
super(volume*3);
}

@Override
public double getVolumeValue() {
return super.getVolume();
}

public static double convert(Volume volume) {
return volume.getVolumeValue()/3;
}
}
21 changes: 21 additions & 0 deletions src/domain/volume/TeaSpoon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package domain.volume;

/**
* Created by aakash on 7/30/2015.
*/
public class TeaSpoon extends Volume{

public TeaSpoon(double volume) {
super(volume);
}

@Override
public double getVolumeValue() {
return super.getVolume();
}

public static double convert(Volume volume) {
return volume.getVolumeValue();
}

}
10 changes: 7 additions & 3 deletions src/domain/volume/Volume.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@
/**
* Created by aakash on 7/30/2015.
*/
public class Volume {
public abstract class Volume {

private double volume;

public Volume(double volume) {
this.volume = volume;
}

public double getVolume() {
return volume;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!(o instanceof Volume )) return false;

Volume volume1 = (Volume) o;

return Double.compare(volume1.volume, volume) == 0;

}

public abstract double getVolumeValue();
}
10 changes: 3 additions & 7 deletions src/tests/LengthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@ public class LengthTest {

@Test
public void checkComparisonBetweenMetreAndCentimetre() {
Metres metres = new Metres(3);
Centimetres centimetres = new Centimetres(300);

assertTrue(metres.equals(centimetres));
assertTrue(new Metres(3).equals(new Centimetres(300)));
}

@Test
public void checkConversionFromCentimetreToFeet() {
Feet feet = new Feet(3);
double inches = Inch.convert(feet);
Inch inch = new Inch(inches);
double inches = Inch.convert(new Feet(3));

assertEquals(36,inches,0.00001);
assertTrue(inch.equals(feet));
assertTrue(new Inch(inches).equals(new Feet(3)));
}

}
32 changes: 32 additions & 0 deletions src/tests/VolumeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package tests;

import domain.volume.Cup;
import domain.volume.Ounce;
import domain.volume.TableSpoon;
import domain.volume.TeaSpoon;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by aakash on 7/30/2015.
*/
public class VolumeTest {

@Test
public void checkComparisonBetweenTbspAndCup() {

assertTrue(new TableSpoon(16).equals(new Cup(1)));
}

@Test
public void checkConversionFromOunceToTeaspoon() {
Ounce onz = new Ounce(2);
double tsp = TeaSpoon.convert(onz);

TeaSpoon teaSpoon = new TeaSpoon(tsp);

assertEquals(12,tsp,0.00001);
assertTrue(teaSpoon.equals(onz));
}
}

0 comments on commit 7215a2b

Please sign in to comment.