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

Calculate begin from previous section #365

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion AudioCuesheetEditor/Model/IO/Export/CuesheetSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public CuesheetSection(Cuesheet cuesheet)
title = Cuesheet.Title;
audiofileName = Cuesheet.Audiofile?.Name;
//Try to set begin
begin = Cuesheet.Sections?.FirstOrDefault()?.End;
begin = Cuesheet.Sections?.LastOrDefault()?.End;
if (Begin.HasValue == false)
{
begin = Cuesheet.Tracks.Min(x => x.Begin);
Expand Down
134 changes: 126 additions & 8 deletions AudioCuesheetEditorTests/Model/IO/Export/CuesheetSectionTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AudioCuesheetEditor.Model.IO.Export;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AudioCuesheetEditor.Model.AudioCuesheet;
using AudioCuesheetEditor.Model.Entity;
using AudioCuesheetEditor.Model.AudioCuesheet;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace AudioCuesheetEditor.Model.IO.Export.Tests
{
Expand Down Expand Up @@ -52,5 +47,128 @@ public void ValidationTest()
Assert.AreEqual(ValidationStatus.Success, beginValidationResult.Status);
Assert.AreEqual(ValidationStatus.Success, endValidationResult.Status);
}

[TestMethod()]
public void Begin_FirstSection_ReturnsTimespanZero()
{
// Arrange
var cuesheet = new Cuesheet();
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 4, 43)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 9, 23)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 14, 12)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 18, 53)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 22, 01)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 25, 56)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 31, 12)
});
// Act
var section = cuesheet.AddSection();
// Assert
Assert.AreEqual(TimeSpan.Zero, section.Begin);
}

[TestMethod()]
public void Begin_SecondSection_ReturnsFirstSectionEnd()
{
// Arrange
var cuesheet = new Cuesheet();
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 4, 43)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 9, 23)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 14, 12)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 18, 53)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 22, 01)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 25, 56)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 31, 12)
});
var section1 = cuesheet.AddSection();
section1.End = new TimeSpan(0, 30, 0);
// Act
var section2 = cuesheet.AddSection();
// Assert
Assert.AreEqual(section1.End, section2.Begin);
}

[TestMethod()]
public void Begin_ThirdSection_ReturnsSecondSectionEnd()
{
// Arrange
var cuesheet = new Cuesheet();
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 4, 43)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 9, 23)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 14, 12)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 18, 53)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 22, 01)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 25, 56)
});
cuesheet.AddTrack(new Track()
{
End = new TimeSpan(0, 31, 12)
});
var section1 = cuesheet.AddSection();
section1.End = new TimeSpan(0, 15, 0);
var section2 = cuesheet.AddSection();
section2.End = new TimeSpan(0, 30, 0);
// Act
var section3 = cuesheet.AddSection();
// Assert
Assert.AreEqual(section2.End, section3.Begin);
}
}
}