Skip to content

Commit

Permalink
Calculate begin from previous section
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoCoderMatrix86 committed Jun 10, 2024
1 parent b03d4d5 commit afc6e67
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 9 deletions.
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);
}
}
}

0 comments on commit afc6e67

Please sign in to comment.