diff --git a/src/Latitude.java b/src/Latitude.java index d9f9f3b..c6ac2f9 100644 --- a/src/Latitude.java +++ b/src/Latitude.java @@ -1,5 +1,3 @@ -import java.util.*; - public class Latitude { private MapLatitude mapLatitude; private double value; @@ -11,6 +9,10 @@ } public void updateGPS(double lat2, double long2) { this.value = lat2; - this.mapLatitude.updateLatitude(this.value); + //this.mapLatitude.updateLatitude(this.value); } + // �n�}�̕\���ʒu���X�V���邽�߂̐V�������\�b�h + public void updateMapLatitude() { + this.mapLatitude.updateLatitude(this.value); + } } \ No newline at end of file diff --git a/src/Longitude.java b/src/Longitude.java index b533c8a..60c0df4 100644 --- a/src/Longitude.java +++ b/src/Longitude.java @@ -1,5 +1,3 @@ -import java.util.*; - public class Longitude { private MapLongitude mapLongitude; private double value; @@ -11,6 +9,9 @@ } public void updateGPS(double lat2, double long2) { this.value = long2; - this.mapLongitude.updateLongitude(this.value); + //this.mapLongitude.updateLongitude(this.value); } + public void updateMapLongitude() { + this.mapLongitude.updateLongitude(this.value); + } } \ No newline at end of file diff --git a/src/Map.java b/src/Map.java index abfd465..8aa8b82 100644 --- a/src/Map.java +++ b/src/Map.java @@ -1,26 +1,41 @@ -import java.util.*; - public class Map { private MapLongitude mapLongitude; private Longitude longitude; private MapLatitude mapLatitude; private Latitude latitude; + private boolean autoUpdateEnabled; + public Map() { this.mapLongitude = new MapLongitude(); this.longitude = new Longitude(mapLongitude); this.mapLatitude = new MapLatitude(); this.latitude = new Latitude(mapLatitude); + this.autoUpdateEnabled = true; // �f�t�H���g�Ŏ����X�V��ON�ɐݒ� } + // �����X�V��ON/OFF��؂�ւ��郁�\�b�h + public void setAutoUpdate(boolean enabled) { + this.autoUpdateEnabled = enabled; + } public double getMapLongitude() { return mapLongitude.getValue(); } public double getLongitude() { return longitude.getValue(); } - public void updateGPS(double lat2, double long2) { - this.longitude.updateGPS(lat2, long2); - this.latitude.updateGPS(lat2, long2); - } + // GPS�̈ʒu��񂪍X�V����郁�\�b�h + public void updateGPS(double lat2, double long2) { + this.longitude.updateGPS(lat2, long2); + this.latitude.updateGPS(lat2, long2); + if (this.autoUpdateEnabled) { + this.mapLatitude.updateLatitude(lat2); + this.mapLongitude.updateLongitude(long2); + } + } + // �蓮��GPS�̈ʒu�����X�V���郁�\�b�h + public void updateManually() { + this.longitude.updateMapLongitude(); + this.latitude.updateMapLatitude(); + } public double getMapLatitude() { return mapLatitude.getValue(); } diff --git a/src/TestManualUpdate.java b/src/TestManualUpdate.java new file mode 100644 index 0000000..2faf8b1 --- /dev/null +++ b/src/TestManualUpdate.java @@ -0,0 +1,70 @@ +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����� + } + +} \ No newline at end of file