Skip to content

Commit 9fac0f5

Browse files
author
LoneWandererProductions
committed
Merge some new stuff
2 parents 86fc06c + 9e3525d commit 9fac0f5

15 files changed

Lines changed: 410 additions & 288 deletions

CommonExtendedObjectsTests/CommonExtendedObjectsTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net5.0</TargetFramework>
@@ -18,4 +18,4 @@
1818
<ProjectReference Include="..\Mathematics\Mathematics.csproj" />
1919
</ItemGroup>
2020

21-
</Project>
21+
</Project>

CommonExtendedObjectsTests/DataItem.cs

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,79 +13,20 @@
1313

1414
namespace CommonExtendedObjectsTests
1515
{
16-
/// <inheritdoc cref="ObservableObject" />
1716
/// <summary>
1817
/// Data Object
1918
/// </summary>
2019
internal sealed class DataItem
2120
{
22-
/// <summary>
23-
/// The id.
24-
/// </summary>
25-
private int _id;
26-
27-
/// <summary>
28-
/// The name.
29-
/// </summary>
30-
private string _name;
31-
3221
/// <summary>
3322
/// Gets or sets the id.
3423
/// </summary>
35-
internal int Id
36-
{
37-
get => _id;
38-
set
39-
{
40-
if (_id == value)
41-
{
42-
return;
43-
}
44-
45-
_id = value;
46-
}
47-
}
24+
internal int Id { get; set; }
4825

4926
/// <summary>
5027
/// Gets or sets the name.
5128
/// </summary>
52-
internal string Name
53-
{
54-
get => _name;
55-
set
56-
{
57-
if (_name == value)
58-
{
59-
return;
60-
}
61-
62-
_name = value;
63-
}
64-
}
65-
66-
/// <inheritdoc />
67-
/// <summary>
68-
/// Indicates whether the current object is equal to another object of the same type.
69-
/// </summary>
70-
/// <param name="other">An object to compare with this object.</param>
71-
/// <returns>
72-
/// <see langword="true" /> if the current object is equal to the <paramref name="other" /> parameter; otherwise,
73-
/// <see langword="false" />.
74-
/// </returns>
75-
internal bool Equals(DataItem other)
76-
{
77-
if (ReferenceEquals(null, other))
78-
{
79-
return false;
80-
}
81-
82-
if (ReferenceEquals(this, other))
83-
{
84-
return true;
85-
}
86-
87-
return _id == other._id && _name == other._name;
88-
}
29+
internal string Name { get; set; }
8930

9031
/// <inheritdoc />
9132
/// <summary>
@@ -97,7 +38,7 @@ internal bool Equals(DataItem other)
9738
/// </returns>
9839
public override bool Equals(object obj)
9940
{
100-
return ReferenceEquals(this, obj) || obj is DataItem other && Equals(other);
41+
return ReferenceEquals(this, obj) || (obj is DataItem other && Equals(other));
10142
}
10243

10344
/// <inheritdoc />
@@ -109,7 +50,7 @@ public override bool Equals(object obj)
10950
/// </returns>
11051
public override int GetHashCode()
11152
{
112-
return HashCode.Combine(_id);
53+
return HashCode.Combine(Id);
11354
}
11455
}
11556
}

CommonExtendedObjectsTests/HelperMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ internal static BaseMatrix MatrixTestOne(BaseMatrix mOne, BaseMatrix mTwo)
4747
res += spanOne[iOne + k] * spanTwo[iTwo];
4848
}
4949

50-
spanResult[i * w + j] = res;
50+
spanResult[(i * w) + j] = res;
5151
}
5252
}
5353

CommonExtendedObjectsTests/ImmutableLookupMapTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ namespace CommonExtendedObjectsTests
2121
public class PerformanceTests
2222
{
2323
/// <summary>
24-
/// The data
24+
/// The data
2525
/// </summary>
2626
private Dictionary<int, string> _data;
2727

2828
/// <summary>
29-
/// The immutable lookup map
29+
/// The immutable lookup map
3030
/// </summary>
3131
private ImmutableLookupMap<int, string> _immutableLookupMap;
3232

3333
/// <summary>
34-
/// The read only dictionary
34+
/// The read only dictionary
3535
/// </summary>
3636
private ReadOnlyDictionary<int, string> _readOnlyDictionary;
3737

CommonExtendedObjectsTests/IntArrayTests.cs

Lines changed: 100 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,41 @@ namespace CommonExtendedObjectsTests
1717
public class IntArrayTests
1818
{
1919
/// <summary>
20-
/// The size
20+
/// The size
2121
/// </summary>
2222
private const int Size = 1_000_000;
2323

2424
/// <summary>
25-
/// Indexings the should get and set values correctly.
25+
/// Indexing the should get and set values correctly.
2626
/// </summary>
2727
[TestMethod]
2828
public void IndexingShouldGetAndSetValuesCorrectly()
2929
{
3030
var arr = new IntArray(5);
31-
for (int i = 0; i < arr.Length; i++)
31+
for (var i = 0; i < arr.Length; i++)
32+
{
3233
arr[i] = i * 10;
34+
}
3335

34-
for (int i = 0; i < arr.Length; i++)
36+
for (var i = 0; i < arr.Length; i++)
37+
{
3538
Assert.AreEqual(i * 10, arr[i]);
39+
}
3640

3741
arr.Dispose();
3842
}
3943

4044
/// <summary>
41-
/// Removes at should remove element and shift left.
45+
/// Removes at should remove element and shift left.
4246
/// </summary>
4347
[TestMethod]
4448
public void RemoveAtShouldRemoveElementAndShiftLeft()
4549
{
4650
var arr = new IntArray(5);
47-
for (int i = 0; i < arr.Length; i++)
51+
for (var i = 0; i < arr.Length; i++)
52+
{
4853
arr[i] = i;
54+
}
4955

5056
arr.RemoveAt(2);
5157

@@ -56,7 +62,7 @@ public void RemoveAtShouldRemoveElementAndShiftLeft()
5662
}
5763

5864
/// <summary>
59-
/// Resizes the should change length and preserve old data.
65+
/// Resizes the should change length and preserve old data.
6066
/// </summary>
6167
[TestMethod]
6268
public void ResizeShouldChangeLengthAndPreserveOldData()
@@ -77,25 +83,29 @@ public void ResizeShouldChangeLengthAndPreserveOldData()
7783
}
7884

7985
/// <summary>
80-
/// Clears the should zero out all elements.
86+
/// Clears the should zero out all elements.
8187
/// </summary>
8288
[TestMethod]
8389
public void ClearShouldZeroOutAllElements()
8490
{
8591
var arr = new IntArray(4);
86-
for (int i = 0; i < arr.Length; i++)
92+
for (var i = 0; i < arr.Length; i++)
93+
{
8794
arr[i] = 42;
95+
}
8896

8997
arr.Clear();
9098

91-
for (int i = 0; i < arr.Length; i++)
99+
for (var i = 0; i < arr.Length; i++)
100+
{
92101
Assert.AreEqual(0, arr[i]);
102+
}
93103

94104
arr.Dispose();
95105
}
96106

97107
/// <summary>
98-
/// Compares the int array vs int array dot net performance.
108+
/// Compares the int array vs int array dot net performance.
99109
/// </summary>
100110
[TestMethod]
101111
public void CompareIntArrayvsIntArrayDotNetPerformance()
@@ -106,12 +116,16 @@ public void CompareIntArrayvsIntArrayDotNetPerformance()
106116
var intArray = new IntArray(Size);
107117
stopwatch.Restart();
108118

109-
for (int i = 0; i < Size; i++)
119+
for (var i = 0; i < Size; i++)
120+
{
110121
intArray[i] = i;
122+
}
111123

112124
long intArraySum = 0;
113-
for (int i = 0; i < Size; i++)
125+
for (var i = 0; i < Size; i++)
126+
{
114127
intArraySum += intArray[i];
128+
}
115129

116130
stopwatch.Stop();
117131
var customTime = stopwatch.ElapsedMilliseconds;
@@ -123,12 +137,16 @@ public void CompareIntArrayvsIntArrayDotNetPerformance()
123137
var nativeArray = new int[Size];
124138
stopwatch.Restart();
125139

126-
for (int i = 0; i < Size; i++)
140+
for (var i = 0; i < Size; i++)
141+
{
127142
nativeArray[i] = i;
143+
}
128144

129145
long nativeSum = 0;
130-
for (int i = 0; i < Size; i++)
146+
for (var i = 0; i < Size; i++)
147+
{
131148
nativeSum += nativeArray[i];
149+
}
132150

133151
stopwatch.Stop();
134152
var nativeTime = stopwatch.ElapsedMilliseconds;
@@ -190,5 +208,72 @@ private static void RunIndexingTest(IUnmanagedArray<int> arr)
190208

191209
arr.Dispose();
192210
}
211+
212+
/// <summary>
213+
/// Removes the multiple should remove sequential indices.
214+
/// </summary>
215+
[TestMethod]
216+
public void RemoveMultipleShouldRemoveSequentialIndices()
217+
{
218+
var arr = new IntArray(10);
219+
for (var i = 0; i < arr.Length; i++)
220+
{
221+
arr[i] = i + 1; // [1..10]
222+
}
223+
224+
var toRemove = new[] { 3, 4, 5 }; // remove elements at indices 3,4,5 (4th,5th,6th elements)
225+
226+
var sw = Stopwatch.StartNew();
227+
arr.RemoveMultiple(toRemove);
228+
sw.Stop();
229+
230+
Console.WriteLine($"RemoveMultiple (sequential) took {sw.ElapsedTicks} ticks");
231+
232+
Assert.AreEqual(7, arr.Length);
233+
234+
// Remaining should be: 1,2,3,7,8,9,10 (indices:0,1,2,3,4,5,6)
235+
Assert.AreEqual(1, arr[0]);
236+
Assert.AreEqual(2, arr[1]);
237+
Assert.AreEqual(3, arr[2]);
238+
Assert.AreEqual(7, arr[3]);
239+
Assert.AreEqual(8, arr[4]);
240+
Assert.AreEqual(9, arr[5]);
241+
Assert.AreEqual(10, arr[6]);
242+
243+
arr.Dispose();
244+
}
245+
246+
/// <summary>
247+
/// Removes the multiple should remove non sequential indices.
248+
/// </summary>
249+
[TestMethod]
250+
public void RemoveMultipleShouldRemoveNonSequentialIndices()
251+
{
252+
var arr = new IntArray(10);
253+
for (var i = 0; i < arr.Length; i++)
254+
{
255+
arr[i] = i + 1; // [1..10]
256+
}
257+
258+
var toRemove = new[] { 1, 3, 6 }; // remove elements at indices 1,3,6
259+
260+
var sw = Stopwatch.StartNew();
261+
arr.RemoveMultiple(toRemove);
262+
sw.Stop();
263+
264+
Console.WriteLine($"RemoveMultiple (non-sequential) took {sw.ElapsedTicks} ticks");
265+
266+
Assert.AreEqual(7, arr.Length);
267+
268+
// Remaining elements: indices 0,2,4,5,7,8,9
269+
// Values: 1, 3, 5, 6, 8, 9, 10
270+
int[] expected = { 1, 3, 5, 6, 8, 9, 10 };
271+
for (var i = 0; i < arr.Length; i++)
272+
{
273+
Assert.AreEqual(expected[i], arr[i]);
274+
}
275+
276+
arr.Dispose();
277+
}
193278
}
194279
}

0 commit comments

Comments
 (0)