Skip to content

Commit 581fa18

Browse files
committed
Lets provide stricter rules when instantiating Hashes and Frames instances.
1 parent a5aa631 commit 581fa18

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/SoundFingerprinting/Data/Frames.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,33 @@ public class Frames : IEnumerable<Frame>
1212
public Frames(IEnumerable<Frame> frames, string origin, int frameRate)
1313
{
1414
this.frames = frames.ToList();
15+
if (this.frames.Any() && frameRate == 0)
16+
{
17+
throw new ArgumentException(nameof(frameRate));
18+
}
19+
1520
RelativeTo = DateTime.Now.AddSeconds((double) this.frames.Count / frameRate);
1621
FrameRate = frameRate;
1722
Origin = origin;
1823
}
1924

2025
public Frames(IEnumerable<Frame> frames, string origin, int frameRate, DateTime relativeTo)
2126
{
22-
RelativeTo = relativeTo;
2327
this.frames = frames.ToList();
28+
if (this.frames.Any() && frameRate == 0)
29+
{
30+
throw new ArgumentException(nameof(frameRate));
31+
}
32+
33+
RelativeTo = relativeTo;
2434
FrameRate = frameRate;
25-
Origin = origin;
35+
Origin = origin;
2636
}
27-
37+
2838
public DateTime RelativeTo { get; }
2939

30-
public double Duration => (double)frames.Count / FrameRate;
31-
40+
public double Duration => (double) frames.Count / FrameRate;
41+
3242
public string Origin { get; }
3343

3444
public int FrameRate { get; }

src/SoundFingerprinting/Data/Hashes.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public Hashes(IEnumerable<HashedFingerprint> fingerprints, double durationInSeco
4545
public Hashes(IEnumerable<HashedFingerprint> fingerprints, double durationInSeconds, DateTime relativeTo, IEnumerable<string> origins, string streamId)
4646
{
4747
this.fingerprints = fingerprints.ToList();
48+
if (this.fingerprints.Any() && durationInSeconds <= 0)
49+
{
50+
throw new ArgumentException(nameof(durationInSeconds));
51+
}
52+
4853
DurationInSeconds = durationInSeconds;
4954
RelativeTo = relativeTo;
5055
Origins = origins;

0 commit comments

Comments
 (0)