|
| 1 | +using Algorithms.Other; |
| 2 | +using NUnit.Framework; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Linq; |
| 6 | +using System.Text; |
| 7 | +using System.Threading.Tasks; |
| 8 | + |
| 9 | +namespace Algorithms.Tests.Other |
| 10 | +{ |
| 11 | + [TestFixture] |
| 12 | + public class TriangulatorTests |
| 13 | + { |
| 14 | + [Test] |
| 15 | + public void CalculatePosition_ValidCoordinatesAndDistances_ReturnsExpectedPosition() |
| 16 | + { |
| 17 | + var triangulator = new Triangulator(); |
| 18 | + var baseLocations = new List<(double Latitude, double Longitude)> |
| 19 | + { |
| 20 | + (16.054407, 108.202167), |
| 21 | + (16.049807, 108.218991), |
| 22 | + (16.063597, 108.215553) |
| 23 | + }; |
| 24 | + |
| 25 | + var distances = new List<double> { 0.5, 0.7, 0.6 }; |
| 26 | + |
| 27 | + var expectedPosition = (Latitude: 16.054, Longitude: 108.210); |
| 28 | + var result = triangulator.CalculatePosition(baseLocations, distances); |
| 29 | + |
| 30 | + Assert.That(result.Latitude, Is.EqualTo(expectedPosition.Latitude).Within(0.01)); |
| 31 | + Assert.That(result.Longitude, Is.EqualTo(expectedPosition.Longitude).Within(0.01)); |
| 32 | + } |
| 33 | + |
| 34 | + [Test] |
| 35 | + public void CalculatePosition_InvalidBaseLocations_ThrowsArgumentException() |
| 36 | + { |
| 37 | + var triangulator = new Triangulator(); |
| 38 | + var baseLocations = new List<(double Latitude, double Longitude)> |
| 39 | + { |
| 40 | + (10.762622, 106.660172) |
| 41 | + }; |
| 42 | + var distances = new List<double> { 1.0 }; |
| 43 | + |
| 44 | + Assert.That(() => triangulator.CalculatePosition(baseLocations, distances), Throws.ArgumentException); |
| 45 | + } |
| 46 | + |
| 47 | + [Test] |
| 48 | + public void CalculatePosition_InvalidDistances_ThrowsArgumentException() |
| 49 | + { |
| 50 | + var triangulator = new Triangulator(); |
| 51 | + var baseLocations = new List<(double Latitude, double Longitude)> |
| 52 | + { |
| 53 | + (10.762622, 106.660172), |
| 54 | + (10.774981, 106.665504), |
| 55 | + (10.771817, 106.681179) |
| 56 | + }; |
| 57 | + var distances = new List<double> { 1.0 }; |
| 58 | + |
| 59 | + Assert.That(() => triangulator.CalculatePosition(baseLocations, distances), Throws.ArgumentException); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments