Skip to content

Commit 7ebb6cd

Browse files
committed
Let's upgrade PrptoBuf before it's not too late.
1 parent ba99bce commit 7ebb6cd

13 files changed

+76
-113
lines changed

src/SoundFingerprinting.Tests/Integration/InMemoryModelServiceTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq;
55

66
using NUnit.Framework;
7-
using NUnit.Framework.Internal;
87
using SoundFingerprinting.Configuration;
98
using SoundFingerprinting.Data;
109
using SoundFingerprinting.InMemory;

src/SoundFingerprinting.Tests/Integration/IntegrationWithSampleFilesTest.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace SoundFingerprinting.Tests.Integration
22
{
33
using System.Collections.Generic;
4-
using System.Diagnostics;
54
using System.IO;
65
using System.Linq;
76
using System.Runtime.Serialization.Formatters.Binary;
@@ -19,20 +18,20 @@ public abstract class IntegrationWithSampleFilesTest : AbstractTest
1918

2019
protected void AssertHashDatasAreTheSame(Hashes h1, Hashes h2)
2120
{
22-
var firstHashDatas = h1.ToList();
23-
var secondHashDatas = h2.ToList();
21+
var firstHashes = h1.ToList();
22+
var secondHashes = h2.ToList();
2423
Assert.AreEqual(h1.DurationInSeconds, h2.DurationInSeconds);
25-
Assert.AreEqual(firstHashDatas.Count, secondHashDatas.Count);
24+
Assert.AreEqual(firstHashes.Count, secondHashes.Count);
2625

2726
// hashes are not ordered as parallel computation is involved
28-
firstHashDatas = SortHashesBySequenceNumber(firstHashDatas);
29-
secondHashDatas = SortHashesBySequenceNumber(secondHashDatas);
27+
firstHashes = SortHashesBySequenceNumber(firstHashes);
28+
secondHashes = SortHashesBySequenceNumber(secondHashes);
3029

31-
for (int i = 0; i < firstHashDatas.Count; i++)
30+
for (int i = 0; i < firstHashes.Count; i++)
3231
{
33-
Assert.AreEqual(firstHashDatas[i].SequenceNumber, secondHashDatas[i].SequenceNumber);
34-
Assert.AreEqual(firstHashDatas[i].StartsAt, secondHashDatas[i].StartsAt, 0.0001);
35-
CollectionAssert.AreEqual(firstHashDatas[i].HashBins, secondHashDatas[i].HashBins);
32+
Assert.AreEqual(firstHashes[i].SequenceNumber, secondHashes[i].SequenceNumber);
33+
Assert.AreEqual(firstHashes[i].StartsAt, secondHashes[i].StartsAt, 0.0001);
34+
CollectionAssert.AreEqual(firstHashes[i].HashBins, secondHashes[i].HashBins);
3635
}
3736
}
3837

@@ -58,14 +57,12 @@ protected AudioSamples GetAudioSamples()
5857
lock (this)
5958
{
6059
var serializer = new BinaryFormatter();
61-
using (Stream stream = new FileStream(PathToSamples, FileMode.Open, FileAccess.Read))
62-
{
63-
return (AudioSamples)serializer.Deserialize(stream);
64-
}
60+
using Stream stream = new FileStream(PathToSamples, FileMode.Open, FileAccess.Read);
61+
return (AudioSamples)serializer.Deserialize(stream);
6562
}
6663
}
6764

68-
private List<HashedFingerprint> SortHashesBySequenceNumber(IEnumerable<HashedFingerprint> hashDatasFromFile)
65+
private static List<HashedFingerprint> SortHashesBySequenceNumber(IEnumerable<HashedFingerprint> hashDatasFromFile)
6966
{
7067
return hashDatasFromFile.OrderBy(hashData => hashData.SequenceNumber).ToList();
7168
}

src/SoundFingerprinting.Tests/SoundFingerprinting.Tests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<LangVersion>8</LangVersion>
77
</PropertyGroup>
88
<ItemGroup>
9-
<PackageReference Include="protobuf-net" Version="2.3.2" />
10-
<PackageReference Include="Moq" Version="4.8.2" />
11-
<PackageReference Include="NUnit" Version="3.9.0" />
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
13-
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
9+
<PackageReference Include="protobuf-net" Version="2.4.4" />
10+
<PackageReference Include="Moq" Version="4.13.1" />
11+
<PackageReference Include="NUnit" Version="3.12.0" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
13+
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
1414
</ItemGroup>
1515
<ItemGroup>
1616
<ProjectReference Include="..\SoundFingerprinting\SoundFingerprinting.csproj" />

src/SoundFingerprinting.Tests/Unit/DAO/CompoundModelReferenceTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using NUnit.Framework;
2-
using SoundFingerprinting.DAO;
3-
using System;
4-
5-
namespace SoundFingerprinting.Tests.Unit.DAO
1+
namespace SoundFingerprinting.Tests.Unit.DAO
62
{
3+
using NUnit.Framework;
4+
using SoundFingerprinting.DAO;
5+
using System;
6+
77
[TestFixture]
88
public class CompoundModelReferenceTest
99
{

src/SoundFingerprinting.Tests/Unit/FFT/SpectrumServiceOctaveTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public void ShouldGenerateLogSpectrumFromAudioSamples()
2828
float f2 = 1400;
2929
for (int t = 0; t < samples.Length; ++t)
3030
{
31-
samples[t] = (float)System.Math.Sin(2 * System.Math.PI * f1 / Fs * t)
32-
+ (float)System.Math.Sin(2 * System.Math.PI * f2 / Fs * t);
31+
samples[t] = (float)System.Math.Sin(2 * System.Math.PI * f1 / Fs * t) + (float)System.Math.Sin(2 * System.Math.PI * f2 / Fs * t);
3332
}
3433

3534
var audio = new AudioSamples(samples, "410Hz", 5512);

src/SoundFingerprinting.Tests/Unit/InMemory/ProtoSerializerTest.cs

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
namespace SoundFingerprinting.Tests.Unit.InMemory
22
{
3-
using System;
43
using System.IO;
5-
using System.Linq;
64
using NUnit.Framework;
75
using ProtoBuf;
86
using SoundFingerprinting.DAO;
97
using SoundFingerprinting.DAO.Data;
108
using SoundFingerprinting.Data;
11-
using SoundFingerprinting.Tests.Integration;
129

1310
[TestFixture]
1411
public class ProtoSerializerTest
@@ -18,53 +15,41 @@ public void ShouldSerializeModelReference()
1815
{
1916
var @ref = new ModelReference<int>(42);
2017

21-
using (var stream = new MemoryStream())
22-
{
23-
Serializer.SerializeWithLengthPrefix<IModelReference>(stream, @ref, PrefixStyle.Fixed32);
24-
byte[] serialized = stream.ToArray();
25-
using (var deserializedStream = new MemoryStream(serialized))
26-
{
27-
var reference = Serializer.DeserializeWithLengthPrefix<IModelReference>(deserializedStream, PrefixStyle.Fixed32);
18+
using var stream = new MemoryStream();
19+
Serializer.SerializeWithLengthPrefix<IModelReference>(stream, @ref, PrefixStyle.Fixed32);
20+
byte[] serialized = stream.ToArray();
21+
using var deserializedStream = new MemoryStream(serialized);
22+
var reference = Serializer.DeserializeWithLengthPrefix<IModelReference>(deserializedStream, PrefixStyle.Fixed32);
2823

29-
Assert.NotNull(reference);
30-
}
31-
}
24+
Assert.NotNull(reference);
3225
}
3326

3427
[Test]
3528
public void ShouldSerialize()
3629
{
3730
var sub = new SubFingerprintData(new[] { 1, 2, 3 }, 1, 1f, new ModelReference<int>(1), new ModelReference<int>(2));
3831

39-
using (var stream = new MemoryStream())
40-
{
41-
Serializer.SerializeWithLengthPrefix(stream, sub, PrefixStyle.Fixed32);
42-
byte[] serialized = stream.ToArray();
32+
using var stream = new MemoryStream();
33+
Serializer.SerializeWithLengthPrefix(stream, sub, PrefixStyle.Fixed32);
34+
byte[] serialized = stream.ToArray();
4335

44-
using (var streamFinal = new MemoryStream(serialized))
45-
{
46-
var deserialized = Serializer.DeserializeWithLengthPrefix<SubFingerprintData>(streamFinal, PrefixStyle.Fixed32);
36+
using var streamFinal = new MemoryStream(serialized);
37+
var deserialized = Serializer.DeserializeWithLengthPrefix<SubFingerprintData>(streamFinal, PrefixStyle.Fixed32);
4738

48-
Assert.AreEqual(sub, deserialized);
49-
}
50-
}
39+
Assert.AreEqual(sub, deserialized);
5140
}
5241

5342
[Test]
5443
public void ShouldSerializeModelReferenceProviders()
5544
{
5645
var provider = new UIntModelReferenceProvider(10);
57-
using (var stream = new MemoryStream())
58-
{
59-
Serializer.SerializeWithLengthPrefix(stream, provider, PrefixStyle.Fixed32);
60-
byte[] serialized = stream.ToArray();
61-
using (var streamFinal = new MemoryStream(serialized))
62-
{
63-
var deserialized = Serializer.DeserializeWithLengthPrefix<UIntModelReferenceProvider>(streamFinal, PrefixStyle.Fixed32);
46+
using var stream = new MemoryStream();
47+
Serializer.SerializeWithLengthPrefix(stream, provider, PrefixStyle.Fixed32);
48+
byte[] serialized = stream.ToArray();
49+
using var streamFinal = new MemoryStream(serialized);
50+
var deserialized = Serializer.DeserializeWithLengthPrefix<UIntModelReferenceProvider>(streamFinal, PrefixStyle.Fixed32);
6451

65-
Assert.AreEqual(11, (uint)deserialized.Next().Id);
66-
}
67-
}
52+
Assert.AreEqual(11, (uint)deserialized.Next().Id);
6853
}
6954

7055
[Test]

src/SoundFingerprinting.Tests/Unit/LCS/CoverageEstimatorTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace SoundFingerprinting.Tests.Unit.LCS
22
{
3-
using System.Collections.Generic;
43
using System.Linq;
54

65
using NUnit.Framework;

src/SoundFingerprinting.Tests/Unit/LCS/LISTest.cs renamed to src/SoundFingerprinting.Tests/Unit/LCS/LongestIncreasingSequenceTest.cs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
namespace SoundFingerprinting.Tests.Unit.LCS
22
{
3-
using System;
43
using System.Collections.Generic;
54
using System.Linq;
65
using NUnit.Framework;
76
using SoundFingerprinting.LCS;
87
using SoundFingerprinting.Query;
98

109
[TestFixture]
11-
public class LISTest
10+
public class LongestIncreasingSequenceTest
1211
{
1312
[Test]
1413
public void ShouldFindLongestIncreasingSequenceEmpty()
1514
{
1615
var result = LisNew.GetIncreasingSequences(Enumerable.Empty<MatchedWith>());
17-
16+
1817
Assert.IsFalse(result.Any());
1918
}
20-
19+
2120
[Test]
2221
public void ShouldFindLongestIncreasingSequenceTrivial()
2322
{
2423
var pairs = new[] {(1, 1, 0d)};
2524
var result = LisNew.GetIncreasingSequences(Generate(pairs)).First();
26-
25+
2726
AssertResult(pairs, result);
2827
}
29-
28+
3029
[Test]
3130
public void ShouldFindLongestIncreasingSequence0()
3231
{
3332
/*
34-
* q 1 2 3
33+
* q 1 2 3
3534
* t 1 2 3
3635
* expected x x x
3736
*/
@@ -44,9 +43,9 @@ public void ShouldFindLongestIncreasingSequence0()
4443
[Test]
4544
public void ShouldFindLongestIncreasingSequence1()
4645
{
47-
/* s 4 3 2 1
46+
/* s 4 3 2 1
4847
* q 1 2 3 4
49-
* t 1 1 1 2
48+
* t 1 1 1 2
5049
* expected x x
5150
* max 1 2 3 4
5251
* case max' is decreasing, t stays the same last 3 elements (need to pick only one)
@@ -65,7 +64,7 @@ public void ShouldFindLongestIncreasingSequence2()
6564
/*
6665
* pick best score
6766
* |
68-
* score 3 2 1 1
67+
* score 3 2 1 1
6968
* q 1 1 1 4
7069
* t 1 2 3 4
7170
* expected x x
@@ -85,7 +84,7 @@ public void ShouldFindLongestIncreasingSequence2()
8584
public void ShouldFindLongestIncreasingSequence3()
8685
{
8786
/* reversed pick best score
88-
*
87+
*
8988
* score 0 1 2 3
9089
* q 1 2 3 4
9190
* t 4 3 2 1
@@ -105,7 +104,7 @@ public void ShouldFindLongestIncreasingSequence3()
105104
[Test]
106105
public void ShouldFindLongestIncreasingSequence4()
107106
{
108-
/* ignore reverse
107+
/* ignore reverse
109108
* |
110109
* score 1 1 2 1 1
111110
* q 1 2 0 3 4
@@ -155,7 +154,7 @@ public void ShouldFindLongestIncreasingSequence6()
155154
* pick best scoring option for first encounter
156155
* |
157156
* s 0 0 1 0 0 0 1
158-
* q 1 20 2 3 21 3 22
157+
* q 1 20 2 3 21 3 22
159158
* t 1 1 2 2 2 3 3
160159
* expected x y x y x y
161160
* max 1 2 2 3 4 3 5
@@ -198,8 +197,8 @@ public void ShouldFindLongestIncreasingSequence8()
198197
{
199198
/*
200199
* s
201-
* q 20 1 2 21 3 22 4 0 5
202-
* t 1 1 2 2 3 3 4 4 5
200+
* q 20 1 2 21 3 22 4 0 5
201+
* t 1 1 2 2 3 3 4 4 5
203202
* expected y x x y x y x x
204203
* max 1 2 2 3 3 4 4 1 5
205204
* max (c.) 1 1 2 2 3 3 4 1 5
@@ -228,7 +227,7 @@ public void ShouldFindLongestIncreasingSequence9()
228227

229228
var pairs = new[] {(1, 1, 0d), (2, 2, 0), (3, 3, 0), (4, 4, 0), (1, 20, 0), (2, 21, 0), (3, 22, 0), (4, 23, 0), (5, 24, 0), (6, 25, 0)};
230229
var results = LisNew.GetIncreasingSequences(Generate(pairs), 6).ToArray();
231-
230+
232231
Assert.AreEqual(2, results.Length);
233232
}
234233

@@ -239,20 +238,20 @@ public void ShouldFindLongestIncreasingSequence10()
239238
* q 1 2 3 4 5 6 0 2 3 4 5 7
240239
* t 1 2 3 4 5 6 20 21 22 23 24 25
241240
* max (c.) 1 2 3 4 5 6 1 2 3 4 5 7
242-
*/
243-
241+
*/
242+
244243
var pairs = new[] {(1, 1, 0d), (2, 2, 0), (3, 3, 0), (4, 4, 0), (5, 5, 0), (6, 6, 0), (0, 20, 0), (2, 21, 0), (3, 22, 0), (4, 23, 0), (5, 24, 0), (7, 25, 0)};
245244
var results = LisNew.GetIncreasingSequences(Generate(pairs), 7).ToArray();
246-
245+
247246
Assert.AreEqual(2, results.Length);
248247
}
249-
248+
250249
[Test]
251250
public void ShouldFindLongestIncreasingSequence11()
252251
{
253252
/*
254253
* q 1 2 0 1 2
255-
* t 1 2 20 21 22
254+
* t 1 2 20 21 22
256255
* max (c.) 1 2 1 2 3
257256
*/
258257

@@ -262,7 +261,7 @@ public void ShouldFindLongestIncreasingSequence11()
262261
var expected1 = new[] {(1, 1, 0d), (2, 2, 0)};
263262
var expected2 = new[] {(0, 20, 0d)};
264263
Assert.AreEqual(2, results.Length);
265-
264+
266265
AssertResult(expected1, results[0]);
267266
AssertResult(expected2, results[1]);
268267
}
@@ -280,7 +279,7 @@ public void ShouldFindLongestIncreasingSequence12()
280279
var results = LisNew.GetIncreasingSequences(Generate(pairs), 5).ToArray();
281280

282281
var expected1 = new[] {(1, 1, 0d), (2, 4, 3)};
283-
282+
284283
AssertResult(expected1, results[0]);
285284
}
286285

@@ -297,18 +296,18 @@ public void ShouldFindLongestIncreasingSequence13()
297296
var results = LisNew.GetIncreasingSequences(Generate(pairs), 5).ToArray();
298297

299298
var expected1 = new[] {(1, 1, 0d), (3, 4, 0)};
300-
299+
301300
AssertResult(expected1, results[0]);
302301
}
303-
302+
304303
[Test]
305304
public void ShouldFindLongestIncreasingSequence14()
306305
{
307306
/*
308307
* s 0 0 0 1 0 0 0 0 0 0 0 0
309-
* q 1 10 2 11 3 12 1 10 2 11 3 12
308+
* q 1 10 2 11 3 12 1 10 2 11 3 12
310309
* t 1 1 2 2 3 3 10 10 11 11 12 12
311-
* max (c.) 1 2 2 3 3 4 1 4 2 5 3 6
310+
* max (c.) 1 2 2 3 3 4 1 4 2 5 3 6
312311
*/
313312
var pairs = new[]
314313
{
@@ -318,7 +317,7 @@ public void ShouldFindLongestIncreasingSequence14()
318317
var results = LisNew.GetIncreasingSequences(Generate(pairs), 12).ToArray();
319318

320319
var expected1 = new[] {(1, 1, 0d), (2, 2, 0), (3, 3, 0), (10, 10, 0), (11, 11, 0), (12, 12, 0)};
321-
320+
322321
AssertResult(expected1, results[0]);
323322
}
324323

@@ -373,9 +372,9 @@ public void BruteForceTest()
373372
(185, 367, 78), (228, 368, 62), (248, 369, 90), (270, 370, 98), (293, 371, 80), (320, 372, 61), (336, 372, 65), (354, 373, 98),
374373
(390, 374, 59), (410, 375, 83), (466, 377, 95), (488, 378, 74), (524, 379, 87)
375374
};
376-
375+
377376
var results = LisNew.GetIncreasingSequences(Generate(pairs), 1000).ToArray();
378-
377+
379378
Assert.AreEqual(1, results.Length);
380379
}
381380

0 commit comments

Comments
 (0)