mirror of https://github.com/ErsatzTV/ErsatzTV.git
12 changed files with 104 additions and 17 deletions
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
using ErsatzTV.Core.Iptv; |
||||
using FluentAssertions; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ErsatzTV.Core.Tests.Iptv; |
||||
|
||||
[TestFixture] |
||||
public class ChannelIdentifierTests |
||||
{ |
||||
[TestCase("1.23", "1.23.etv")] |
||||
[TestCase("12.3", "12.3.etv")] |
||||
[TestCase("123", "123.etv")] |
||||
[TestCase("1.24", "1.24.etv")] |
||||
[TestCase("12.4", "12.4.etv")] |
||||
[TestCase("124", "124.etv")] |
||||
public void TestLegacy(string channelNumber, string expected) |
||||
{ |
||||
string actual = ChannelIdentifier.LegacyFromNumber(channelNumber); |
||||
actual.Should().Be(expected); |
||||
} |
||||
|
||||
[TestCase("1.23", "C1.23.150.ersatztv.org")] |
||||
[TestCase("12.3", "C12.3.198.ersatztv.org")] |
||||
[TestCase("123", "C123.246.ersatztv.org")] |
||||
[TestCase("1.24", "C1.24.151.ersatztv.org")] |
||||
[TestCase("12.4", "C12.4.199.ersatztv.org")] |
||||
[TestCase("124", "C124.247.ersatztv.org")] |
||||
public void TestNew(string channelNumber, string expected) |
||||
{ |
||||
string actual = ChannelIdentifier.FromNumber(channelNumber); |
||||
actual.Should().Be(expected); |
||||
} |
||||
} |
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
using System.Globalization; |
||||
|
||||
namespace ErsatzTV.Core.Iptv; |
||||
|
||||
public static class ChannelIdentifier |
||||
{ |
||||
public static string LegacyFromNumber(string channelNumber) |
||||
{ |
||||
return $"{channelNumber}.etv"; |
||||
} |
||||
|
||||
public static string FromNumber(string channelNumber) |
||||
{ |
||||
// get rid of any decimal (only two are allowed)
|
||||
int number = (int)(decimal.Parse(channelNumber, CultureInfo.InvariantCulture) * 100); |
||||
int id = 0; |
||||
while (number != 0) |
||||
{ |
||||
id += number % 10 + 48; |
||||
number /= 10; |
||||
} |
||||
|
||||
return $"C{channelNumber}.{id}.ersatztv.org"; |
||||
} |
||||
} |
Loading…
Reference in new issue