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

Removed the accidentaly added non-working ulong implementation #38

Open
wants to merge 1 commit into
base: tribe
Choose a base branch
from
Open
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
21 changes: 0 additions & 21 deletions RevolveUavcan/Tools/BitArrayTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,6 @@ private static BitArray FillBitArrayWithMSB(this BitArray bitArray, int finalSiz
return template;
}

/// <summary>
/// Calculate the ulong value of a BitArray
/// </summary>
/// <param name="bitArray">The BitArray we want to calculate the corresponding ulong value for</param>
/// <returns>An integer representation of the BitArray</returns>
public static ulong GetULongFromBitArray(this BitArray bitArray)
{
if (bitArray.Length > 64)
{
throw new ArgumentException("BitArray length cannot be greater than 64 bits.");
}

// Initialize bitArrayWithMsb with values from bitArray and fill it with MSB
BitArray bitArrayWithMsb = FillBitArrayWithMSB(bitArray, 64);

// Find and return corresponding integer value from bitArrayWithMsb
int[] array = new int[2];
bitArrayWithMsb.CopyTo(array, 0);
return (uint)array[0] + ((ulong)(uint)array[1] << 32);
}

/// <summary>
/// Calculate the long value of a BitArray
/// </summary>
Expand Down
30 changes: 0 additions & 30 deletions RevolveUavcanTest/Tools/BitArrayToolsGetValueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,35 +148,5 @@ public static IEnumerable<object[]> GetFloatAndDoubleInvalidData()
yield return new object[] { new BitArray(42) };
yield return new object[] { new BitArray(69) };
}


[DataTestMethod]
[DynamicData(nameof(GetULongValidData), DynamicDataSourceType.Method)]
public void GetULongValidArgsTest(BitArray bitArray, ulong expectedResult)
{
var result = bitArray.GetULongFromBitArray();
Assert.AreEqual(expectedResult, result);
}

public static IEnumerable<object[]> GetULongValidData()
{
yield return new object[] { new BitArray(BitConverter.GetBytes((ulong) 12)), (ulong) 12 };
yield return new object[] { new BitArray(BitConverter.GetBytes((ulong) 17)), (ulong ) 17 };
yield return new object[] { new BitArray(BitConverter.GetBytes((ulong) 128)), (ulong) 128 };
yield return new object[] { new BitArray(BitConverter.GetBytes((ulong) 12_000)), (ulong) 12_000 };
yield return new object[] { new BitArray(BitConverter.GetBytes((ulong) 3_000_000_000)), (ulong) 3_000_000_000 };
}

[TestMethod]
[DynamicData(nameof(GetULongInvalidData), DynamicDataSourceType.Method)]
public void GetULongInvalidArgsTest(BitArray bitArray)
{
Assert.ThrowsException<ArgumentException>(() => bitArray.GetULongFromBitArray());
}

public static IEnumerable<object[]> GetULongInvalidData()
{
yield return new object[] { new BitArray(69) };
}
}
}
Loading