Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

位置情報サービスが正常に動作しない不具合を修正 #99

Merged
merged 31 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7fa72db
Add TRViS.LocationService project to solution
TetsuOtter Nov 2, 2023
cd93cf3
Merge branch 'main' into 88-fix-location-service
TetsuOtter Nov 11, 2023
a56cd03
change line ending from CRLF to LF
TetsuOtter Nov 12, 2023
f993a48
Create CalculateDistance.cs
TetsuOtter Nov 12, 2023
8fcc611
Create IsNearBy.cs
TetsuOtter Nov 12, 2023
c4fd06b
add test project for TRViS.LocationService
TetsuOtter Nov 12, 2023
849edc5
Leave判定用の関数も追加
TetsuOtter Nov 15, 2023
0fa9659
Create ILocationService.cs
TetsuOtter Nov 15, 2023
a81e85f
Create StaLocationInfo.cs
TetsuOtter Nov 15, 2023
64c11f2
Create LonLatLocationService.cs
TetsuOtter Nov 15, 2023
b7709ec
Create LonLatLocationService.Tests.cs
TetsuOtter Nov 15, 2023
011ee09
インデントを修正
TetsuOtter Nov 15, 2023
e0a7f02
InfoRow等の「緯度経度が設定されていない駅」は無視するように修正
TetsuOtter Nov 15, 2023
f9c06f0
add ref to LocationService project
TetsuOtter Nov 15, 2023
bdff465
LocationServiceの判定ロジックをブロジェクト分離したため、本体側にそれを反映
TetsuOtter Nov 15, 2023
718461b
メインスレッド以外でUIを触っていたミスを修正
TetsuOtter Nov 16, 2023
4eeba60
位置情報のパーミッションを毎度確認するようにした
TetsuOtter Nov 16, 2023
6971347
列車データ変更後にボタンの「運転開始」ボタンをきちんと戻すようにした
TetsuOtter Nov 16, 2023
85988c2
ForceSetLocationInfoのテストを追加
TetsuOtter Nov 24, 2023
b238ff2
ログ出力を追加
TetsuOtter Nov 24, 2023
a7186b2
Merge branch 'main' into 88-fix-location-service
TetsuOtter Nov 24, 2023
ede7996
ログ出力でNullRefが起きるバグを修正
TetsuOtter Nov 24, 2023
06d98ee
駅が進むときにHaptic Feedbackを出すようにした
TetsuOtter Nov 24, 2023
7b471a8
Rowのダブルタップで強制的に現在駅をセットできるようにした
TetsuOtter Nov 24, 2023
4c9f153
LogViewに距離情報も出力するようにした
TetsuOtter Nov 24, 2023
7e7dba6
ForceLonLatまわりのテストを追加
TetsuOtter Nov 24, 2023
849cb2c
ログ出力を追加
TetsuOtter Nov 24, 2023
8af752f
ForceLonLatでRunningToNextStationにならない不具合を修正
TetsuOtter Nov 24, 2023
d4f70a2
現在位置更新時にスクロールしない問題を修正
TetsuOtter Nov 24, 2023
9908288
不要なプロパティを削除
TetsuOtter Nov 24, 2023
f7962aa
スクロール実行をUpdateCurrentRunningLocationVisualizer側に移動
TetsuOtter Nov 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TRViS.LocationService.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using NUnit.Framework;
227 changes: 227 additions & 0 deletions TRViS.LocationService.Tests/LonLatLocationService.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
using TRViS.Services;

namespace TRViS.LocationService.Tests;

public class Tests
{
[Test]
public void InitializeTest()
{
LonLatLocationService service = new();
Assert.Multiple(() =>
{
Assert.That(service.StaLocationInfo, Is.Null);
Assert.That(service.CurrentStationIndex, Is.EqualTo(-1));
Assert.That(service.IsRunningToNextStation, Is.False);
});
}

[Test]
public void MoveTest()
{
LonLatLocationService service = new()
{
StaLocationInfo =
[
new(0, 0, 0, 200),
new(1, 1, 1, 200),
new(2, 2, 2, 200),
]
};

// 初期状態は、駅0にいる
Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(0));
Assert.That(service.IsRunningToNextStation, Is.False);
});

service.SetCurrentLocation(0.1, 0.1);

// (平均値を取るために、3回以上の移動が必要)
Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(0));
Assert.That(service.IsRunningToNextStation, Is.False);
});

service.SetCurrentLocation(0.1, 0.1);
service.SetCurrentLocation(0.1, 0.1);

// 駅0を離れ、駅1に向かっている
Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(0));
Assert.That(service.IsRunningToNextStation, Is.True);
});

service.SetCurrentLocation(1, 1);
service.SetCurrentLocation(1, 1);
service.SetCurrentLocation(1, 1);

// ちょうど駅1にいる
Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(1));
Assert.That(service.IsRunningToNextStation, Is.False);
});

service.SetCurrentLocation(2, 2);
service.SetCurrentLocation(2, 2);
service.SetCurrentLocation(2, 2);

// 駅1を離れ、駅2に向かっている
Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(1));
Assert.That(service.IsRunningToNextStation, Is.True);
});

service.SetCurrentLocation(2, 2);
service.SetCurrentLocation(2, 2);
service.SetCurrentLocation(2, 2);

// ちょうど駅2にいる
Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(2));
Assert.That(service.IsRunningToNextStation, Is.False);
});

service.SetCurrentLocation(3, 3);
service.SetCurrentLocation(3, 3);
service.SetCurrentLocation(3, 3);

// 駅2から先には進まない
Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(2));
Assert.That(service.IsRunningToNextStation, Is.False);
});
}

[Test]
public void ForceSetPositionTest_NearStation()
{
StaLocationInfo sta1 = new(0, 0, 0, 200);
StaLocationInfo sta2 = new(1, 1, 1, 200);
StaLocationInfo sta3 = new(2, 2, 2, 200);
LonLatLocationService service = new()
{
StaLocationInfo =
[
sta1,
sta2,
sta3,
]
};

// 初期状態は、駅0にいる
Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(0));
Assert.That(service.IsRunningToNextStation, Is.False);
});

service.ForceSetLocationInfo(1, 1);

Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(1));
Assert.That(service.IsRunningToNextStation, Is.False);
});
}

[Test]
public void ForceSetPositionTest_RunningToNextStation1()
{
StaLocationInfo sta1 = new(0, 0, 0, 200);
StaLocationInfo sta2 = new(1, 1, 1, 200);
StaLocationInfo sta3 = new(2, 2, 2, 200);
LonLatLocationService service = new()
{
StaLocationInfo =
[
sta1,
sta2,
sta3,
]
};

// 初期状態は、駅0にいる
Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(0));
Assert.That(service.IsRunningToNextStation, Is.False);
});

service.ForceSetLocationInfo(0.5, 0.5);

Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(0));
Assert.That(service.IsRunningToNextStation, Is.True);
});

service.SetCurrentLocation(1, 1);
Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(0));
Assert.That(service.IsRunningToNextStation, Is.True);
});
service.SetCurrentLocation(1, 1);
service.SetCurrentLocation(1, 1);
Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(1));
Assert.That(service.IsRunningToNextStation, Is.False);
});
}

[Test]
public void ForceSetPositionTest_RunningToNextStation2()
{
StaLocationInfo sta1 = new(0, 0, 0, 200);
StaLocationInfo sta2 = new(1, 1, 1, 200);
StaLocationInfo sta3 = new(2, 2, 2, 200);
LonLatLocationService service = new()
{
StaLocationInfo =
[
sta1,
sta2,
sta3,
]
};

// 初期状態は、駅0にいる
Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(0));
Assert.That(service.IsRunningToNextStation, Is.False);
});

service.ForceSetLocationInfo(1.5, 1.5);

Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(1));
Assert.That(service.IsRunningToNextStation, Is.True);
});

service.SetCurrentLocation(2, 2);
Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(1));
Assert.That(service.IsRunningToNextStation, Is.True);
});
service.SetCurrentLocation(2, 2);
service.SetCurrentLocation(2, 2);

Assert.Multiple(() =>
{
Assert.That(service.CurrentStationIndex, Is.EqualTo(2));
Assert.That(service.IsRunningToNextStation, Is.False);
});
}
}
24 changes: 24 additions & 0 deletions TRViS.LocationService.Tests/TRViS.LocationService.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TRViS.LocationService\TRViS.LocationService.csproj" />
</ItemGroup>

</Project>
54 changes: 54 additions & 0 deletions TRViS.LocationService/ILocationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace TRViS.Services;

public class LocationStateChangedEventArgs : EventArgs, IEquatable<LocationStateChangedEventArgs>
{
public int NewStationIndex { get; }
public bool IsRunningToNextStation { get; }

public LocationStateChangedEventArgs(int newStationIndex, bool isRunningToNextStation)
{
NewStationIndex = newStationIndex;
IsRunningToNextStation = isRunningToNextStation;
}

public bool Equals(LocationStateChangedEventArgs? other)
{
if (other is null)
return false;

if (ReferenceEquals(this, other))
return true;

return
NewStationIndex == other.NewStationIndex
&&
IsRunningToNextStation == other.IsRunningToNextStation
;
}

public override bool Equals(object obj)
=> Equals(obj as LocationStateChangedEventArgs);

public override int GetHashCode()
=> HashCode.Combine(NewStationIndex, IsRunningToNextStation);

public override string ToString()
{
return $"{nameof(LocationStateChangedEventArgs)} {{ {nameof(NewStationIndex)}: {NewStationIndex}, {nameof(IsRunningToNextStation)}: {IsRunningToNextStation} }}";
}
}

public interface ILocationService
{
event EventHandler<LocationStateChangedEventArgs>? LocationStateChanged;

StaLocationInfo[]? StaLocationInfo { get; set; }

int CurrentStationIndex { get; }

bool IsRunningToNextStation { get; }

void ResetLocationInfo();

void ForceSetLocationInfo(int stationIndex, bool isRunningToNextStation);
}
Loading
Loading