diff --git a/src/Map.java b/src/Map.java index 82489d5..a2a1995 100644 --- a/src/Map.java +++ b/src/Map.java @@ -1,31 +1,37 @@ import java.util.*; public class Map { - private MapLatitude mapLatitude; - private Latitude latitude; - private MapLongitude mapLongitude; private Longitude longitude; + private Latitude latitude; + private MapLatitude mapLatitude; + private MapLongitude mapLongitude; private Presenter presenter; public Map() { - this.mapLatitude = new MapLatitude(); - this.latitude = new Latitude(); - this.mapLongitude = new MapLongitude(); this.longitude = new Longitude(); - this.presenter = new Presenter(longitude, latitude, mapLongitude, mapLatitude); - } - public double getMapLatitude() { - return mapLatitude.getValue(); - } - public double getLatitude() { - return latitude.getValue(); - } - public double getMapLongitude() { - return mapLongitude.getValue(); + this.latitude = new Latitude(); + this.mapLatitude = new MapLatitude(); + this.mapLongitude = new MapLongitude(); + this.presenter = new Presenter(longitude, mapLongitude, latitude, mapLatitude); } public double getLongitude() { return longitude.getValue(); } + public double getLatitude() { + return latitude.getValue(); + } + public double getMapLatitude() { + return mapLatitude.getValue(); + } + public double getMapLongitude() { + return mapLongitude.getValue(); + } public void updateGPS(double lat2, double long2) { this.presenter.updateGPS(lat2, long2); } + public void setAutoUpdate(boolean isAutoUpdate) { + this.presenter.setAutoUpdate(isAutoUpdate); + } + public void updateManually() { + this.presenter.updateManually(); + } } \ No newline at end of file diff --git a/src/Presenter.java b/src/Presenter.java index 9ecf8a6..8669dde 100644 --- a/src/Presenter.java +++ b/src/Presenter.java @@ -2,19 +2,31 @@ public class Presenter { private Longitude longitude; - private Latitude latitude; private MapLongitude mapLongitude; + private Latitude latitude; private MapLatitude mapLatitude; - public Presenter(Longitude longitude, Latitude latitude, MapLongitude mapLongitude, MapLatitude mapLatitude) { + private boolean isAutoUpdate = true; + public Presenter(Longitude longitude, MapLongitude mapLongitude, Latitude latitude, MapLatitude mapLatitude) { this.longitude = longitude; - this.latitude = latitude; this.mapLongitude = mapLongitude; + this.latitude = latitude; this.mapLatitude = mapLatitude; } public void updateGPS(double lat2, double long2) { double longitude = this.longitude.updateGPS(lat2, long2); double latitude = this.latitude.updateGPS(lat2, long2); + if (isAutoUpdate) { + this.mapLongitude.updateLongitude(longitude); + this.mapLatitude.updateLatitude(latitude); + } + } + public void updateManually() { + double longitude = this.longitude.getValue(); + double latitude = this.latitude.getValue(); this.mapLongitude.updateLongitude(longitude); this.mapLatitude.updateLatitude(latitude); } + public void setAutoUpdate(boolean isAutoUpdate) { + this.isAutoUpdate = isAutoUpdate; + } } \ No newline at end of file diff --git a/src/TestManualUpdate.java b/src/TestManualUpdate.java new file mode 100644 index 0000000..6661e17 --- /dev/null +++ b/src/TestManualUpdate.java @@ -0,0 +1,72 @@ + + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestManualUpdate { + + @Test + public void test() { + // �k��35.0�x�C���o135.0�x�C�����X�V���[�h�ɐݒ肷�� + Map map = new Map(); + map.updateGPS(35.0, 135.0); + map.setAutoUpdate(true); + double lati = map.getLatitude(); + double longi = map.getLongitude(); + double mapLati = map.getMapLatitude(); + double mapLongi = map.getMapLongitude(); + assertEquals(lati, 35.0, 0.0001); + assertEquals(longi, 135.0, 0.0001); + assertEquals(mapLati, 35.0, 0.0001); + assertEquals(mapLongi, 135.0, 0.0001); + + // �k��35.1�x�C���o135.1�x�Ɉړ����� + map.updateGPS(35.1, 135.1); + lati = map.getLatitude(); + longi = map.getLongitude(); + mapLati = map.getMapLatitude(); + mapLongi = map.getMapLongitude(); + assertEquals(lati, 35.1, 0.0001); + assertEquals(longi, 135.1, 0.0001); + assertEquals(mapLati, 35.1, 0.0001); + assertEquals(mapLongi, 135.1, 0.0001); + + // �蓮�X�V���s�� + map.updateManually(); + lati = map.getLatitude(); + longi = map.getLongitude(); + mapLati = map.getMapLatitude(); + mapLongi = map.getMapLongitude(); + assertEquals(lati, 35.1, 0.0001); + assertEquals(longi, 135.1, 0.0001); + assertEquals(mapLati, 35.1, 0.0001); + assertEquals(mapLongi, 135.1, 0.0001); + + // �蓮�X�V���[�h�ɐݒ肷�� + map.setAutoUpdate(false); + + // �k��35.0�x�C���o135.0�x�ɖ߂� + map.updateGPS(35.0, 135.0); + lati = map.getLatitude(); + longi = map.getLongitude(); + mapLati = map.getMapLatitude(); + mapLongi = map.getMapLongitude(); + assertEquals(lati, 35.0, 0.0001); + assertEquals(longi, 135.0, 0.0001); + assertEquals(mapLati, 35.1, 0.0001); // �蓮�X�V�̂��ߒl�͕ω����Ȃ� + assertEquals(mapLongi, 135.1, 0.0001); // �蓮�X�V�̂��ߒl�͕ω����Ȃ� + + // �蓮�X�V���s�� + map.updateManually(); + lati = map.getLatitude(); + longi = map.getLongitude(); + mapLati = map.getMapLatitude(); + mapLongi = map.getMapLongitude(); + assertEquals(lati, 35.0, 0.0001); + assertEquals(longi, 135.0, 0.0001); + assertEquals(mapLati, 35.0, 0.0001); // �蓮�X�V�ɂ���Ēl���X�V����� + assertEquals(mapLongi, 135.0, 0.0001); // �蓮�X�V�ɂ���Ēl���X�V����� + } + +}