Minor refact + unit tests

This commit is contained in:
niksedk 2016-01-21 20:04:43 +01:00
parent 85d2aca40c
commit 8e7a395a00
2 changed files with 25 additions and 6 deletions

View File

@ -1792,14 +1792,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
int hours = int.Parse(highPart.Substring(0, 4));
int minutes = int.Parse(highPart.Substring(4, 2));
int second = int.Parse(lowPart.Substring(2, 2));
int seconds = int.Parse(lowPart.Substring(2, 2));
int frames = int.Parse(lowPart.Substring(4, 2));
int milliseconds = (int)((TimeCode.BaseUnit / Configuration.Settings.General.CurrentFrameRate) * frames);
if (milliseconds > 999)
milliseconds = 999;
return new TimeCode(hours, minutes, second, milliseconds);
return new TimeCode(hours, minutes, seconds, FramesToMillisecondsMax999(frames));
}
return new TimeCode(0, 0, 0, 0);
}

View File

@ -35,6 +35,29 @@ namespace Test.Logic
Assert.AreEqual(0, p.NumberOfLines);
}
[TestMethod]
public void TestAdjust1()
{
var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0,1,1,1) };
p.Adjust(1, 10);
Assert.AreEqual(new TimeCode(0,1,11,1).TotalMilliseconds, p.StartTime.TotalMilliseconds);
}
[TestMethod]
public void TestAdjust2()
{
var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0, 1, 1, 1) };
p.Adjust(2, 10);
Assert.AreEqual(new TimeCode(0, 2, 12, 2).TotalMilliseconds, p.StartTime.TotalMilliseconds);
}
[TestMethod]
public void TestAdjust3()
{
var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0, 0, 0, 0) };
p.Adjust(1, 1);
Assert.AreEqual(1, p.StartTime.TotalSeconds);
}
}
}